Method: Redstruct::Hash#set

Defined in:
lib/redstruct/hash.rb

#set(key, value, overwrite: true) ⇒ Boolean

Sets or updates the value at key

Parameters:

  • key (#to_s)

    the hash key

  • value (#to_s)

    the new value to set

Returns:

  • (Boolean)

    true if the field was set (not updated!), false otherwise



39
40
41
42
43
44
45
46
47
# File 'lib/redstruct/hash.rb', line 39

def set(key, value, overwrite: true)
  result = if overwrite
    self.connection.hset(@key, key, value)
  else
    self.connection.hsetnx(@key, key, value)
  end

  return coerce_bool(result)
end