1

I used win-redis-server-2.6 to store some simple key-value pairs, redis-cli.exe to set in key-values, and then get the value out through Jedis.

First, redis-cli > set foo "中" the responde is ok

Then, Using Jedis

JedisPoolConfig poolConfig = new JedisPoolConfig();
jPool = new JedisPool(poolConfig, host, port);
Jedis jedis = jPool.getResource();
String test= jedis.get("foo");
System.out.println(test);

BUT, i got this �� I have searched the problem, but i got no help.

Redis - problem with accents (UTF-8 encoding) How to save and retrieve string with accents in redis?

these two ways can not solve my problem, because i must use the jedis to get out the value.

I have tried redis-cli --raw get foo this can get out the value, but when i remove the --raw option , the redis-cli.exe just crashed.

And for set values i have tried using hiredis-C-client to set value, but also i got the problem.

BUT when i set value through Jedis and get value also using Jedis ,It is OK.

Also i have tried to decode the value get out by jedis,using the following code String newStr = new String(test.getBytes("UTF-8"), "UTF-8"); I have tried "GBK", "GB2312", "ISO-8859-1" , but all failed.

Could anyone please help me? Thanks in advance.

Kong

Community
  • 1
  • 1
  • i guess that `set foo "中" ` is creating problems for you. Could you try adding data through the Jedis itself. – Santosh Joshi Feb 19 '14 at 09:06
  • Thanks ,i have tried set values by Jedis itself, it is ok. But we have to set values through 'redis-cli.exe' or 'hiredis C++ client', when i use hiredis-client to set values to redis,the problem also occurs. – user3327130 Feb 20 '14 at 00:38

1 Answers1

0

At last, We use another way to implement this function.

That is we encode any chinese values we want to set in redis by UTF8 . After this , i can get the right string out by Jedis.