Why are the values added by redis zadd serialized
getting it through php code will always be serialized
127.0.0.1:6379> ZRANGE key 0 -1 WITHSCORES
1) "i:1;"
2) "1"
3) "s:6:\"google\";"
4) "1"
5) "i:4;"
6) "2"
7) "s:4:\"i:1;\";"
8) "2"
127.0.0.1:6379> ZRANGE key 0 -1 WITHSCORES
but I can add normal directly under cli. Why is that?
127.0.0.1:6379> zadd key 1 google
(integer) 1
127.0.0.1:6379> ZRANGE key 0 -1 WITHSCORES
1) "google"
2) "1"
3) "i:1;"
4) "1"
5) "s:6:\"google\";"
6) "1"
7) "i:4;"
8) "2"
9) "s:4:\"i:1;\";"
10) "2"
127.0.0.1:6379>
because redis kv mode can only store strings, how does the array of PHP become strings? the default is serialization, and deserialization
when fetching. In most cases, we manually convert JSON strings into redis, so it is more convenient for other programs to read.
= Update =
The serialization parameter of the
phpredis
extension has three values, which are
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE); // don't serialize data
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); // use built-in serialize/unserialize
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); // use igBinary serialize/unserialize
use $redis- > getOption (Redis::OPT_SERIALIZER);
method to see which one is configured
found the problem, which solves the problem of turning off serialization
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE); // don't serialize data
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); // use built-in serialize/unserialize
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); // use igBinary serialize/unserialize
$redis->setOption(Redis::OPT_PREFIX, 'myAppName:'); // use custom prefix on all keys