lib/picky/backends/redis/list.rb in picky-3.6.7 vs lib/picky/backends/redis/list.rb in picky-3.6.8
- old
+ new
@@ -4,24 +4,10 @@
class Redis
class List < Basic
- # Writes the hash into Redis.
- #
- def dump hash
- clear
- hash.each_pair do |key, values|
- redis_key = "#{namespace}:#{key}"
- i = 0
- values.each do |value|
- i += 1
- client.zadd redis_key, i, value
- end
- end
- end
-
# Clear the index for this list.
#
# Note: Perhaps we can use a server only command.
# This is not the optimal way to do it.
#
@@ -30,15 +16,53 @@
client.keys(redis_key).each do |key|
client.del key
end
end
+ # Deletes the list for the key.
+ #
+ def delete key
+ client.del key
+ end
+
+ # Writes the hash into Redis.
+ #
+ def dump hash
+ unless @immediate
+ clear
+ # client.pipelined do
+ hash.each_pair do |key, values|
+ redis_key = "#{namespace}:#{key}"
+ i = 0
+ values.each do |value|
+ i += 1
+ client.zadd redis_key, i, value
+ end
+ end
+ # end
+ end
+ end
+
# Get a collection.
#
# Internal API method for the index.
#
def [] key
- client.zrange "#{namespace}:#{key}", 0, -1
+ list = client.zrange "#{namespace}:#{key}", :'0', :'-1'
+ DirectlyManipulable.make self, list, key
+ list
+ end
+
+ # Set a single list.
+ #
+ def []= key, values
+ redis_key = "#{namespace}:#{key}"
+ i = 0
+ values.each do |value|
+ i += 1
+ client.zadd redis_key, i, value
+ end
+ self[key] # TODO Performance?
end
end
end
\ No newline at end of file