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.
3
Answers
https://redis.io/commands/set vs https://redis.io/commands/setex
and yes, serialize the data with serialize or jasn_encode.
psetex
is precisesetex
, meaning the units for the TTL are in milliseconds, not in seconds. See https://redis.io/commands/psetexAs 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
orPEXPIRE
.As others have described
SETEX
takes the TTL in seconds andPSETEX
takes it in milliseconds.You can have
PhpRedis
handle the serialization for you though:setOption examples in the docs