Heim  >  Artikel  >  Backend-Entwicklung  >  PHP redis hIncrBy 递增出现问题

PHP redis hIncrBy 递增出现问题

WBOY
WBOYOriginal
2016-06-06 20:24:081865Durchsuche

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>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn