lib/redis/list.rb in redis-objects-0.1.1 vs lib/redis/list.rb in redis-objects-0.1.2
- old
+ new
@@ -57,40 +57,57 @@
else
at(index)
end
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.
+ # 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)
values.each(&block)
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)
end
- # Return the value at the given index.
+ # Return the value at the given index. Can also use familiar list[index] syntax.
+ # Redis: LINDEX
def at(index)
redis.lindex(key, index)
end
+ # Return the first element in the list. Redis: LINDEX(0)
+ def first
+ at(0)
+ end
+
+ # Return the last element in the list. Redis: LINDEX(-1)
def last
- redis.lrange(key, -1, -1)
+ at(-1)
end
+ # Clear the list entirely. Redis: DEL
def clear
redis.del(key)
end
+ # 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)
\ No newline at end of file