php - phpredis function mSet with ttl -


i'm using memcached, i'm trying move mechanism redis.

my goal save entire array (key => value) every 1000 iterations.

old solution:

<?php $data = array(     'key1' => 'value1',     'key2' => 'value2',     'key3' => 'value3' ); $memcached->setmulti($data, time()+864000); 

new solution:

<?php $data = array(     'key1' => 'value1',     'key2' => 'value2',     'key3' => 'value3' ); $redis->mset($data); 

the operation of these scripts identical.

as can see, redis can not set expire date when i'm using multi (mset function).

any solution?

mset doesn't support ex , px options available set. have 2 options depending on needs:

  • if need atomic, use either transactions or lua scripting. example transactions (from redis-cli) this:

    > multi

    ok

    > set key1 value1 ex 10

    queued

    > set key2 value2 ex 10

    queued

    > exec

i'm not familiar phpredis, has abstraction handles you.

  • if don't need atomicity, can use pipelining multiple set commands.

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -