lib/redis/list.rb in redis-objects-0.2.0 vs lib/redis/list.rb in redis-objects-0.2.1

- old
+ new

@@ -4,10 +4,12 @@ # behave as much like Ruby arrays as possible. # class List require 'enumerator' include Enumerable + require 'redis/serialize' + include Redis::Serialize attr_reader :key, :options, :redis def initialize(key, redis=$redis, options={}) @key = key @redis = redis @@ -20,31 +22,31 @@ self # for << 'a' << 'b' end # Add a member to the end of the list. Redis: RPUSH def push(value) - redis.rpush(key, value) + redis.rpush(key, to_redis(value)) end # Remove a member from the end of the list. Redis: RPOP def pop - redis.rpop(key) + from_redis redis.rpop(key) end # Add a member to the start of the list. Redis: LPUSH def unshift(value) - redis.lpush(key, value) + redis.lpush(key, to_redis(value)) end # Remove a member from the start of the list. Redis: LPOP def shift - redis.lpop(key) + from_redis redis.lpop(key) end # Return all values in the list. Redis: LRANGE(0,-1) def values - range(0, -1) + from_redis range(0, -1) end alias_method :get, :values # Same functionality as Ruby arrays. If a single number is given, return # just the element at that index using Redis: LINDEX. Otherwise, return @@ -62,11 +64,10 @@ # 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. # Redis: LREM def delete(name, count=0) redis.lrem(key, count, name) # weird api - get end # Iterate through each member of the set. Redis::Objects mixes in Enumerable, # so you can also use familiar methods like +collect+, +detect+, and so forth. def each(&block) @@ -74,16 +75,16 @@ end # Return a range of values from +start_index+ to +end_index+. Can also use # the familiar list[start,end] Ruby syntax. Redis: LRANGE def range(start_index, end_index) - redis.lrange(key, start_index, end_index) + from_redis redis.lrange(key, start_index, end_index) end # Return the value at the given index. Can also use familiar list[index] syntax. # Redis: LINDEX def at(index) - redis.lindex(key, index) + from_redis redis.lindex(key, index) end # Return the first element in the list. Redis: LINDEX(0) def first at(0) \ No newline at end of file