n.b. nil gets represented as an empty string by redis, so the two are in effect identical keys.
# File lib/keymap/connection_adapters/redis_adapter.rb, line 96 def initialize(connection, id, sentinel=nil) @connection = connection @id = id @sentinel = sentinel self[sentinel] = sentinel end
# File lib/keymap/connection_adapters/redis_adapter.rb, line 107 def [](key) connection.hget id, key end
# File lib/keymap/connection_adapters/redis_adapter.rb, line 111 def []=(key, value) connection.hset id, key, value end
# File lib/keymap/connection_adapters/redis_adapter.rb, line 139 def delete(key) value = self[key] connection.hdel id, key value end
# File lib/keymap/connection_adapters/redis_adapter.rb, line 115 def each if block_given? hash_keys.each { |key| yield [key, self[key]] unless key == sentinel } else ::Enumerable::Enumerator.new(self, :each) end end
# File lib/keymap/connection_adapters/redis_adapter.rb, line 123 def each_pair if block_given? hash_keys.each { |key| yield key, self[key] unless key == sentinel } else ::Enumerable::Enumerator.new(self, :each_pair) end end
# File lib/keymap/connection_adapters/redis_adapter.rb, line 131 def each_value if block_given? hash_keys.each { |key| yield self[key] unless key == sentinel } else ::Enumerable::Enumerator.new(self, :each_value) end end
# File lib/keymap/connection_adapters/redis_adapter.rb, line 103 def empty? connection.hlen id == 1 end
# File lib/keymap/connection_adapters/redis_adapter.rb, line 145 def merge!(hash) hash.each do |key, value| self[key] = value end self end
# File lib/keymap/connection_adapters/redis_adapter.rb, line 156 def hash_keys keys = connection.hkeys id keys.delete sentinel keys.delete '' keys end