java110
2021-03-22 3a63bde28d2802c818adef25e47b8c98f3ab4b6c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.java110.utils.cache;
 
import com.java110.dto.businessDatabus.BusinessDatabusDto;
import com.java110.utils.util.SerializeUtil;
import redis.clients.jedis.Jedis;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 映射缓存工具类
 * Created by wuxw on 2018/4/14.
 */
public class DatabusCache extends BaseCache {
 
    //后缀 用来刷缓存时删除 所有以这个为后缀的数据
    public final static String DEFAULT_DATABUS = "JAVA110_DATABUS";
 
 
    /**
     * 获取  databus
     *
     * @return
     */
    public static List<BusinessDatabusDto> getDatabuss() {
        Jedis redis = null;
        try {
            redis = getJedis();
            return SerializeUtil.unserializeList(redis.get((DEFAULT_DATABUS).getBytes()), BusinessDatabusDto.class);
        } finally {
            if (redis != null) {
                redis.close();
            }
        }
    }
 
    /**
     * 获取  databus
     *
     * @return
     */
    public static List<BusinessDatabusDto> getDatabuss(String businessType) {
        List<BusinessDatabusDto> businessDatabusDtos = getDatabuss();
 
        List<BusinessDatabusDto> tmpBusinessDatabusDtos = new ArrayList<>();
 
        for (BusinessDatabusDto businessDatabusDto : businessDatabusDtos) {
            if (businessType.equals(businessDatabusDto.getBusinessTypeCd())) {
                tmpBusinessDatabusDtos.add(businessDatabusDto);
            }
        }
        return tmpBusinessDatabusDtos;
    }
 
    /**
     * 保存list 数据
     *
     * @param businessDatabusDtos
     */
    public static void setValue(List<BusinessDatabusDto> businessDatabusDtos) {
        Jedis redis = null;
        try {
            redis = getJedis();
            redis.set((DEFAULT_DATABUS).getBytes(), SerializeUtil.serializeList(businessDatabusDtos));
        } finally {
            if (redis != null) {
                redis.close();
            }
        }
    }
 
 
}