Class: GCoder::Storage::RedisAdapter
Instance Method Summary
collapse
Methods inherited from Adapter
#config, #initialize
Instance Method Details
#clear ⇒ Object
78
79
80
|
# File 'lib/gcoder/storage.rb', line 78
def clear
@rdb.keys(@keyspace + '*').each { |key| @rdb.del(key) }
end
|
#connect ⇒ Object
72
73
74
75
76
|
# File 'lib/gcoder/storage.rb', line 72
def connect
require 'redis'
@rdb = Redis.connect(*[config[:connection]].compact)
@keyspace = "#{config[:keyspace] || 'gcoder'}:"
end
|
#get(key) ⇒ Object
82
83
84
|
# File 'lib/gcoder/storage.rb', line 82
def get(key)
@rdb.get(keyns(key))
end
|
#set(key, value) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/gcoder/storage.rb', line 86
def set(key, value)
if (ttl = config[:key_ttl])
@rdb.setex(keyns(key), ttl, nval(value))
else
@rdb.set(keyns(key), nval(value))
end
end
|