lib/redis/list.rb in redis-objects-0.7.0 vs lib/redis/list.rb in redis-objects-0.8.0
- old
+ new
@@ -18,19 +18,19 @@
# Works like push. Can chain together: list << 'a' << 'b'
def <<(value)
push(value)
self # for << 'a' << 'b'
end
-
+
# Add a member before or after pivot in the list. Redis: LINSERT
def insert(where,pivot,value)
redis.linsert(key,where,to_redis(pivot),to_redis(value))
end
# Add a member to the end of the list. Redis: RPUSH
- def push(value)
- redis.rpush(key, to_redis(value))
+ def push(*values)
+ redis.rpush(key, values.map{|v| to_redis(v) })
redis.ltrim(key, -options[:maxlength], -1) if options[:maxlength]
end
# Remove a member from the end of the list. Redis: RPOP
def pop
@@ -48,12 +48,12 @@
def rpoplpush(destination)
from_redis redis.rpoplpush(key, destination.is_a?(Redis::List) ? destination.key : destination.to_s)
end
# Add a member to the start of the list. Redis: LPUSH
- def unshift(value)
- redis.lpush(key, to_redis(value))
+ def unshift(*values)
+ redis.lpush(key, values.map{|v| to_redis(v) })
redis.ltrim(key, 0, options[:maxlength] - 1) if options[:maxlength]
end
# Remove a member from the start of the list. Redis: LPOP
def shift
@@ -86,11 +86,11 @@
end
alias_method :slice, :[]
# Same functionality as Ruby arrays.
def []=(index, value)
- redis.lset(key, index, value)
+ redis.lset(key, index, to_redis(value))
end
# Delete the element(s) from the list that match name. If count is specified,
# only the first-N (if positive) or last-N (if negative) will be removed.
# Use .del to completely delete the entire key.
@@ -130,19 +130,19 @@
# Return the length of the list. Aliased as size. Redis: LLEN
def length
redis.llen(key)
end
alias_method :size, :length
-
+
# Returns true if there are no elements in the list. Redis: LLEN == 0
def empty?
length == 0
end
-
+
def ==(x)
values == x
end
-
+
def to_s
values.join(', ')
end
end
end