lib/ramaze/cache/redis.rb in ramaze-2012.12.08 vs lib/ramaze/cache/redis.rb in ramaze-2023.01.06

- old
+ new

@@ -1,6 +1,6 @@ -require 'redis' +require 'redis-namespace' module Ramaze class Cache ## # The Redis cache is a cache driver for Redis (http://redis.io/). Redis is a @@ -100,12 +100,12 @@ # def cache_setup(hostname, username, appname, cachename) options[:namespace] = [ 'ramaze', hostname, username, appname, cachename ].compact.join(':') - - @client = ::Redis.new(options) + redis_connection = ::Redis.new + @client = ::Redis::Namespace.new(options[:namespace], redis: redis_connection) end ## # Clears the entire cache. # @@ -121,11 +121,11 @@ # # @author Michael Fellinger # @param [Array] keys An array of key names to remove. # def cache_delete(*keys) - @client.del(*keys.map{|key| namespaced_key(key) }) + @client.del(*keys) end ## # Retrieves the value of the given key. If no value could be retrieved the # default value (set to nil by default) will be returned instead. @@ -134,11 +134,11 @@ # @param [String] key The name of the key to retrieve. # @param [Mixed] default The default value. # @return [Mixed] # def cache_fetch(key, default = nil) - value = @client.get(namespaced_key(key)) + value = @client.get(key) value.nil? ? default : ::Marshal.load(value) end ## # Stores a new value under the given key. @@ -148,19 +148,16 @@ # @param [Mixed] value The value of the key. # @param [Fixnum] ttl The Time To Live of the key. # @param [Hash] options A hash containing key specific options. # @option options :expires_in The time after which the key should expire. # - def cache_store(key, value, ttl = nil, options = {}) + def cache_store(key, value, options = {}) ttl = options[:ttl] || @options[:expires_in] - @client.setex(namespaced_key(key), ttl, ::Marshal.dump(value)) + @client.setex(key, ttl, ::Marshal.dump(value)) return value end - - def namespaced_key(key) - [options[:namespace], key].join(':') - end + end # Redis end # Cache end # Ramaze