module RedisModel::Types::Hash
Internal: Methods for hash type of key in Redis.
Public Instance Methods
[](key)
click to toggle source
Public: Retrieves a key in Hash
using Redis HGET command.
key - Key to retrieve.
Returns retrieved value.
# File lib/redis_model/types/hash.rb, line 26 def [](key) connection.hget(key_label, key.to_s) end
[]=(key, value)
click to toggle source
Public: Sets a key in Hash
using Redis HSET command.
key - Key to set. value - Value to set.
Returns new value.
# File lib/redis_model/types/hash.rb, line 13 def []=(key, value) result = connection.hset(key_label, key.to_s, value) @cached_hash = nil value end
incr(key, by = 1)
click to toggle source
Public: Increments a key in Hash
using Redis HINCRBY command.
key - Key to increment. by - Amount for increment (default: 1)
Returns incremented value.
# File lib/redis_model/types/hash.rb, line 36 def incr(key, by = 1) result = connection.hincrby(key_label, key, by) @cached_hash = nil result.to_i end
keys()
click to toggle source
# File lib/redis_model/types/hash.rb, line 48 def keys connection.hkeys(key_label) end
to_hash()
click to toggle source
# File lib/redis_model/types/hash.rb, line 44 def to_hash @cached_hash ||= connection.hgetall(key_label) end