How to save and get accent line in redis?

I am unable to set and get the accent line in my redis db.
Accented fonts are coded, how can I get them back when they are installed?

redis> set test téléphone OK redis> get test "t\xc3\xa9l\xc3\xa9phone" 

I know this has already been set (http://stackoverflow.com/questions/6731450/redis-problem-with-accents-utf-8-encoding), but there is no detailed answer.

+4
source share
1 answer

The Redis server saves all data as binary objects, so it is independent of the encoding. The server will simply save what is sent by the client (including UTF-8 characters).

Here are some 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 a 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 on the Redis server. However, when it runs in the terminal, the Redis client interprets the output and uses the sdscatrepr function to convert non-printable characters (the definition of which is language-dependent and can be split into multi-byte characters anyway).

A simple workaround is to run 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, not redis-cli, so in practice this should not be a problem.

+19
source

Source: https://habr.com/ru/post/1392350/


All Articles