java110
2021-04-08 c9b36c8d499409d5b596e4f9cf4fc47fd8a42fd8
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
43
package com.java110.utils.cache;
 
 
import com.java110.utils.factory.ApplicationContextFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
 
import java.util.Set;
 
/**
 * 缓存基类
 * Created by wuxw on 2018/4/14.
 */
public class BaseCache {
 
    protected static Jedis getJedis(){
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        return jedisPool.getResource();
    }
 
    /**
     * 删除数据
     * @param pattern
     */
    public static void removeData(String pattern){
        Jedis redis = null;
        try {
            redis = getJedis();
            Set<String> keys = redis.keys("*"+pattern);
            if(keys == null || keys.size() == 0){
                return ;
            }
            for(String key : keys){
                redis.del(key);
            }
        }finally {
            if(redis != null){
                redis.close();
            }
        }
    }
 
}