class Asynchronic::DataStore::Redis
Constants
- LOCKED
Attributes
options[R]
scope[R]
Public Class Methods
connect(*args)
click to toggle source
# File lib/asynchronic/data_store/redis.rb, line 9 def self.connect(*args) new(*args) end
new(scope, options={})
click to toggle source
# File lib/asynchronic/data_store/redis.rb, line 13 def initialize(scope, options={}) @scope = Key[scope] @options = options end
Public Instance Methods
[](key)
click to toggle source
# File lib/asynchronic/data_store/redis.rb, line 18 def [](key) value = redis.call! 'GET', scope[key] value ? Marshal.load(value) : nil rescue => ex Asynchronic.logger.warn('Asynchronic') { ex.message } value end
[]=(key, value)
click to toggle source
# File lib/asynchronic/data_store/redis.rb, line 26 def []=(key, value) redis.call! 'SET', scope[key], Marshal.dump(value) end
connection_args()
click to toggle source
# File lib/asynchronic/data_store/redis.rb, line 52 def connection_args [scope, options] end
delete(key)
click to toggle source
# File lib/asynchronic/data_store/redis.rb, line 30 def delete(key) redis.call! 'DEL', scope[key] end
delete_cascade(key)
click to toggle source
# File lib/asynchronic/data_store/redis.rb, line 34 def delete_cascade(key) redis.call! 'DEL', scope[key] redis.call!('KEYS', scope[key]['*']).each { |k| redis.call! 'DEL', k } end
keys()
click to toggle source
# File lib/asynchronic/data_store/redis.rb, line 39 def keys redis.call!('KEYS', scope['*']).map { |k| Key[k].remove_first } end
synchronize(key) { || ... }
click to toggle source
# File lib/asynchronic/data_store/redis.rb, line 43 def synchronize(key) while redis.call!('GETSET', scope[key][LOCKED], LOCKED) == LOCKED sleep Asynchronic.redis_data_store_sync_timeout end yield ensure redis.call! 'DEL', scope[key][LOCKED] end
Private Instance Methods
redis()
click to toggle source
# File lib/asynchronic/data_store/redis.rb, line 60 def redis @redis ||= Asynchronic.establish_redis_connection options end