Skip to content

Commit e482f97

Browse files
Merge branch 'hotfix/incrby_float_prefix'
Fixes phpredis#408
2 parents 49dce3b + 2108446 commit e482f97

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

redis.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,13 +1330,11 @@ PHP_METHOD(Redis, incrByFloat) {
13301330
RETURN_FALSE;
13311331
}
13321332

1333-
// Prefix our key, free it if we have
1333+
// Prefix key, format command, free old key if necissary
13341334
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
1335+
cmd_len = redis_cmd_format_static(&cmd, "INCRBYFLOAT", "sf", key, key_len, val);
13351336
if(key_free) efree(key);
13361337

1337-
// Format our INCRBYFLOAT command
1338-
cmd_len = redis_cmd_format_static(&cmd, "INCRBYFLOAT", "sf", key, key_len, val);
1339-
13401338
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
13411339
IF_ATOMIC() {
13421340
redis_bulk_double_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);

tests/TestRedis.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -462,31 +462,41 @@ public function testIncr()
462462

463463
public function testIncrByFloat()
464464
{
465-
// incrbyfloat is new in 2.6.0
466-
if (version_compare($this->version, "2.5.0", "lt")) {
467-
$this->markTestSkipped();
468-
}
465+
// incrbyfloat is new in 2.6.0
466+
if (version_compare($this->version, "2.5.0", "lt")) {
467+
$this->markTestSkipped();
468+
}
469469

470-
$this->redis->delete('key');
470+
$this->redis->delete('key');
471+
472+
$this->redis->set('key', 0);
471473

472-
$this->redis->set('key', 0);
474+
$this->redis->incrbyfloat('key', 1.5);
475+
$this->assertEquals('1.5', $this->redis->get('key'));
473476

474-
$this->redis->incrbyfloat('key', 1.5);
475-
$this->assertEquals('1.5', $this->redis->get('key'));
477+
$this->redis->incrbyfloat('key', 2.25);
478+
$this->assertEquals('3.75', $this->redis->get('key'));
476479

477-
$this->redis->incrbyfloat('key', 2.25);
478-
$this->assertEquals('3.75', $this->redis->get('key'));
480+
$this->redis->incrbyfloat('key', -2.25);
481+
$this->assertEquals('1.5', $this->redis->get('key'));
479482

480-
$this->redis->incrbyfloat('key', -2.25);
481-
$this->assertEquals('1.5', $this->redis->get('key'));
483+
$this->redis->set('key', 'abc');
482484

483-
$this->redis->set('key', 'abc');
485+
$this->redis->incrbyfloat('key', 1.5);
486+
$this->assertTrue("abc" === $this->redis->get('key'));
484487

485-
$this->redis->incrbyfloat('key', 1.5);
486-
$this->assertTrue("abc" === $this->redis->get('key'));
488+
$this->redis->incrbyfloat('key', -1.5);
489+
$this->assertTrue("abc" === $this->redis->get('key'));
490+
491+
// Test with prefixing
492+
$this->redis->setOption(Redis::OPT_PREFIX, 'someprefix:');
493+
$this->redis->del('key');
494+
$this->redis->incrbyfloat('key',1.8);
495+
$this->assertEquals('1.8', $this->redis->get('key'));
496+
$this->redis->setOption(Redis::OPT_PREFIX, '');
497+
$this->assertTrue($this->redis->exists('someprefix:key'));
498+
$this->redis->del('someprefix:key');
487499

488-
$this->redis->incrbyfloat('key', -1.5);
489-
$this->assertTrue("abc" === $this->redis->get('key'));
490500
}
491501

492502
public function testDecr()

0 commit comments

Comments
 (0)