jedis instance 表现很奇怪


The error is:
[B cannot be cast to java.lang.Long
at redis.clients.jedis.Connection.getIntegerReply(
at redis.clients.jedis.Jedis.hset(
As I read the issue '' So I know the pool.getResource() may be the correct way to use in production. 
But there is still something I do not know about the  jedis instance because I cannot figure out what the mean with the "multithreded environment".
Let me show My test code:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ImportMain {
private static Logger logger = LoggerFactory.getLogger(ImportMain.class);

public static void main(String args) {
Importer importer = new Importer();
try {
File file = new File(args[0]);
if (file.isDirectory()) {
File files = file.listFiles();
for (File f : files) {
if(f.isHidden()) {
} else if (file.isFile() && !file.isHidden()) {
} else {
} catch (IOException e) {
logger.error(e.getMessage() ,e);
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;


public class Importer {
private static Logger logger = LoggerFactory.getLogger(Importer.class);
private Jedis jedis;

public Importer() {
jedis = new Jedis("localhost");"------{}---------", jedis.toString());

public void process(File file) throws IOException {"start to process file:{}", file.getAbsoluteFile());
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
String line = null;
long total = 0L;
while ((line = br.readLine()) != null) {
jedis.hset("test::test", line, "1");
jedis.sync();"total record:{}", total);

Now,we can run: , the only argument I gived is "/tmp/A"
the directory structure:
Then it will run error!
It is unbelievable, right? I have never use any multi-threaded way to use the jedis instance, but It still works wrong, I just want to know why.
When I attempt to use the JedisPool, I also encoutered some problems:
The default maxIdle is 8, So if I have 9 files under the dircetory, It will still run wrong the same as before, I return the resource by call 'pool.returnResource(jedis);'
But if I return the resource by call 'pool.returnBrokenResource(jedis);' it work fine. It seems that the later is to create a new jedis instance not the one of eight.
Can I ask that the later is the correct usage in this circumstance? 
As I understand is : If the connection is not alive in the 15minutes(default), the redis-server will close the connection, and then this connection could be called broken?

zp0824 - 好好学习,天天向上


根据编译器提示的错误,这个问题是因为 B 无法被转换为 Long 类型而导致的,是一个类型错误,可能是你的代码写错了:[B cannot be cast to java.lang.Long at redis.clients.jedis.Connection.getIntegerReply( at redis.clients.jedis.Jedis.hset( 你现在写的这个测试代码比较复杂,debug 起来难。 如果你是刚开始学习 Redis 的话,建议从最简单的代码开始尝试,不要一开始就上太复杂的代码,特别是这些涉及 IO 和字符 parse 的。。。最容易写错了。 Jedis 的测试套件里面,提供了很多不错的使用实例,你可以去参考一下: ... .java