We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Update Redis Key Value

Hi,

How can i update existing redis key value? Like everytime i add collection data it updates the existing redis key value instead of deleting all the value of the key it will just append on the existing value. append() in redis itself exist while in phalcon dont. What will be the version of append in phalcon for redis?

https://redis.io/commands/append

edited Feb '16

Phalcon Redis cache adapter doesn't support append, it will replace given key with new value

https://docs.phalcon.io/en/latest/api/Phalcon_Cache_Backend_Redis.html https://github.com/phalcon/cphalcon/blob/master/phalcon/cache/backend/redis.zep

if you need this, you have to use

https://github.com/phpredis/phpredis#append

which supports append



7.7k

Thanks to this @ david let me try to make it work on my end using phpredis



7.7k

Hi @david,

How can i make phpredis work on phalcon? Do you have example on this?

It is PECL package https://pecl.php.net/package/redis

If you use Linux, install it via

apt-get install php5-redis on Debian
yum install php-redis on Red Hat

Than register service container to you DI and use.

$di->set(function () {
  $redis = new Redis();
  $redis->connect('127.0.0.1', 6379);
  return $redis; 
}


7.7k

I already have this service on my end

is this different from the one you sent?

//Redis cache $di->set("Redis",function () use($config){ $frontCache = new \Phalcon\Cache\Frontend\Data( array( "lifetime" => $config->lifeTime->RedCache ) );

$cache = new \Phalcon\Cache\Backend\Redis($frontCache,
    array(
        'host' => $config->redis->host,
        'port' => $config->redis->port,
        'auth' => $config->redis->auth,
        'persistent' => $config->redis->persistent,
        'index' => 1,
    )
);
return $cache;

}, true);

I can use all the redis commands except for some like append thing.

edited Mar '16

Hey, your service uses standard Phalcon Redis cache backend, which doesn't support append, you have to use standard PHP extension for \Redis if you want to use append.

If you want to use it as Cache backend, you have to implement you own wrapper above \Redis which will implement \Phalcon\Cache\BackendInterface.