Class: Conflow::Redis::ValueField Private

Inherits:
Field
  • Object
show all
Defined in:
lib/conflow/redis/value_field.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents single value (Redis String). Values are serialized as JSON in order to preserve type.

Instance Attribute Summary

Attributes inherited from Field

#key

Instance Method Summary collapse

Methods inherited from Field

#initialize

Constructor Details

This class inherits a constructor from Conflow::Redis::Field

Instance Method Details

#==(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if equal.

Parameters:

Returns:

  • (Boolean)

    true if equal



24
25
26
27
28
29
30
# File 'lib/conflow/redis/value_field.rb', line 24

def ==(other)
  case other
  when String, Numeric then value == other
  when ValueField      then key == other.key || to_s == other.to_s
  else super
  end
end

#default(value) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

value must be serializable through JSON.dump

Returns Redis response.

Parameters:

  • value (Object)

    value to be assigned to field (unless key already holds value)

Returns:

  • (String)

    Redis response



18
19
20
# File 'lib/conflow/redis/value_field.rb', line 18

def default(value)
  command :set, [key, JSON.dump(value), nx: true]
end

#overwrite(value) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

value must be serializable through JSON.dump

Returns Redis response.

Parameters:

  • value (Object)

    new value to be saved

Returns:

  • (String)

    Redis response



11
12
13
# File 'lib/conflow/redis/value_field.rb', line 11

def overwrite(value)
  command :set, [key, JSON.dump(value)]
end

#to_sString? Also known as: to_str

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns String representation of value.

Returns:

  • (String, nil)

    String representation of value



33
34
35
# File 'lib/conflow/redis/value_field.rb', line 33

def to_s
  value&.to_s
end

#valueObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns JSON-parsed value present in Redis.

Returns:

  • (Object)

    JSON-parsed value present in Redis



38
39
40
41
# File 'lib/conflow/redis/value_field.rb', line 38

def value
  result = command(:get, [key])
  result && JSON.parse(result)
end