require 'redis' module Legion module Cache module Redis 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 end def restart close @client = nil client end def 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' end def delete(key) client.del(key) == 1 end def flush client.flushdb == 'OK' end end end end