Get the App
SLTechnology News&Howtos  ›  Database  › 

Redis auto serialization pit ~

Shulou Source: shulou.com Published: 2022-06-01 16:58:36 09月13日 Update

Recently, the project needs to use Redis to store objects / arrays.

Then, as always, follow redis- > set (KEY, OBJECT)

It turns out I can't deposit it.

Then I asked my colleague to try it, but I didn't expect that he could save it.

At that time, I was entangled with the same reids version and configuration, ah, how can he save it directly, but mine has not been able to do so.

After some twists and turns, I suddenly found such an article: https://my.oschina.net/u/222608/blog/1925135

Redis::OPT_SERIALIZER this option controls redis serialization

Then $redis- > getOption (Redis::OPT_SERIALIZER); take this value, and sure enough, it is different. My return is 0, and automatic serialization is not turned on.

The colleague's return is 2; Redis::SERIALIZER_IGBINARY; turns on serialization.

Then I tried it again-> incr.

Sure enough, mine can increase by 1. 5%. Colleagues cannot augment successfully because automatic serialization is turned on.

$redis = new MyRedis ()

$order = OrderModel::findByCondition (['id' = > 45])-> one ()

$ret = $redis- > set ('fltest333',100)

$data = $redis- > get ('fltest333')

Var_dump ($ret,$data)

$ret=$redis- > incr ('fltest333')

$data = $redis- > get ('fltest333')

Var_dump ($ret,$data)

$ret = $redis- > getOption (Redis::OPT_SERIALIZER)

Var_dump ($ret)

Exit

Tags: Sequence colleague no success as always object array version article result project experiment control configuration Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology vpn MySQL Docker Linux