Question

I am working with Redis.

I got 2 Projects, one inserts data and the other is selects.

I put some key/field/value via org.springframework.data.redis.RedisTemplate. The project encoding is UTF-8. key and field is String type and value is Object.

What I want to do is select data from remote database(Insert Project) and insert its own redis. When getting data, uses Jedis and in case of putting uses Template.

The problem.

  • I had serialize String and Key when I insert to Insert Project.
  • However, when I select in the other, it breaks.
  • using console(redis-cli) makes right answer.

Here is my source code. Is there anything should be considered? Thanks :

@Repository
public class RedisDuplicator implements RedisDecalcomanie {

    @Inject
    RedisManagerImpl serviceRedis;

    @Override
    public void duplicateHash(String key) throws Exception {
        RedisHepler helper = RedisHepler.getInstance();
        Jedis managerRedis = helper.getConnection();

        Map<byte[], byte[]> hashAll = managerRedis.hgetAll(key.getBytes());

        Iterator<byte[]> iter = hashAll.keySet().iterator();
        while(iter.hasNext()){
            byte[] field = iter.next();
            byte[] value = hashAll.get(field);

            System.out.println("REDIS DUPLICATOR - ORIGIN : " + field);
            System.out.println("REDIS DUPLICATOR : " + new String(field, "ISO-8859-1"));
//          System.out.println("\t[ val ] : " + new String(value));

            System.out.println("utf-8 -> euc-kr        : " + new String(field, "euc-kr"));
            System.out.println("utf-8 -> ksc5601       : " + new String(field, "ksc5601"));
            System.out.println("utf-8 -> x-windows-949 : " + new String(field, "x-windows-949"));
            System.out.println("utf-8 -> iso-8859-1    : " + new String(field, "iso-8859-1"));
            System.out.println("iso-8859-1 -> euc-kr        : " + new String(field, "euc-kr"));
            System.out.println("iso-8859-1 -> ksc5601       : " + new String(field, "ksc5601"));
            System.out.println("iso-8859-1 -> x-windows-949 : " + new String(field, "x-windows-949"));
            System.out.println("iso-8859-1 -> utf-8         : " + new String(field, "utf-8"));
            System.out.println("euc-kr -> utf-8         : " + new String(field, "utf-8"));
            System.out.println("euc-kr -> ksc5601       : " + new String(field, "ksc5601"));
            System.out.println("euc-kr -> x-windows-949 : " + new String(field, "x-windows-949"));
            System.out.println("euc-kr -> iso-8859-1    : " + new String(field, "iso-8859-1"));
            System.out.println("ksc5601 -> euc-kr        : " + new String(field, "euc-kr"));
            System.out.println("ksc5601 -> utf-8         : " + new String(field, "utf-8"));
            System.out.println("ksc5601 -> x-windows-949 : " + new String(field, "x-windows-949"));
            System.out.println("ksc5601 -> iso-8859-1    : " + new String(field, "iso-8859-1"));
            System.out.println("x-windows-949 -> euc-kr     : " + new String(field, "euc-kr"));
            System.out.println("x-windows-949 -> utf-8      : " + new String(field, "utf-8"));
            System.out.println("x-windows-949 -> ksc5601    : " + new String(field, "ksc5601"));
            System.out.println("x-windows-949 -> iso-8859-1 : " + new String(field, "iso-8859-1"));
        }

        helper.returnResource(managerRedis);
        helper.destroyPool();
    }

    @Override
    public void duplicateList(String key) throws Exception {
        // TODO Auto-generated method stub

    }
}; 

output :

REDIS DUPLICATOR - ORIGIN : [B@3d3c33b7
REDIS DUPLICATOR : ’t160
utf-8 -> euc-kr        : ыt160
utf-8 -> ksc5601       : ыt160
utf-8 -> x-windows-949 : ыt160
utf-8 -> iso-8859-1    : ’t160
iso-8859-1 -> euc-kr        : ыt160
iso-8859-1 -> ksc5601       : ыt160
iso-8859-1 -> x-windows-949 : ыt160
iso-8859-1 -> utf-8         : ��t160
euc-kr -> utf-8         : ��t160
euc-kr -> ksc5601       : ыt160
euc-kr -> x-windows-949 : ыt160
euc-kr -> iso-8859-1    : ’t160
ksc5601 -> euc-kr        : ыt160
ksc5601 -> utf-8         : ��t160
ksc5601 -> x-windows-949 : ыt160
ksc5601 -> iso-8859-1    : ’t160
x-windows-949 -> euc-kr     : ыt160
x-windows-949 -> utf-8      : ��t160
x-windows-949 -> ksc5601    : ыt160
x-windows-949 -> iso-8859-1 : ’t160
REDIS DUPLICATOR - ORIGIN : [B@4b0e18ba
REDIS DUPLICATOR : ’t130
utf-8 -> euc-kr        : ыt130
utf-8 -> ksc5601       : ыt130
utf-8 -> x-windows-949 : ыt130
utf-8 -> iso-8859-1    : ’t130
iso-8859-1 -> euc-kr        : ыt130
iso-8859-1 -> ksc5601       : ыt130
iso-8859-1 -> x-windows-949 : ыt130
iso-8859-1 -> utf-8         : ��t130
euc-kr -> utf-8         : ��t130
euc-kr -> ksc5601       : ыt130
euc-kr -> x-windows-949 : ыt130
euc-kr -> iso-8859-1    : ’t130
ksc5601 -> euc-kr        : ыt130
ksc5601 -> utf-8         : ��t130
ksc5601 -> x-windows-949 : ыt130
ksc5601 -> iso-8859-1    : ’t130
x-windows-949 -> euc-kr     : ыt130
x-windows-949 -> utf-8      : ��t130
x-windows-949 -> ksc5601    : ыt130
x-windows-949 -> iso-8859-1 : ’t130

I expected some of these should be '130'.

Was it helpful?

Solution

It comes out my console encoding problem. Since my Eclipse workspace setting was default, it could not print UTF-8 text:D (But it is still mystery why it could not print iso-8859-1 encoding...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top