Shopsys: make redis cache handling consistent

Created on 6 Jun 2019  路  3Comments  路  Source: shopsys/shopsys

What is happening


Now there seems to be inconsistency from the view of the redis-check redis-clean and redis-clean-old-version

  • CheckRedisCommand
    yaml Shopsys\FrameworkBundle\Command\CheckRedisCommand: arguments: $cacheClients: - '@snc_redis.bestselling_products' - '@snc_redis.doctrine_metadata' - '@snc_redis.doctrine_query' - '@snc_redis.session' # missing framework_annotations
    php foreach ($this->cacheClients as $cacheClient) { try { $cacheClient->ping();
  • RedisCleanCacheCommand
    yaml Shopsys\FrameworkBundle\Component\Redis\RedisFacade: arguments: $cacheClients: - '@snc_redis.bestselling_products' - '@snc_redis.doctrine_metadata' - '@snc_redis.doctrine_query'
    php $this->redisFacade->cleanCache(); foreach ($this->cacheClients as $redis) { $prefix = (string)$redis->getOption(Redis::OPT_PREFIX); $pattern = $prefix . '*'; if (!$this->hasAnyKey($redis, $pattern)) { continue; } $redis->eval("return redis.call('del', unpack(redis.call('keys', ARGV[1])))", [$pattern]); }
  • RedisCleanCacheOldCommand

    Shopsys\FrameworkBundle\Component\Redis\RedisVersionsFacade:
        arguments:
            $globalClient: '@snc_redis.global'
            $currentVersion: '%build-version%'
    

    ```php
    $this->redisVersionsFacade->cleanOldCache();
    do {
    $keys = $this->globalClient->scan($iterator, $versionPattern);

        if ($keys !== false) {
            $toRemove = [];
    
            foreach ($keys as $key) {
                if (strpos($key, $currentVersionPrefix) === false) {
                    $keyWithoutPrefix = substr($key, strlen($prefix)); 
                    $toRemove[] = $keyWithoutPrefix;
                }
            }
            $this->globalClient->unlink($toRemove);
    

    ```
    As we can see from the check and clean commands, redis cache client can be stored on different redis servers, but as for the redis-clean-old-version removing of old cache is done just via global client.
    Second thing is that if someone wants to implement new cache like Twig, there seems to be no cookbook that tells what framework services should be overriden with new set of cache clients.

Expected result

  • [x] framework_annotation client is handled by redis commands (in #1158 or #1161)
  • [ ] redis-clean redis-clean-old-version redis-check are consistent
  • [ ] cookbook for adding a new cache client (e.g. Twig cache) with integration for redis shopsys commands (phing targets)
Bug DX & Refactoring Documentation Stale

Most helpful comment

There is a reason redis-clean and redis-clean-old-version differ. Regular cleaning is using the version prefix clients but when you need to clean old versions, you have to use "unprefixed" client, and that is the global client. But once prefixed (version) clients are on different servers, then.... yes, it will be a problem :thinking:

All 3 comments

There is a reason redis-clean and redis-clean-old-version differ. Regular cleaning is using the version prefix clients but when you need to clean old versions, you have to use "unprefixed" client, and that is the global client. But once prefixed (version) clients are on different servers, then.... yes, it will be a problem :thinking:

This issue has been automatically marked as stale because there was no activity within the last 4 months (and it is quite a long time). It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because there was no acivity within the last half a year.

Was this page helpful?
0 / 5 - 0 ratings