Expected behaviour
Given this code:
<?php
setlocale(LC_ALL, 'de_DE');
$redis = new \Redis();
$redis->connect('127.0.0.1');
$redis->zadd('tmp_set', -1607954792.2, 'foo');
var_dump($redis->getLastError());
I expect this code to return NULL as the last error.
Actual behaviour
I get ERR value is not a valid float as the last error.
I'm seeing this behaviour on
- OS: all
- Redis: all versions
- PHP: all versions
- phpredis: 5.3.2
I've checked
Details
As far as I can tell, this is because redis_zadd_cmd uses redis_cmd_append_sstr_dbl which in turn uses snprintf to convert the float to string:
|
int |
|
redis_cmd_append_sstr_dbl(smart_string *str, double value) |
|
{ |
|
char tmp[64]; |
|
int len; |
|
|
|
/* Convert to string */ |
|
len = snprintf(tmp, sizeof(tmp), "%.17g", value); |
|
|
|
// Append the string |
|
return redis_cmd_append_sstr(str, tmp, len); |
|
} |
snprintf depends on the application locale when selecting the decimal separator which for the German language is , instead of .. Changing the system/application locale to English fixes it.
This seems issue seems to have been reported and addressed before in #33 / 1d6133d but it seems that subsequent changes broke this again.
Expected behaviour
Given this code:
I expect this code to return
NULLas the last error.Actual behaviour
I get
ERR value is not a valid floatas the last error.I'm seeing this behaviour on
I've checked
developbranchDetails
As far as I can tell, this is because
redis_zadd_cmdusesredis_cmd_append_sstr_dblwhich in turn usessnprintfto convert the float to string:phpredis/library.c
Lines 947 to 958 in ee82299
snprintfdepends on the application locale when selecting the decimal separator which for the German language is,instead of.. Changing the system/application locale to English fixes it.This seems issue seems to have been reported and addressed before in #33 / 1d6133d but it seems that subsequent changes broke this again.