Sitelet https://github.com/phpredis/phpredis/issues/1893
Skip to content

Non-English Locale breaks ZADD #1893

Description

@msiemens

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

  • There is no similar issue from other users
  • Issue isn't fixed in develop branch

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:

phpredis/library.c

Lines 947 to 958 in ee82299

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions