lib/legion/cache/redis.rb in legion-cache-0.2.1 vs lib/legion/cache/redis.rb in legion-cache-1.0.0

- old
+ new

@@ -1,39 +1,50 @@ require 'redis' module Legion module Cache module Redis - def connect + extend self + + def client + return @client unless @client.nil? + @client = ::Redis.new + @connected = true + @client end + def connected? + @connected ||= false + end + def close - @client.close + client.close end def restart close - connect + @client = nil + client end def get(key) - @client.get(key) + client.get(key) end alias fetch get def set(key, value, ttl: nil) args = {} args[:ex] = ttl unless ttl.nil? - @client.set(key, value, **args) == 'OK' + client.set(key, value, **args) == 'OK' end def delete(key) - @client.del(key) == 1 + client.del(key) == 1 end def flush - @client.flushdb == 'OK' + client.flushdb == 'OK' end end end end