class Keymap::ConnectionAdapters::RedisAdapter::RedisHash

Attributes

connection[R]
id[R]
sentinel[R]

Public Class Methods

new(connection, id, sentinel=nil) click to toggle source

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

Public Instance Methods

[](key) click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 107
def [](key)
  connection.hget id, key
end
[]=(key, value) click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 111
def []=(key, value)
  connection.hset id, key, value
end
delete(key) click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 139
def delete(key)
  value = self[key]
  connection.hdel id, key
  value
end
each() { |key, self| ... } click to toggle source
# 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
each_pair() { |key, self| ... } click to toggle source
# 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
each_value() { |self| ... } click to toggle source
# 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
empty?() click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 103
def empty?
  connection.hlen id == 1
end
merge(hash) click to toggle source
Alias for: merge!
merge!(hash) click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 145
def merge!(hash)
  hash.each do |key, value|
    self[key] = value
  end
  self
end
Also aliased as: merge

Private Instance Methods

hash_keys() click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 156
def hash_keys
  keys = connection.hkeys id
  keys.delete sentinel
  keys.delete ''
  keys
end