Skip to content
This repository was archived by the owner on Jul 24, 2019. It is now read-only.

Commit e055335

Browse files
committed
Bigint support in HINCRBY, test fixes.
1 parent 9ee596c commit e055335

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

redis.c

+19-6
Original file line numberDiff line numberDiff line change
@@ -4029,23 +4029,36 @@ PHP_METHOD(Redis, hIncrBy)
40294029
{
40304030
zval *object;
40314031
RedisSock *redis_sock;
4032-
char *key = NULL, *cmd, *member;
4033-
int key_len, member_len, cmd_len;
4034-
long val;
4032+
char *key = NULL, *cmd, *member, *val;
4033+
int key_len, member_len, cmd_len, val_len;
4034+
int i;
40354035

4036-
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ossl",
4036+
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osss",
40374037
&object, redis_ce,
4038-
&key, &key_len, &member, &member_len, &val) == FAILURE) {
4038+
&key, &key_len, &member, &member_len, &val, &val_len) == FAILURE) {
40394039
RETURN_FALSE;
40404040
}
40414041

40424042
if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
40434043
RETURN_FALSE;
40444044
}
40454045

4046+
/* check for validity of numeric string */
4047+
i = 0;
4048+
if(val_len && val[0] == '-') { /* negative case */
4049+
i++;
4050+
}
4051+
for(i = 0; i < val_len; ++i) {
4052+
if(val[i] < '0' || val[i] > '9') {
4053+
RETURN_FALSE;
4054+
}
4055+
}
4056+
4057+
4058+
40464059
/* HINCRBY key member amount */
40474060
int key_free = redis_key_prefix(redis_sock, &key, &key_len);
4048-
cmd_len = redis_cmd_format_static(&cmd, "HINCRBY", "ssd", key, key_len, member, member_len, val);
4061+
cmd_len = redis_cmd_format_static(&cmd, "HINCRBY", "sss", key, key_len, member, member_len, val, val_len);
40494062
if(key_free) efree(key);
40504063

40514064
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);

tests/TestRedis.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,8 @@ public function testHashes() {
18021802
$this->redis->delete('h');
18031803
$this->assertTrue(2 === $this->redis->hIncrBy('h', 'x', 2));
18041804
$this->assertTrue(3 === $this->redis->hIncrBy('h', 'x', 1));
1805+
$this->assertTrue(FALSE === $this->redis->hIncrBy('h', 'x', "not-a-number"));
1806+
$this->assertTrue("3" === $this->redis->hGet('h', 'x'));
18051807

18061808
$this->redis->hSet('h', 'y', 'not-a-number');
18071809
$this->assertTrue(FALSE === $this->redis->hIncrBy('h', 'y', 1));
@@ -1839,7 +1841,9 @@ public function testSetRange() {
18391841
$this->redis->setRange('key', 6, 'you'); // don't cut off the end
18401842
$this->assertTrue('hello youis' === $this->redis->get('key'));
18411843

1842-
$this->assertTrue(FALSE === $this->redis->setRange('key', -1, 'plop')); // doesn't work with negative offsets
1844+
$this->redis->set('key', 'hello world');
1845+
$this->assertTrue(11 === $this->redis->setRange('key', -6, 'redis')); // works with negative offsets too!
1846+
$this->assertTrue('hello redis' === $this->redis->get('key'));
18431847

18441848
// fill with zeros if needed
18451849
$this->redis->delete('key');

0 commit comments

Comments
 (0)