lib/redis/list.rb in redis-objects-0.5.3 vs lib/redis/list.rb in redis-objects-0.6.0
- old
+ new
@@ -18,10 +18,15 @@
# 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))
redis.ltrim(key, -options[:maxlength], -1) if options[:maxlength]
@@ -78,9 +83,14 @@
else
at(index)
end
end
alias_method :slice, :[]
+
+ # Same functionality as Ruby arrays.
+ def []=(index, value)
+ redis.lset(key, index, 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.
# Redis: LREM