We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
Example fix is to provide a key prefix (need to unit test this):
class CacheProviderRedis implements CacheProviderInterface { /** * Trace logger. * * @var \Alpha\Util\Logging\Logger * * @since 1.2.4 */ private static $logger = null; /** * Connection to the cache server. * * @var Redis * * @since 1.2.4 */ private $connection; /** * Cache key prefix to use, based on the application title, to prevent key clashes between different apps * using the same cache provider. * * @var string * * @since 3.0.0 */ private $appPrefix; /** * Constructor. * * @since 1.2.4 */ public function __construct() { self::$logger = new Logger('CacheProviderRedis'); $config = ConfigProvider::getInstance(); $this->appPrefix = base64_encode($config->get('app.title')); try { $this->connection = new Redis(); $this->connection->connect($config->get('cache.redis.host'), $config->get('cache.redis.port')); $this->connection->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); $this->connection->select($config->get('cache.redis.db')); } catch (\Exception $e) { self::$logger->error('Error while attempting to connect to Redis cache: ['.$e->getMessage().']'); } } /** * {@inheritdoc} */ public function get($key) { self::$logger->debug('>>get(key=['.$key.'])'); try { $value = $this->connection->get($this->appPrefix.'-'.$key); self::$logger->debug('<<get: ['.print_r($value, true).'])'); return $value; } catch (\Exception $e) { self::$logger->error('Error while attempting to load a business object from Redis instance: ['.$e->getMessage().']'); self::$logger->debug('<<get: [false])'); return false; } } /** * {@inheritdoc} */ public function set($key, $value, $expiry = 0) { try { if ($expiry > 0) { $this->connection->setex($this->appPrefix.'-'.$key, $expiry, $value); } else { $this->connection->set($this->appPrefix.'-'.$key, $value); } } catch (\Exception $e) { self::$logger->error('Error while attempting to store a value to Redis instance: ['.$e->getMessage().']'); } } /** * {@inheritdoc} */ public function delete($key) { try { $this->connection->delete($this->appPrefix.'-'.$key); } catch (\Exception $e) { self::$logger->error('Error while attempting to remove a value from Redis instance: ['.$e->getMessage().']'); } } }
Sorry, something went wrong.
#334 - added the appPrefix attribute to each of the CacheProviderInte…
66a53ef
…rface providers to ensure that multiple apps using the same caching service do not have a key clash
alphadevx
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: