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?

http://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.phalconphp.com/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



1.8k

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



1.8k

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; 
}


1.8k

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.