赞
踩
本地设置了redis的密码,但在远程连接时并没有输入密码,所以无法请求成功!
public void testJedisSingle(){
Jedis jedis = new Jedis("127.0.0.1", 6379);
jedis.auth("你的密码");
jedis.set("aaa","123");
String aaa = jedis.get("aaa");
System.out.println(aaa);
jedis.close();
}
public void pool() { JedisPoolConfig config = new JedisPoolConfig(); //最大连接数 config.setMaxTotal(30); //最大连接空闲数 config.setMaxIdle(2); JedisPool pool = new JedisPool(config, "127.0.0.1", 6379); //有密码也可以用下面这个连接方法 //jedisPool = new JedisPool(Config,"127.0.0.1", 6379 ,3000, redisPassword); Jedis jedis = null; try { jedis = pool.getResource(); jedis.auth("你的密码"); jedis.set("name", "123"); String name = jedis.get("name"); System.out.println(name); }catch(Exception ex){ ex.printStackTrace(); }finally{ if(jedis != null){ //关闭连接 jedis.close(); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。