module RedisCluster::Function::Hash
Hash
implement redis hashes commands. There will be some adjustment for cluster. see redis.io/commands#hash. Most of the code are copied from github.com/redis/redis-rb/blob/master/lib/redis.rb.
SETTER = [:hdel, :hincrby, :hincrbyfloat, :hmset, :hset, :hsetnx] GETTER = [:hexists, :hget, :hgetall, :hkeys, :hlen, :hmget, :hstrlen, :hvals, :hscan]
Public Instance Methods
Delete one or more hash fields.
@param [String] key @param [String, Array<String>] field @return [Fixnum] the number of fields that were removed from the hash
# File lib/redis_cluster/function/hash.rb, line 21 def hdel(key, field) call(key, [:hdel, key, field]) end
Determine if a hash field exists.
@param [String] key @param [String] field @return [Boolean] whether or not the field exists in the hash
# File lib/redis_cluster/function/hash.rb, line 83 def hexists(key, field) call(key, [:hexists, key, field], transform: Redis::Boolify, read: true) end
Get the value of a hash field.
@param [String] key @param [String] field @return [String]
# File lib/redis_cluster/function/hash.rb, line 92 def hget(key, field) call(key, [:hget, key, field], read: true) end
Get all the fields and values in a hash.
@param [String] key @return [Hash<String, String>]
# File lib/redis_cluster/function/hash.rb, line 100 def hgetall(key) call(key, [:hgetall, key], transform: Redis::Hashify, read: true) end
Increment the integer value of a hash field by the given integer number.
@param [String] key @param [String] field @param [Fixnum] increment @return [Fixnum] value of the field after incrementing it
# File lib/redis_cluster/function/hash.rb, line 31 def hincrby(key, field, increment) call(key, [:hincrby, key, field, increment]) end
Increment the numeric value of a hash field by the given float number.
@param [String] key @param [String] field @param [Float] increment @return [Float] value of the field after incrementing it
# File lib/redis_cluster/function/hash.rb, line 41 def hincrbyfloat(key, field, increment) call(key, [:hincrbyfloat, key, field, increment], transform: Redis::Floatify) end
Get all the fields in a hash.
@param [String] key @return [Array<String>]
# File lib/redis_cluster/function/hash.rb, line 108 def hkeys(key) call(key, [:hkeys, key], read: true) end
Get the number of fields in a hash.
@param [String] key @return [Fixnum] number of fields in the hash
# File lib/redis_cluster/function/hash.rb, line 124 def hlen(key) call(key, [:hlen, key], read: true) end
Get the values of all the given hash fields.
@example
redis.hmget("hash", "f1", "f2") # => ["v1", "v2"]
@param [String] key @param [Array<String>] fields array of fields @return [Array<String>] an array of values for the specified fields
# File lib/redis_cluster/function/hash.rb, line 137 def hmget(key, *fields) call(key, [:hmget, key] + fields, read: true) end
Set
one or more hash values.
@example
redis.hmset("hash", "f1", "v1", "f2", "v2") # => "OK"
@param [String] key @param [Array<String>] attrs array of fields and values @return [String] `“OK”`
# File lib/redis_cluster/function/hash.rb, line 54 def hmset(key, *attrs) call(key, [:hmset, key] + attrs) end
Set
the string value of a hash field.
@param [String] key @param [String] field @param [String] value @return [Boolean] whether or not the field was added to the hash
# File lib/redis_cluster/function/hash.rb, line 64 def hset(key, field, value) call(key, [:hset, key, field, value], transform: Redis::Boolify) end
Set
the value of a hash field, only if the field does not exist.
@param [String] key @param [String] field @param [String] value @return [Boolean] whether or not the field was added to the hash
# File lib/redis_cluster/function/hash.rb, line 74 def hsetnx(key, field, value) call(key, [:hsetnx, key, field, value], transform: Redis::Boolify) end
Returns the string length of the value associated with field in the hash stored at key.
@param [String] key @param [String] field @return [Fixnum] String
lenght
# File lib/redis_cluster/function/hash.rb, line 146 def hstrlen(key, field) call(key, [:hstrlen, key, field], read: true) end
Get all the values in a hash.
@param [String] key @return [Array<String>]
# File lib/redis_cluster/function/hash.rb, line 116 def hvals(key) call(key, [:hvals, key], read: true) end