得到x=XXX格式的X和XXX值(1)
redis中某一个Key所储存的数据如下:
1. 获取连接池配置对象
> JedisPoolConfig config = new JedisPoolConfig();
2.设置最大连接数
> config.setMaxTotal(30);
3.设置最大的空闲连接数
config.setMaxIdle(10);
4.获得连接池:
> JedisPool jedisPool = new JedisPool(poolConfig,host,port);
5.获得核心对象:jedis
Jedis jedis = null;
6.通过连接池来获得连接
jedis = jedisPool.getResource();
jedis.auth();
7.操作完成之后释放资源和连接池
// 释放资源
if (jedis != null) {
jedis.close();
}
// 释放连接池
if (jedisPool != null) {
jedisPool.close();
}
// 获取连接池配置对象
JedisPoolConfig config = new JedisPoolConfig();
// 设置最大连接数
config.setMaxTotal(30);
// 设置最大的空闲连接数
config.setMaxIdle(10);
// 获得连接池:
JedisPool jedisPool = new JedisPool(poolConfig,host,port);
// 获得核心对象:jedis
Jedis jedis = null;
try {
// 通过连接池来获得连接
jedis = jedisPool.getResource();
jedis.auth("11111");
/** 进行操作代码 */
} catch (Exception e) {
e.printStackTrace();
} finally {
// 释放资源
if (jedis != null) {
jedis.close();
}
// 释放连接池
if (jedisPool != null) {
jedisPool.close();
}
}