lib/redis/list.rb in redis-objects-0.3.1 vs lib/redis/list.rb in redis-objects-0.3.2

- old
+ new

@@ -15,30 +15,32 @@ def initialize(key, *args) @key = key @options = args.last.is_a?(Hash) ? args.pop : {} @redis = args.first || $redis end - + # Works like push. Can chain together: list << 'a' << 'b' def <<(value) push(value) self # for << 'a' << 'b' 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] end # Remove a member from the end of the list. Redis: RPOP def pop from_redis redis.rpop(key) end # Add a member to the start of the list. Redis: LPUSH def unshift(value) redis.lpush(key, to_redis(value)) + redis.ltrim(key, 0, options[:maxlength] - 1) if options[:maxlength] end # Remove a member from the start of the list. Redis: LPOP def shift from_redis redis.lpop(key) @@ -116,6 +118,6 @@ def to_s values.join(', ') end end -end \ No newline at end of file +end