class Redis::BaseObject
Defines base functionality for all redis-objects.
Attributes
key[R]
options[R]
Public Class Methods
new(key, *args)
click to toggle source
# File lib/redis/base_object.rb, line 10 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
Public Instance Methods
allow_expiration(&block)
click to toggle source
# File lib/redis/base_object.rb, line 33 def allow_expiration(&block) result = block.call set_expiration result end
as_json(*)
click to toggle source
# File lib/redis/base_object.rb, line 45 def as_json(*) to_hash end
redis()
click to toggle source
Dynamically query the handle to enable resetting midstream
# File lib/redis/base_object.rb, line 17 def redis @myredis || ::Redis::Objects.redis end
set_expiration()
click to toggle source
# File lib/redis/base_object.rb, line 23 def set_expiration if !@options[:expiration].nil? redis.expire(@key, @options[:expiration]) if redis.ttl(@key) < 0 elsif !@options[:expireat].nil? expireat = @options[:expireat] at = expireat.respond_to?(:call) ? expireat.call.to_i : expireat.to_i redis.expireat(@key, at) if redis.ttl(@key) < 0 end end
to_hash()
click to toggle source
# File lib/redis/base_object.rb, line 49 def to_hash { "key" => @key, "options" => @options, "value" => value } end
to_json(*args)
click to toggle source
# File lib/redis/base_object.rb, line 39 def to_json(*args) to_hash.to_json(*args) rescue NoMethodError => e raise e.class, "The current runtime does not provide a `to_json` implementation. Require 'json' or another JSON library and try again." end