Home > Backend Development > PHP Tutorial > PHP redis hIncrBy 递增出现问题

PHP redis hIncrBy 递增出现问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:24:08
Original
1941 people have browsed it

PHP redis hIncrBy 递增出现问题

第一次请求的时候,hGetAll返回的count_comment58,然后hincrBy +1后再hGetAll,返回的count_comment预期为59却变成1了。没有实现预期递增效果。

PHP redis hIncrBy 递增出现问题

再次执行同样请求,hGetAll返回的count_comment1,然后hincrBy +1后再hGetAll,返回的count_comment2了。这次请求hincrBy +1是实现的预期递增。

PHP redis hIncrBy 递增出现问题

不太清楚是什么情况造成,找了好久没找到原因。
这里的redis中使用phpredis来连接
count_comment都是string类型。

回复内容:

PHP redis hIncrBy 递增出现问题

第一次请求的时候,hGetAll返回的count_comment58,然后hincrBy +1后再hGetAll,返回的count_comment预期为59却变成1了。没有实现预期递增效果。

PHP redis hIncrBy 递增出现问题

再次执行同样请求,hGetAll返回的count_comment1,然后hincrBy +1后再hGetAll,返回的count_comment2了。这次请求hincrBy +1是实现的预期递增。

PHP redis hIncrBy 递增出现问题

不太清楚是什么情况造成,找了好久没找到原因。
这里的redis中使用phpredis来连接
count_comment都是string类型。

我找到问题了

This is expected, you can't run INCR, INCRBY, or HINCRBY on serialized data.

初始化redis时,使用的是SERIALIZER格式下存储

<code>$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);</code>
Copy after login
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template