★ wanayoo — archive 1999 https://github.com/phpredis/phpredis/issues/239Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hIncrBy does not works properly #239

Closed
larest opened this issue Aug 29, 2012 · 1 comment
Closed

hIncrBy does not works properly #239

larest opened this issue Aug 29, 2012 · 1 comment

Comments

@larest
Copy link

@larest larest commented Aug 29, 2012

hIncrBy - spoil hash key

<?php

$redis = new Redis();
$config=new stdClass();
$config->host='127.0.0.1';
$config->port=6379;
$config->timeout=2;
$config->dbIndex=0;

$redis->connect($config->host, $config->port, $config->timeout);

$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);
$redis->select($config->dbIndex);

$key = 'UserFacts:1';
$hashKey = 'NumOfSomethingImportant';
$redis->hSet($key, $hashKey,2);

$hGet1 = $redis->hGet($key, $hashKey);
echo "hGet1:";var_dump($hGet1);

$hIncrBy=$redis->hIncrBy($key,$hashKey,1);
echo "hIncrBy:"; var_dump($hIncrBy);

$hGet2 = $redis->hGet($key, $hashKey);
echo "hGet2:";var_dump($hGet2);

echo "<br>expect hGet2=3, got:".$hGet2;

The script return:
hGet1:int(2)
hIncrBy:int(1)
hGet2:NULL

expect hGet2=3, got:

Enviroment:

PHP Version 5.3.15
System Linux cebo.loc 2.6.18-308.11.1.el5 #1 SMP Tue Jul 10 08:48:43 EDT 2012 x86_64
Server API Apache 2.0 Handler
Redis Version 2.2.2

unusual php extensions:
amqp,apc,xdebug,xhprof

@nicolasff
Copy link
Contributor

@nicolasff nicolasff commented Aug 29, 2012

Hello,

This is expected, you can't run INCR, INCRBY, or HINCRBY on serialized data.
There is no way around it, I'm afraid: the data is in binary form, we can't use read-modify-write as it wouldn't be atomic. You can use WATCH and do the read-modify-write yourself, that's the easiest way.

Nicolas

@nicolasff nicolasff closed this Aug 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.