1. 增加 Redis 依赖包
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.3.0</version>
</dependency>
2.RedisUtil 实现代码
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* description * created by A on 2021/3/26 */public class RedisUtil1 {
public static JedisPool jedisPool=null;
public static Jedis getJedis(){if(jedisPool==null){JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(100); // 最大可用连接数
jedisPoolConfig.setBlockWhenExhausted(true); // 连贯耗尽后是否期待
jedisPoolConfig.setMaxWaitMillis(2000); // 等待时间
jedisPoolConfig.setMaxIdle(5); // 最大闲置连接数
jedisPoolConfig.setMinIdle(5); // 最小闲置连接数
jedisPoolConfig.setTestOnBorrow(true); // 连贯的时候测试一下 ping pong
jedisPool=new JedisPool(jedisPoolConfig,"hadoop102",6379,1000) ;
System.out.println("开拓连接池");
return jedisPool.getResource();}else{return jedisPool.getResource();
}
}
}