- Jedis: 一款java操作redis数据库的工具.
- 使用步骤:
- 导入jedis的jar包
- 使用
//1. 获取连接
Jedis jedis = new Jedis("localhost",6379);
//2. 操作
jedis.set("username","zhangsan");
//3. 关闭连接
jedis.close();
- jedis连接池: JedisPool
- 使用步骤:
- 创建JedisPool连接池对象
- 调用方法 getResource()方法获取Jedis连接
//创建一个配置对象
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(50);
config.setMaxIdle(10);
//创建Jedis连接池对象
JedisPool jedisPool = new JedisPool(config,"localhost",6379);
//获取连接
Jedis jedis = jedisPool.getResource();
//使用
jedis.set("hehe","heihei");
//关闭 归还到连接池中
jedis.close();