package com.ks.app.utils;
|
|
import org.springframework.stereotype.Component;
|
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.JedisPool;
|
|
import javax.annotation.Resource;
|
|
/**
|
* @author hxh
|
* @title: JedisUtil
|
* @description: Jedis工具类
|
* @date 2022/5/9 11:53
|
*/
|
@Component
|
public class JedisUtil {
|
|
|
@Resource
|
private JedisPool jedisPool;
|
|
/**
|
* 执行
|
*
|
* @param jedisExcuter
|
*/
|
public void excute(JedisExcuter jedisExcuter) throws Exception {
|
Jedis jedis = jedisPool.getResource();
|
try {
|
if (jedisExcuter != null) {
|
jedisExcuter.execute(jedis);
|
}
|
} finally {
|
jedis.close();
|
}
|
}
|
|
public interface JedisExcuter {
|
public void execute(Jedis jedis) throws Exception;
|
}
|
|
}
|