1

I am using StackExchange.Redis library to work with redis. I have set Unicode string value as below.

db.StringSet(key,"धन्यवाद");

And I am trying to get Unicode string using

db.StringGet(key);

But getting ????? instead of Unicode string. Redis stores Unicode string value in below format.

\xe0\xa4\xa7\xe0\xa4\xa8\xe0\xa5\x8d\xe0\xa4\xaf\xe0\xa4\xb5\xe0\xa4\xbe\xe0\xa4\xa6
dharmesh parmar
  • 127
  • 1
  • 4
  • 9
  • Possible duplicate of [Redis - problem with accents (UTF-8 encoding)](https://stackoverflow.com/questions/6731450/redis-problem-with-accents-utf-8-encoding) – NicoXiang Jul 20 '17 at 01:40
  • @Nico getting (error) ERR unknown command '--raw' on redis cli. Have you tried this?!!! – dharmesh parmar Jul 20 '17 at 21:25
  • I test your code, it works fine and i can get the right string and cmd like 'redis-cli --raw mget key' works fine on my pc, too. I think its a enviroment problem, what is your redis version? If it still does not work, just check the second answer, decode that string. – NicoXiang Jul 21 '17 at 01:02

1 Answers1

0

RedisValue has an implicit cast operator of type string. It encodes it as an UTF-8 byte array before sending it. If you have your string in Unicode you should obtain the bytes by yourself.

byte[] data = Encoding.Unicode.GetBytes(value);
db.StringSet(key, data);
...
data = db.StringGet(key);
value = Encoding.Unicode.GetString(data);
Ion Ciobanu
  • 506
  • 4
  • 13