Class: Redis::Value
Overview
Class representing a simple value. You can use standard Ruby operations on it.
Instance Attribute Summary collapse
Instance Method Summary
collapse
#delete, #exists?, #expire, #expireat, #marshal, #move, #persist, #rename, #renamenx, #sort, #ttl, #type, #unmarshal
Methods inherited from BaseObject
#allow_expiration, #redis, #set_expiration
Constructor Details
#initialize(key, *args) ⇒ Value
Returns a new instance of Value.
12
13
14
15
|
# File 'lib/redis/value.rb', line 12
def initialize(key, *args)
super(key, *args)
redis.setnx(key, marshal(@options[:default])) if !@options[:default].nil?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
42
43
44
|
# File 'lib/redis/value.rb', line 42
def method_missing(*args)
self.value.send *args
end
|
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
11
12
13
|
# File 'lib/redis/value.rb', line 11
def key
@key
end
|
#options ⇒ Object
Returns the value of attribute options.
11
12
13
|
# File 'lib/redis/value.rb', line 11
def options
@options
end
|
Instance Method Details
#==(other) ⇒ Object
37
|
# File 'lib/redis/value.rb', line 37
def ==(other); value == other end
|
#as_json(*args) ⇒ Object
39
|
# File 'lib/redis/value.rb', line 39
def as_json(*args); value.as_json *args end
|
#inspect ⇒ Object
33
34
35
|
# File 'lib/redis/value.rb', line 33
def inspect
"#<Redis::Value #{value.inspect}>"
end
|
#nil? ⇒ Boolean
38
|
# File 'lib/redis/value.rb', line 38
def nil?; value.nil? end
|
#to_json(*args) ⇒ Object
40
|
# File 'lib/redis/value.rb', line 40
def to_json(*args); value.to_json *args end
|
#value ⇒ Object
Also known as:
get
28
29
30
|
# File 'lib/redis/value.rb', line 28
def value
unmarshal redis.get(key)
end
|
#value=(val) ⇒ Object
Also known as:
set
17
18
19
20
21
22
23
24
25
|
# File 'lib/redis/value.rb', line 17
def value=(val)
allow_expiration do
if val.nil?
delete
else
redis.set key, marshal(val)
end
end
end
|