Maison  >  Article  >  développement back-end  >  PHP redis hIncrBy 递增出现问题

PHP redis hIncrBy 递增出现问题

WBOY
WBOYoriginal
2016-06-06 20:24:081865parcourir

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>
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn