Home » Php » what is the diff b/w pset and psetx in php redis?Is it possible set a array as value with it?

what is the diff b/w pset and psetx in php redis?Is it possible set a array as value with it?

Posted by: admin February 25, 2020 Leave a comment

Questions:
$redisClient -> setex('key', 3600, 'value' );

and

$redisClient -> psetex('key', 3600, 'value' );
How to&Answers:

https://redis.io/commands/set vs https://redis.io/commands/setex

and yes, serialize the data with serialize or jasn_encode.

Answer:

psetex is precise setex, meaning the units for the TTL are in milliseconds, not in seconds. See https://redis.io/commands/psetex

As value, you can set any binary-safe string. You can store an array serialized in your preferred format, like JSON or CSV, but every operation you do on the array you have to read in full and write back in full.

Consider the other data types in Redis: lists, sets, sorted sets, hash (maps). Chances are another data type is a better fit for your requirement. See https://redis.io/topics/data-types

You can always set an expiration on any type of key using EXPIRE or PEXPIRE.