簡體   English   中英

如何在C#中使用StackExchange.Redis從Redis緩存中獲取Unicode字符串?

[英]How to get Unicode string from redis cache using StackExchange.Redis in c#?

我正在使用StackExchange.Redis庫來使用Redis。 我已將Unicode字符串值設置如下。

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

我正在嘗試使用Unicode字符串

db.StringGet(key);

但是得到????? 而不是Unicode字符串。 Redis以以下格式存儲Unicode字符串值。

\xe0\xa4\xa7\xe0\xa4\xa8\xe0\xa5\x8d\xe0\xa4\xaf\xe0\xa4\xb5\xe0\xa4\xbe\xe0\xa4\xa6

RedisValue具有字符串類型的隱式RedisValue運算符。 在發送之前,它將其編碼為UTF-8字節數組。 如果您使用Unicode字符串,則應該自己獲取字節。

byte[] data = Encoding.Unicode.GetBytes(value);
db.StringSet(key, data);
...
data = db.StringGet(key);
value = Encoding.Unicode.GetString(data);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM