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:



11
12
13
# File 'lib/oxblood/commands/hashes.rb', line 11

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:



22
23
24
# File 'lib/oxblood/commands/hashes.rb', line 22

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:



34
35
36
# File 'lib/oxblood/commands/hashes.rb', line 34

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:



45
46
47
# File 'lib/oxblood/commands/hashes.rb', line 45

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:



57
58
59
# File 'lib/oxblood/commands/hashes.rb', line 57

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:



72
73
74
# File 'lib/oxblood/commands/hashes.rb', line 72

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:



83
84
85
# File 'lib/oxblood/commands/hashes.rb', line 83

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:



94
95
96
# File 'lib/oxblood/commands/hashes.rb', line 94

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:



106
107
108
# File 'lib/oxblood/commands/hashes.rb', line 106

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:



117
118
119
# File 'lib/oxblood/commands/hashes.rb', line 117

def hmset(key, *args)
  run(*args.unshift(:HMSET, key))
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:



130
131
132
# File 'lib/oxblood/commands/hashes.rb', line 130

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:



143
144
145
# File 'lib/oxblood/commands/hashes.rb', line 143

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:



155
156
157
# File 'lib/oxblood/commands/hashes.rb', line 155

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:



166
167
168
# File 'lib/oxblood/commands/hashes.rb', line 166

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