我正在与Redis合作。
我有2个项目,一个插入数据,另一个是选择。
我通过org.springframework.data.redis.RedisTemplate
放了一些键/字段/值。项目编码是UTF-8。
密钥和字段为String
类型,值为Object
。
我想要做的是从远程数据库(插入项目)中选择数据并插入自己的redis。获取数据时,使用Jedis并使用模板。
问题。
这是我的源代码。有什么需要考虑的吗?谢谢:
@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
}
};
输出:
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
我预计其中一些应该是'130'。
答案 0 :(得分:0)
它出现了我的控制台编码问题。由于我的Eclipse工作区设置是默认设置,因此无法打印UTF-8文本:D(但为什么它无法打印iso-8859-1编码仍然很神秘......)