diff options
-rw-r--r-- | library.c | 6 | ||||
-rw-r--r-- | library.h | 16 | ||||
-rwxr-xr-x | redis.c | 3 | ||||
-rw-r--r-- | tests/TestRedis.php | 16 |
4 files changed, 32 insertions, 9 deletions
@@ -308,8 +308,7 @@ redis_cmd_format_static(char **ret, char *keyword, char *format, ...) { case 'f': case 'F': { double d = va_arg(ap, double); - dbl_str = _php_math_number_format(d, 8, '.', '\x00'); - dbl_len = strlen(dbl_str); + REDIS_DOUBLE_TO_STRING(dbl_str, dbl_len, d) smart_str_append_long(&buf, dbl_len); smart_str_appendl(&buf, _NL, sizeof(_NL) - 1); smart_str_appendl(&buf, dbl_str, dbl_len); @@ -377,8 +376,7 @@ redis_cmd_format(char **ret, char *format, ...) { case 'F': case 'f': { double d = va_arg(ap, double); - dbl_str = _php_math_number_format(d, 8, '.', '\x00'); - dbl_len = strlen(dbl_str); + REDIS_DOUBLE_TO_STRING(dbl_str, dbl_len, d) smart_str_append_long(&buf, dbl_len); smart_str_appendl(&buf, _NL, sizeof(_NL) - 1); smart_str_appendl(&buf, dbl_str, dbl_len); @@ -47,12 +47,22 @@ redis_key_prefix(RedisSock *redis_sock, char **key, int *key_len TSRMLS_DC); PHPAPI int redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **return_value TSRMLS_DC); -/* - * Variant Read methods, mostly to implement eval - */ PHPAPI int redis_read_reply_type(RedisSock *redis_sock, REDIS_REPLY_TYPE *reply_type, int *reply_info TSRMLS_DC); PHPAPI int redis_read_variant_line(RedisSock *redis_sock, REDIS_REPLY_TYPE reply_type, zval **z_ret TSRMLS_DC); PHPAPI int redis_read_variant_bulk(RedisSock *redis_sock, int size, zval **z_ret TSRMLS_DC); PHPAPI int redis_read_multibulk_recursive(RedisSock *redis_sock, int elements, zval **z_ret TSRMLS_DC); PHPAPI int redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab); + + +#if ZEND_MODULE_API_NO >= 20100000 +#define REDIS_DOUBLE_TO_STRING(dbl_str, dbl_len, dbl) \ + char dbl_decsep; \ + dbl_decsep = '.'; \ + dbl_str = _php_math_number_format_ex(dbl, 8, &dbl_decsep, 1, NULL, 0); \ + dbl_len = strlen(dbl_str); +#else +#define REDIS_DOUBLE_TO_STRING(dbl_str, dbl_len, dbl) \ + dbl_str = _php_math_number_format(dbl, 8, '.', '\x00'); \ + dbl_len = strlen(dbl_str); +#endif
\ No newline at end of file @@ -3684,8 +3684,7 @@ PHP_METHOD(Redis, zAdd) { /* add score */ score = Z_DVAL_P(z_args[i]); - dbl_str = _php_math_number_format(score, 8, '.', '\x00'); - dbl_len = strlen(dbl_str); + REDIS_DOUBLE_TO_STRING(dbl_str, dbl_len, score) smart_str_appendc(&buf, '$'); smart_str_append_long(&buf, dbl_len); smart_str_appendl(&buf, _NL, sizeof(_NL) - 1); diff --git a/tests/TestRedis.php b/tests/TestRedis.php index 188d8224..99c9a5c6 100644 --- a/tests/TestRedis.php +++ b/tests/TestRedis.php @@ -1814,6 +1814,22 @@ class Redis_Test extends TestSuite $this->redis->delete('key2'); $this->redis->delete('key3'); + $this->redis->zadd('key1', 2000.1, 'one'); + $this->redis->zadd('key1', 3000.1, 'two'); + $this->redis->zadd('key1', 4000.1, 'three'); + + $ret = $this->redis->zRange('key1', 0, -1, TRUE); + $this->assertTrue(count($ret) === 3); + $retValues = array_keys($ret); + + $this->assertTrue(array('one', 'two', 'three') === $retValues); + + // + 0 converts from string to float OR integer + $this->assertTrue(is_float($ret['one'] + 0)); + $this->assertTrue(is_float($ret['two'] + 0)); + $this->assertTrue(is_float($ret['three'] + 0)); + + $this->redis->delete('key1'); // ZREMRANGEBYRANK $this->redis->zAdd('key1', 1, 'one'); |