Class: Redis::BaseObject
- Inherits:
-
Object
- Object
- Redis::BaseObject
- Defined in:
- lib/redis/base_object.rb
Overview
Defines base functionality for all redis-objects.
Instance Method Summary collapse
- #allow_expiration(&block) ⇒ Object
-
#initialize(key, *args) ⇒ BaseObject
constructor
A new instance of BaseObject.
-
#redis ⇒ Object
Dynamically query the handle to enable resetting midstream.
- #set_expiration ⇒ Object
Constructor Details
#initialize(key, *args) ⇒ BaseObject
Returns a new instance of BaseObject.
4 5 6 7 8 |
# File 'lib/redis/base_object.rb', line 4 def initialize(key, *args) @key = key.is_a?(Array) ? key.flatten.join(':') : key @options = args.last.is_a?(Hash) ? args.pop : {} @myredis = Objects::ConnectionPoolProxy.proxy_if_needed(args.first) end |
Instance Method Details
#allow_expiration(&block) ⇒ Object
25 26 27 28 29 |
# File 'lib/redis/base_object.rb', line 25 def allow_expiration(&block) result = block.call set_expiration result end |
#redis ⇒ Object
Dynamically query the handle to enable resetting midstream
11 12 13 |
# File 'lib/redis/base_object.rb', line 11 def redis @myredis || ::Redis::Objects.redis end |
#set_expiration ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/redis/base_object.rb', line 17 def set_expiration if !@options[:expiration].nil? redis.expire(@key, @options[:expiration]) if redis.ttl(@key) < 0 elsif !@options[:expireat].nil? redis.expireat(@key, @options[:expireat].to_i) if redis.ttl(@key) < 0 end end |