fix LC_COLLATE issue #176 #799

Open
wants to merge 1 commit into
from

3 participants

@charsyam

sortCompare has a bug in sort.c

if server.sort_alpha is true, sort_alpha has nothing to do with sort_bypattern.

so it has to compare with strcoll instead of compareStringObject.

and add locale config parameter to set locale easily.

@charsyam charsyam referenced this pull request Nov 29, 2012
Open

LC_COLLATE for SORT? #176

@baina

The Redis server itself stores all data as a binary objects, so it is not dependent on the encoding. The server will just store what is sent by the client (including UTF-8 chars).

Here are a few experiments:

$ echo téléphone | hexdump -C
00000000 74 c3 a9 6c c3 a9 70 68 6f 6e 65 0a |t..l..phone.|
c3a9 is the representation of the 'é' char.

$ redis-cli

set t téléphone
OK
get t
"t\xc3\xa9l\xc3\xa9phone"
Actually the data is correctly stored in the Redis server. However, when it is launched in a terminal, the Redis client interprets the output and applies the sdscatrepr function to transform non printable chars (whose definition is locale dependent, and may be broken for multibyte chars anyway).

A simple workaround is to launch redis-cli with the 'raw' option:

$ redis-cli --raw

get t
téléphone
Your own application will probably use one of the client libraries rather than redis-cli, so it should not be a problem in practice.

@charsyam

@bania. I don't think so. of course, redis server itself stores all data as a binary. but this problem is not about just storing.. for example. in Polish
redis> LPUSH test adam
(integer) 1
redis> LPUSH test łukasz
(integer) 2
redis> LPUSH test zuzanna
(integer) 3

redis> SORT test ALPHA
1) "adam"
2) "zuzanna"
3) "\xc5\x82ukasz"

łukasz has to be ahead of zuzanna.
but SORT result is wrong. we expect below result.

redis> SORT test ALPHA
1) "adam"
2) "\xc5\x82ukasz"
3) "zuzanna"

and my patch is about this problem :) Thank you.

@baina

@charsyam You're right! Does your patch support redis hash sort(sorting by hash values)?
Thank you.

@charsyam

@baina I don't know. I just found miss cases of sortCompare in sortCommand.

@charsyam

@antirez I think this issue is obviously bug in special environment to use special letters.

@charsyam charsyam referenced this pull request Nov 21, 2013
Closed

Sorting in redis 2.8 #1388

@JackieXie168 JackieXie168 pushed a commit that referenced this pull request Sep 16, 2014
@wmrowan wmrowan fixes issue #799 9358e83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment