Class: Conflow::Redis::ValueField
- Defined in:
- lib/conflow/redis/value_field.rb
Overview
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) ⇒ String
Redis response.
-
#default(value) ⇒ String
Redis response.
-
#nil? ⇒ Boolean
True if object does not exist in Redis, else otherwise.
-
#overwrite(value) ⇒ String
Redis response.
-
#to_s ⇒ String?
(also: #to_str)
String representation of value.
-
#value ⇒ Object
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) ⇒ String
Returns Redis response.
24 25 26 27 28 29 30 31 |
# File 'lib/conflow/redis/value_field.rb', line 24 def ==(other) case other when String, Numeric then value == other when Symbol then value.to_sym == other when ValueField then key == other.key || to_s == other.to_s else super end end |
#default(value) ⇒ String
Note:
value must be serializable through JSON.dump
Returns Redis response.
17 18 19 |
# File 'lib/conflow/redis/value_field.rb', line 17 def default(value) command :set, [key, JSON.dump(value), nx: true] end |
#nil? ⇒ Boolean
Returns true if object does not exist in Redis, else otherwise.
34 35 36 |
# File 'lib/conflow/redis/value_field.rb', line 34 def nil? value.nil? end |
#overwrite(value) ⇒ String
Note:
value must be serializable through JSON.dump
Returns Redis response.
10 11 12 |
# File 'lib/conflow/redis/value_field.rb', line 10 def overwrite(value) command :set, [key, JSON.dump(value)] end |
#to_s ⇒ String? Also known as: to_str
Returns String representation of value.
39 40 41 |
# File 'lib/conflow/redis/value_field.rb', line 39 def to_s value&.to_s end |
#value ⇒ Object
Returns JSON-parsed value present in Redis.
44 45 46 47 |
# File 'lib/conflow/redis/value_field.rb', line 44 def value result = command(:get, [key]) result && JSON.parse(result) end |