下载
这里下载的是windows
直接解压,打开解压目录,进入powerShell 启动服务端:
打开另一个powerShell启动客户端:
ping pong成功;
废话不多说:
先封装一个JedisPool 能够调出JedisPool,我把它加入common包:
简而言之就是配置好JedisPool然后用JedisPool返回Jedis类
properties:
redis1.ip=127.0.0.1
redis1.port=6379
redis.max.total=20
redis.max.idle=10
redis.min.idle=2
redis.test.borrow=true
redis.test.return=false
看下面的配置,自己改下properties文件
package com.van.mall.common;
import com.van.mall.util.PropertiesUtil;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* @author Van
* @date 2020/3/21 - 13:51
*/
@PropertySource(value = {
"classpath:application.properties"})
public class RedisPool {
private static JedisPool pool;//connection pool
private static Integer maxTotal =Integer.parseInt(PropertiesUtil.getPropertity("redis.max.total")) ;//max connection
private static Integer maxIdle =Integer.parseInt(PropertiesUtil.getPropertity("redis.max.idle"));//max idle connection
private static Integer minIdle=Integer.parseInt(PropertiesUtil.getPropertity("redis.min.idle"));//min idle connection
private static Boolean testOnBorrow=Boolean.parseBoolean(PropertiesUtil.getPropertity("redis.test.borrow"));//whether test when borrow a jedis if true then it's available
private static Boolean testOnReturn=Boolean.parseBoolean(PropertiesUtil.getPropertity("redis.test.return"));//whether test when return a jedis if true then it's available
private static String redisIp=PropertiesUtil.getPropertity("redis.ip");
private static Integer redisPort=Integer.parseInt(PropertiesUtil.getPropertity("redis.port")) ;
private static void initPool(){
JedisPoolConfig config=new JedisPoolConfig();
config.setMaxIdle(maxIdle);
config.setMaxTotal(maxTotal);
config.setMinIdle(minIdle);
config.setTestOnBorrow(testOnBorrow);
config.setTestOnReturn(testOnReturn);
//whether block when resource is exhausted: false will throw a exception,true will block until timeout, default is true
config.setBlockWhenExhausted(true);
pool=new JedisPool(config,redisIp,redisPort,1000*2);
}
static {
initPool();
}
public static Jedis get