Class: Conflow::Redis::ValueField Private
- 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
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
private
True if equal.
-
#default(value) ⇒ String
private
Redis response.
-
#overwrite(value) ⇒ String
private
Redis response.
-
#to_s ⇒ String?
(also: #to_str)
private
String representation of value.
-
#value ⇒ Object
private
JSON-parsed value present in Redis.
Methods inherited from Field
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.
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.
value must be serializable through JSON.dump
Returns 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.
value must be serializable through JSON.dump
Returns 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_s ⇒ String? 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.
33 34 35 |
# File 'lib/conflow/redis/value_field.rb', line 33 def to_s value&.to_s end |
#value ⇒ Object
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.
38 39 40 41 |
# File 'lib/conflow/redis/value_field.rb', line 38 def value result = command(:get, [key]) result && JSON.parse(result) end |