Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichael-grunder <michael.grunder@gmail.com>2013-11-19 19:40:30 +0400
committermichael-grunder <michael.grunder@gmail.com>2013-11-19 19:40:30 +0400
commite482f970acbd7210d28ed45b86672087dc7c94fe (patch)
tree238669a6dfeef672c79ba4a80de25ea7b54af419
parent49dce3b3729cb1f9e1ccf942c39d2dabaaf3d76d (diff)
parent2108446ecbf33375878f8a77a04f41d339443d69 (diff)
Merge branch 'hotfix/incrby_float_prefix'incrby_float_prefix
Fixes #408
-rw-r--r--redis.c6
-rw-r--r--tests/TestRedis.php44
2 files changed, 29 insertions, 21 deletions
diff --git a/redis.c b/redis.c
index c2a3d87c..3ed22b63 100644
--- a/redis.c
+++ b/redis.c
@@ -1330,13 +1330,11 @@ PHP_METHOD(Redis, incrByFloat) {
RETURN_FALSE;
}
- // Prefix our key, free it if we have
+ // Prefix key, format command, free old key if necissary
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
+ cmd_len = redis_cmd_format_static(&cmd, "INCRBYFLOAT", "sf", key, key_len, val);
if(key_free) efree(key);
- // Format our INCRBYFLOAT command
- cmd_len = redis_cmd_format_static(&cmd, "INCRBYFLOAT", "sf", key, key_len, val);
-
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
IF_ATOMIC() {
redis_bulk_double_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
diff --git a/tests/TestRedis.php b/tests/TestRedis.php
index 60f015f5..e4e41c44 100644
--- a/tests/TestRedis.php
+++ b/tests/TestRedis.php
@@ -462,31 +462,41 @@ class Redis_Test extends TestSuite
public function testIncrByFloat()
{
- // incrbyfloat is new in 2.6.0
- if (version_compare($this->version, "2.5.0", "lt")) {
- $this->markTestSkipped();
- }
+ // incrbyfloat is new in 2.6.0
+ if (version_compare($this->version, "2.5.0", "lt")) {
+ $this->markTestSkipped();
+ }
- $this->redis->delete('key');
+ $this->redis->delete('key');
+
+ $this->redis->set('key', 0);
- $this->redis->set('key', 0);
+ $this->redis->incrbyfloat('key', 1.5);
+ $this->assertEquals('1.5', $this->redis->get('key'));
- $this->redis->incrbyfloat('key', 1.5);
- $this->assertEquals('1.5', $this->redis->get('key'));
+ $this->redis->incrbyfloat('key', 2.25);
+ $this->assertEquals('3.75', $this->redis->get('key'));
- $this->redis->incrbyfloat('key', 2.25);
- $this->assertEquals('3.75', $this->redis->get('key'));
+ $this->redis->incrbyfloat('key', -2.25);
+ $this->assertEquals('1.5', $this->redis->get('key'));
- $this->redis->incrbyfloat('key', -2.25);
- $this->assertEquals('1.5', $this->redis->get('key'));
+ $this->redis->set('key', 'abc');
- $this->redis->set('key', 'abc');
+ $this->redis->incrbyfloat('key', 1.5);
+ $this->assertTrue("abc" === $this->redis->get('key'));
- $this->redis->incrbyfloat('key', 1.5);
- $this->assertTrue("abc" === $this->redis->get('key'));
+ $this->redis->incrbyfloat('key', -1.5);
+ $this->assertTrue("abc" === $this->redis->get('key'));
+
+ // Test with prefixing
+ $this->redis->setOption(Redis::OPT_PREFIX, 'someprefix:');
+ $this->redis->del('key');
+ $this->redis->incrbyfloat('key',1.8);
+ $this->assertEquals('1.8', $this->redis->get('key'));
+ $this->redis->setOption(Redis::OPT_PREFIX, '');
+ $this->assertTrue($this->redis->exists('someprefix:key'));
+ $this->redis->del('someprefix:key');
- $this->redis->incrbyfloat('key', -1.5);
- $this->assertTrue("abc" === $this->redis->get('key'));
}
public function testDecr()