Class: Redis::Value
- Inherits:
-
Object
- Object
- Redis::Value
- Includes:
- Helpers::CoreCommands, Helpers::Serialize
- Defined in:
- lib/redis/value.rb
Overview
Class representing a simple value. You can use standard Ruby operations on it.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
- #==(x) ⇒ Object
-
#initialize(key, *args) ⇒ Value
constructor
A new instance of Value.
- #nil? ⇒ Boolean
- #to_s ⇒ Object (also: #to_str)
- #value ⇒ Object (also: #get)
- #value=(val) ⇒ Object (also: #set)
Methods included from Helpers::Serialize
Methods included from Helpers::CoreCommands
#delete, #exists?, #expire, #expireat, #move, #rename, #renamenx, #type
Constructor Details
#initialize(key, *args) ⇒ Value
Returns a new instance of Value.
12 13 14 15 16 17 |
# File 'lib/redis/value.rb', line 12 def initialize(key, *args) @key = key @options = args.last.is_a?(Hash) ? args.pop : {} @redis = args.first || $redis @redis.setnx(key, @options[:default]) if @options[:default] end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
11 12 13 |
# File 'lib/redis/value.rb', line 11 def key @key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/redis/value.rb', line 11 def @options end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
11 12 13 |
# File 'lib/redis/value.rb', line 11 def redis @redis end |
Instance Method Details
#==(x) ⇒ Object
32 |
# File 'lib/redis/value.rb', line 32 def ==(x); value == x; end |
#nil? ⇒ Boolean
33 |
# File 'lib/redis/value.rb', line 33 def nil?; value.nil?; end |
#to_s ⇒ Object Also known as: to_str
29 |
# File 'lib/redis/value.rb', line 29 def to_s; value.to_s; end |
#value ⇒ Object Also known as: get
24 25 26 |
# File 'lib/redis/value.rb', line 24 def value from_redis redis.get(key) end |
#value=(val) ⇒ Object Also known as: set
19 20 21 |
# File 'lib/redis/value.rb', line 19 def value=(val) redis.set key, to_redis(val) end |