1

I'd like to save Arabic characters like سلام in a redis hash, like this:

HMSET arabicHash "سلام" 5
OK

But the result is not as intended:

127.0.0.1:6379> HGETALL arabicHash
1) "\xd8\xb3\xd9\x84\xd8\xa7\xd9\x85"
2) "5"

I'm wondering if there is a way to save سلام directly inot redis set? And if not, how can I convert back "\xd8\xb3\xd9\x84\xd8\xa7\xd9\x85" to human-readable charachters after being retrived?

Update: I've tested on my Ubuntu Bash terminal, but the result is not formatted correctly here. The screenshot:

enter image description here

2 Answers 2

2
  1. You need to put quotes to enclose the key and value being stored in the hash.

enter image description here

Tested on try.redis.io ( it shows the redis output in utf-8 decode form )

  1. The text may showup as utf-8 encoded in redis response, but on decoding, it would show correctly in arabic characters
Sign up to request clarification or add additional context in comments.

2 Comments

Well, I'm tesing on Bash terminal. And I enclosed the arabic word in double quotes (like "سلام" . Please see the photo in my updated question.
Yes, your storage in redis is correct. See the decoded version : mothereff.in/utf-8#%D8%B3%D9%84%D8%A7%D9%85
0

Note that redis-cli by default displays byte-encoded characters (which are not human-readable), but there is a --raw switch for displaying them in a format decoded to strings, i.e. in human-readable form (as Redis developer himself answered here):

$ redis-cli --raw -a $REDIS_PASSWORD

127.0.0.1:6379> HMSET test.hash 123 gęś 
OK

127.0.0.1:6379> HGETALL test.hash
123
gęś

... versus the default:

$ redis-cli -a $REDIS_PASSWORD

127.0.0.1:6379> HMSET test.hash 321 gęś 
OK

127.0.0.1:6379> hgetall test.hash
1) "123"
2) "g\xc4\x99\xc5\x9b"
3) "321"
4) "g\xc4\x99\xc5\x9b"

Notice also that the data format of non-ASCII characters actually stored in the databases is unaffected by this switch.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.