如何用java实现基于JedisCluster对象的连接池

2025年03月22日 12:15
有1个网友回答
网友(1):

public static void writeRedis(String inpath, int[] keyIndex) throws Exception {
InputStream in = new URL(inpath).openStream();// 输入流 ]
LineIterator br = org.apache.commons.io.IOUtils.lineIterator(in, "utf8");// 指定输入流与字符编码
JedisCluster cluster = RedisUtils.getClusterConn();
String[] line = null;
while (br.hasNext()) {
String s = br.next();
line = RedisUtils.split(s);
String key = "";
for (int i = 0; i < keyIndex.length; i++) {
key += line[keyIndex[i]];// TODO:如果有必要,添加分隔符
}
cluster.setnx(key, s);
}
RedisUtils.clusterClose(cluster);