工具类 - 连接redis:JedisUtils
package com.itheima.util;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import java.util.ResourceBundle;
public class JedisUtils {
private static int maxTotal; // 最大连接数
private static int maxIdel; // 最大活跃数
private static String host; // redis服务地址
private static int port; // redis服务端口号
// poolConfig:连接池配置对象
private static JedisPoolConfig jpc;
// JedisPool:Jedis提供的连接池技术
private static JedisPool jp;
static {
// 读取src下的.properties文件,参数不写扩展名
ResourceBundle bundle = ResourceBundle.getBundle("redis");
maxTotal = Integer.parseInt(bundle.getString("redis.maxTotal"));
maxIdel = Integer.parseInt(bundle.getString("redis.maxIdel"));
host = bundle.getString("redis.host");
port = Integer.parseInt(bundle.getString("redis.port"));
//Jedis连接池配置
jpc = new JedisPoolConfig();
jpc.setMaxTotal(maxTotal);
jpc.setMaxIdle(maxIdel);
jp = new JedisPool(jpc,host,port);
}
public static Jedis getJedis(){
return jp.getResource();
}
}