Module: Oxblood::Commands::Hashes

Included in:
Oxblood::Commands
Defined in:
lib/oxblood/commands/hashes.rb

Instance Method Summary collapse

Instance Method Details

#hdel(key, fields) ⇒ Integer

Removes the specified fields from the hash stored at key

Parameters:

  • key (String)

    under which hash is stored

  • fields (Array<#to_s>)

    to delete

Returns:

  • (Integer)

    the number of fields that were removed from the hash

See Also:



13
14
15
# File 'lib/oxblood/commands/hashes.rb', line 13

def hdel(key, fields)
  run(:HDEL, key, fields)
end

#hexists(key, field) ⇒ Integer

Returns if field is an existing field in the hash stored at key

Parameters:

  • key (String)

    under which hash is stored

  • field (String)

    to check for existence

Returns:

  • (Integer)

    1 if the hash contains field and 0 otherwise

See Also:



24
25
26
# File 'lib/oxblood/commands/hashes.rb', line 24

def hexists(key, field)
  run(:HEXISTS, key, field)
end

#hget(key, field) ⇒ String?

Get the value of a hash field

Parameters:

  • key (String)

    under which hash is stored

  • field (String)

    name

Returns:

  • (String, nil)

    the value associated with field or nil when field is not present in the hash or key does not exist.

See Also:



36
37
38
# File 'lib/oxblood/commands/hashes.rb', line 36

def hget(key, field)
  run(:HGET, key, field)
end

#hgetall(key) ⇒ Array

Get all the fields and values in a hash

Parameters:

  • key (String)

    under which hash is stored

Returns:

  • (Array)

    list of fields and their values stored in the hash, or an empty list when key does not exist.

See Also:



47
48
49
# File 'lib/oxblood/commands/hashes.rb', line 47

def hgetall(key)
  run(:HGETALL, key)
end

#hincrby(key, field, increment) ⇒ Integer

Increment the integer value of a hash field by the given number

Parameters:

  • key (String)

    under which hash is stored

  • field (String)

    to increment

  • increment (Integer)

    by value

Returns:

  • (Integer)

    the value at field after the increment operation

See Also:



59
60
61
# File 'lib/oxblood/commands/hashes.rb', line 59

def hincrby(key, field, increment)
  run(:HINCRBY, key, field, increment)
end

#hincrbyfloat(key, field, increment) ⇒ String, RError

Increment the float value of a hash field by the given number

Parameters:

  • key (String)

    under which hash is stored

  • field (String)

    to increment

  • increment (Integer)

    by value

Returns:

  • (String)

    the value of field after the increment

  • (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.

See Also:



74
75
76
# File 'lib/oxblood/commands/hashes.rb', line 74

def hincrbyfloat(key, field, increment)
  run(:HINCRBYFLOAT, key, field, increment)
end

#hkeys(key) ⇒ Array

Get all the keys in a hash

Parameters:

  • key (String)

Returns:

  • (Array)

    list of fields in the hash, or an empty list when key does not exist.

See Also:



85
86
87
# File 'lib/oxblood/commands/hashes.rb', line 85

def hkeys(key)
  run(:HKEYS, key)
end

#hlen(key) ⇒ Integer

Get the number of keys in a hash

Parameters:

  • key (String)

Returns:

  • (Integer)

    number of fields in the hash, or 0 when key does not exist.

See Also:



96
97
98
# File 'lib/oxblood/commands/hashes.rb', line 96

def hlen(key)
  run(:HLEN, key)
end

#hmget(key, *fields) ⇒ Array

Get the field values of all given hash fields

Parameters:

  • key (String)

    under which hash is stored

  • fields (String, Array<String>)

    to get

Returns:

  • (Array)

    list of values associated with the given fields, in the same order as they are requested.

See Also:



108
109
110
# File 'lib/oxblood/commands/hashes.rb', line 108

def hmget(key, *fields)
  run(*fields.unshift(:HMGET, key))
end

#hmset(key, *args) ⇒ String

Set multiple hash fields to multiple values

Parameters:

  • key (String)

    under which store hash

  • args ([String, String], Array<[String, String]>)

    fields and values

Returns:

  • (String)

    ‘OK’

See Also:



119
120
121
# File 'lib/oxblood/commands/hashes.rb', line 119

def hmset(key, *args)
  run(*args.unshift(:HMSET, key))
end

#hscan(key, cursor, opts = {}) ⇒ Array

Incrementally iterate hash fields and associated values

Parameters:

  • cursor (Integer)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :count (Integer)

    Amount of work that should be done at every call in order to retrieve elements from the collection.

  • :match (String)

Returns:

  • (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.

See Also:



185
186
187
188
189
# 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) ⇒ Integer

Set the string value of a hash field

Parameters:

  • key (String)
  • field (String)
  • value (String)

Returns:

  • (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.

See Also:



132
133
134
# File 'lib/oxblood/commands/hashes.rb', line 132

def hset(key, field, value)
  run(:HSET, key, field, value)
end

#hsetnx(key, field, value) ⇒ Integer

Set the value of a hash field, only if the field does not exist

Parameters:

  • key (String)
  • field (String)
  • value (String)

Returns:

  • (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.

See Also:



145
146
147
# File 'lib/oxblood/commands/hashes.rb', line 145

def hsetnx(key, field, value)
  run(:HSETNX, key, field, value)
end

#hstrlen(key, field) ⇒ Integer

Get the length of the value of a hash field

Parameters:

  • key (String)
  • field (String)

Returns:

  • (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.

See Also:



157
158
159
# File 'lib/oxblood/commands/hashes.rb', line 157

def hstrlen(key, field)
  run(:HSTRLEN, key, field)
end

#hvals(key) ⇒ Array

Get all values in a hash

Parameters:

  • key (String)

Returns:

  • (Array)

    list of values in the hash, or an empty list when key does not exist

See Also:



168
169
170
# File 'lib/oxblood/commands/hashes.rb', line 168

def hvals(key)
  run(:HVALS, key)
end