Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis auto serialization pit ~

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report