Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a12758

Browse files
Fix incrby/decrby for large integers
1 parent 9df734a commit 3a12758

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

redis_commands.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,13 +1382,13 @@ redis_atomic_increment(INTERNAL_FUNCTION_PARAMETERS, int type,
13821382
if (val == 1) {
13831383
*cmd_len = redis_cmd_format_static(cmd,"INCR","s",key,key_len);
13841384
} else {
1385-
*cmd_len = redis_cmd_format_static(cmd,"INCRBY","sd",key,key_len,val);
1385+
*cmd_len = redis_cmd_format_static(cmd,"INCRBY","sl",key,key_len,val);
13861386
}
13871387
} else {
13881388
if (val == 1) {
13891389
*cmd_len = redis_cmd_format_static(cmd,"DECR","s",key,key_len);
13901390
} else {
1391-
*cmd_len = redis_cmd_format_static(cmd,"DECRBY","sd",key,key_len,val);
1391+
*cmd_len = redis_cmd_format_static(cmd,"DECRBY","sl",key,key_len,val);
13921392
}
13931393
}
13941394

tests/RedisTest.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,32 +480,35 @@ public function testIncr()
480480
$this->redis->set('key', 0);
481481

482482
$this->redis->incr('key');
483-
$this->assertEquals(1, (int)$this->redis->get('key'));
483+
$this->assertEquals(1, (int)$this->redis->get('key'));
484484

485485
$this->redis->incr('key');
486-
$this->assertEquals(2, (int)$this->redis->get('key'));
486+
$this->assertEquals(2, (int)$this->redis->get('key'));
487487

488-
$this->redis->incrBy('key', 3);
489-
$this->assertEquals(5, (int)$this->redis->get('key'));
488+
$this->redis->incrBy('key', 3);
489+
$this->assertEquals(5, (int)$this->redis->get('key'));
490490

491-
$this->redis->incrBy('key', 1);
492-
$this->assertEquals(6, (int)$this->redis->get('key'));
491+
$this->redis->incrBy('key', 1);
492+
$this->assertEquals(6, (int)$this->redis->get('key'));
493493

494-
$this->redis->incrBy('key', -1);
495-
$this->assertEquals(5, (int)$this->redis->get('key'));
494+
$this->redis->incrBy('key', -1);
495+
$this->assertEquals(5, (int)$this->redis->get('key'));
496496

497-
$this->redis->incr('key', 5);
498-
$this->assertEquals(10, (int)$this->redis->get('key'));
497+
$this->redis->incr('key', 5);
498+
$this->assertEquals(10, (int)$this->redis->get('key'));
499499

500-
$this->redis->del('key');
500+
$this->redis->del('key');
501+
502+
$this->redis->set('key', 'abc');
501503

502-
$this->redis->set('key', 'abc');
504+
$this->redis->incr('key');
505+
$this->assertTrue("abc" === $this->redis->get('key'));
503506

504-
$this->redis->incr('key');
505-
$this->assertTrue("abc" === $this->redis->get('key'));
507+
$this->redis->incr('key');
508+
$this->assertTrue("abc" === $this->redis->get('key'));
506509

507-
$this->redis->incr('key');
508-
$this->assertTrue("abc" === $this->redis->get('key'));
510+
$this->redis->set('key', 0);
511+
$this->assertEquals(2147483648, $this->redis->incrby('key', 2147483648));
509512
}
510513

511514
public function testIncrByFloat()

0 commit comments

Comments
 (0)