module Oxblood::Commands::Hashes

Public Instance Methods

hdel(key, fields) click to toggle source

Removes the specified fields from the hash stored at key @see redis.io/commands/hdel

@param [String] key under which hash is stored @param [Array<#to_s>] fields to delete

@return [Integer] the number of fields that were removed from the hash

# File lib/oxblood/commands/hashes.rb, line 13
def hdel(key, fields)
  run(:HDEL, key, fields)
end
hexists(key, field) click to toggle source

Returns if field is an existing field in the hash stored at key @see redis.io/commands/hexists

@param [String] key under which hash is stored @param [String] field to check for existence

@return [Integer] 1 if the hash contains field and 0 otherwise

# File lib/oxblood/commands/hashes.rb, line 24
def hexists(key, field)
  run(:HEXISTS, key, field)
end
hget(key, field) click to toggle source

Get the value of a hash field @see redis.io/commands/hget

@param [String] key under which hash is stored @param [String] field name

@return [String, nil] the value associated with field

or nil when field is not present in the hash or key does not exist.
# File lib/oxblood/commands/hashes.rb, line 36
def hget(key, field)
  run(:HGET, key, field)
end
hgetall(key) click to toggle source

Get all the fields and values in a hash @see redis.io/commands/hgetall

@param [String] key under which hash is stored

@return [Array] list of fields and their values stored in the hash,

or an empty list when key does not exist.
# File lib/oxblood/commands/hashes.rb, line 47
def hgetall(key)
  run(:HGETALL, key)
end
hincrby(key, field, increment) click to toggle source

Increment the integer value of a hash field by the given number @see redis.io/commands/hincrby

@param [String] key under which hash is stored @param [String] field to increment @param [Integer] increment by value

@return [Integer] the value at field after the increment operation

# File lib/oxblood/commands/hashes.rb, line 59
def hincrby(key, field, increment)
  run(:HINCRBY, key, field, increment)
end
hincrbyfloat(key, field, increment) click to toggle source

Increment the float value of a hash field by the given number @see redis.io/commands/hincrby

@param [String] key under which hash is stored @param [String] field to increment @param [Integer] increment by value

@return [String] the value of field after the increment @return [RError] field contains a value of the wrong type (not a string).

Or the current field content or the specified increment are not parsable
as a double precision floating point number.
# File lib/oxblood/commands/hashes.rb, line 74
def hincrbyfloat(key, field, increment)
  run(:HINCRBYFLOAT, key, field, increment)
end
hkeys(key) click to toggle source

Get all the keys in a hash @see redis.io/commands/hkeys

@param [String] key

@return [Array] list of fields in the hash, or an empty list when

key does not exist.
# File lib/oxblood/commands/hashes.rb, line 85
def hkeys(key)
  run(:HKEYS, key)
end
hlen(key) click to toggle source

Get the number of keys in a hash @see redis.io/commands/hlen

@param [String] key

@return [Integer] number of fields in the hash, or 0 when

key does not exist.
# File lib/oxblood/commands/hashes.rb, line 96
def hlen(key)
  run(:HLEN, key)
end
hmget(key, *fields) click to toggle source

Get the field values of all given hash fields @see redis.io/commands/hmget

@param [String] key under which hash is stored @param [String, Array<String>] fields to get

@return [Array] list of values associated with the given fields,

in the same order as they are requested.
# File lib/oxblood/commands/hashes.rb, line 108
def hmget(key, *fields)
  run(*fields.unshift(:HMGET, key))
end
hmset(key, *args) click to toggle source

Set multiple hash fields to multiple values @see redis.io/commands/hmset

@param [String] key under which store hash @param [[String, String], Array<[String, String]>] args fields and values

@return [String] 'OK'

# File lib/oxblood/commands/hashes.rb, line 119
def hmset(key, *args)
  run(*args.unshift(:HMSET, key))
end
hscan(key, cursor, opts = {}) click to toggle source

Incrementally iterate hash fields and associated values @see redis.io/commands/hscan

@param [Integer] cursor @param [Hash] opts

@option opts [Integer] :count Amount of work that should be done at

every call in order to retrieve elements from the collection.

@option opts [String] :match

@return [Array] two elements array, where the first element is String

representing an unsigned 64 bit number (the cursor), and the second
element is an Array of elements.
# File lib/oxblood/commands/hashes.rb, line 185
def hscan(key, cursor, opts = {})
  args = [:HSCAN, key, cursor]
  Scan.merge_opts!(args, opts)
  run(*args)
end
hset(key, field, value) click to toggle source

Set the string value of a hash field @see redis.io/commands/hset

@param [String] key @param [String] field @param [String] value

@return [Integer] 1 if field is a new field in the hash and value was set.

0 if field already exists in the hash and the value was updated.
# File lib/oxblood/commands/hashes.rb, line 132
def hset(key, field, value)
  run(:HSET, key, field, value)
end
hsetnx(key, field, value) click to toggle source

Set the value of a hash field, only if the field does not exist @see redis.io/commands/hsetnx

@param [String] key @param [String] field @param [String] value

@return [Integer] 1 if field is a new field in the hash and value was set.

0 if field already exists in the hash and no operation was performed.
# File lib/oxblood/commands/hashes.rb, line 145
def hsetnx(key, field, value)
  run(:HSETNX, key, field, value)
end
hstrlen(key, field) click to toggle source

Get the length of the value of a hash field @see redis.io/commands/hstrlen

@param [String] key @param [String] field

@return [Integer] the string length of the value associated with field,

or 0 when field is not present in the hash or key does not exist at all.
# File lib/oxblood/commands/hashes.rb, line 157
def hstrlen(key, field)
  run(:HSTRLEN, key, field)
end
hvals(key) click to toggle source

Get all values in a hash @see redis.io/commands/hvals

@param [String] key

@return [Array] list of values in the hash, or an empty list when

key does not exist
# File lib/oxblood/commands/hashes.rb, line 168
def hvals(key)
  run(:HVALS, key)
end