admin
2022-05-12 fa705507ba574c857b1667553737d23b1b7ff495
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
    }
 
}