地质所 沉降监测网建设项目
chenhuan
2024-05-16 0fdd42e318f51f9e3c6581473416af1cca69877f
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package com.javaweb.redis.util;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.ShardedJedis;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
 
public class RedisUtil {
 
    public static final String SYS_CACHE = "sysCache";
    public static final String USER_CACHE = "userCache";
    public static final String DEFAULT_CACHE = "defaultCache";
 
    public static String getSysInfo(String key) {
        return RedisUtil.getStringValue(SYS_CACHE+"_"+key);
    }
    public static String getDefaultInfo(String key) {
        return RedisUtil.getStringValue(DEFAULT_CACHE+"_"+key);
    }
    public static String getUserInfo(String key,String yhid) {
        return RedisUtil.getStringValue(USER_CACHE+"_"+key+"_"+yhid);
    }
 
    public static void putSysInfo(String key, Object value) {
        RedisUtil.setStringValue(SYS_CACHE+"_"+key,JSON.toJSONString(value));
    }
    public static void putDefaultInfo(String key, Object value) {
 
        RedisUtil.setStringValue(DEFAULT_CACHE+"_"+key,JSON.toJSONString(value));
    }
    public static void putUserInfo(String key,String yhid, Object value) {
        RedisUtil.setStringValue(USER_CACHE+"_"+key+"_"+yhid,JSON.toJSONString(value));
    }
 
    public static void removeSysInfo(String key) {
        RedisUtil.del(SYS_CACHE+"_"+key);
    }
    public static void removeDefaultInfo(String key) {
        RedisUtil.del(DEFAULT_CACHE+"_"+key);
    }
    public static void removeUserInfo(String key,String yhid) {
        RedisUtil.del(USER_CACHE+"_"+key+"_"+yhid);
    }
    public static void clearUserInfo(String yhid){
        List<String> keys=RedisUtil.keys(USER_CACHE+"_*_"+yhid);
        keys.forEach(s->{
            RedisUtil.del(s);
        });
    }
    public static void clearUserCache(){
        List<String> keys=RedisUtil.keys(USER_CACHE+"_*");
        keys.forEach(s->{
            RedisUtil.del(s);
        });
    }
    public static void clearSysCache(){
        List<String> keys=RedisUtil.keys(SYS_CACHE+"_*");
        keys.forEach(s->{
            RedisUtil.del(s);
        });
    }
    public static void clearDefaultCache(){
        List<String> keys=RedisUtil.keys(DEFAULT_CACHE+"_*");
        keys.forEach(s->{
            RedisUtil.del(s);
        });
    }
    //--------------------------------------------------
 
    public static String setStringValue(String key, String value) {
        return InitRedisUtil.setStringValue(key,value);
    }
 
    public static String type(String key) {
        return InitRedisUtil.type(key);
    }
    public static long ttl(String key) {
        return InitRedisUtil.ttl(key);
    }
    /**
     * Set String
     *
     * @param key
     * @param value
     * @param seconds 存活时间,单位/秒
     * @return
     */
    public static String setStringValue(String key, String value, int seconds) {
        return InitRedisUtil.setStringValue(key,value,seconds);
    }
 
    /**
     * Set Object
     * @param key
     * @param obj
     * @param seconds 存活时间,单位/秒
     */
    public static String setObjectValue(String key, Object obj, int seconds) {
        return InitRedisUtil.setObjectValue(key,obj,seconds);
    }
 
    /**
     * Get String
     *
     * @param key
     * @return
     */
    public static String getStringValue(String key) {
        return InitRedisUtil.getStringValue(key);
    }
 
    /**
     * Get Object
     *
     * @param key
     * @return
     */
    public static Object getObjectValue(String key) {
        return InitRedisUtil.getObjectValue(key);
    }
    public static Object getObjectValue(String key,Class cls) {
        return InitRedisUtil.getObjectValue(key,cls);
    }
    /**
     * Delete key
     *
     * @param key
     * @return Integer reply, specifically:
     * an integer greater than 0 if one or more keys were removed
     * 0 if none of the specified key existed
     */
    public static Long del(String key) {
        return InitRedisUtil.del(key);
    }
 
    /**
     * incrBy i(+i)
     *
     * @param key
     * @param i
     * @return new value after incr
     */
    public static Long incrBy(String key, int i) {
        return InitRedisUtil.incrBy(key,i);
    }
 
    /**
     * exists valid
     *
     * @param key
     * @return Boolean reply, true if the key exists, otherwise false
     */
    public static boolean exists(String key) {
        return InitRedisUtil.exists(key);
    }
 
    /**
     * expire reset
     * @param key
     * @param seconds 存活时间,单位/秒
     * @return Integer reply, specifically:
     * 1: the timeout was set.
     * 0: the timeout was not set since the key already has an associated timeout (versions lt 2.1.3), or the key does not exist.
     */
    public static long expire(String key, int seconds) {
        return InitRedisUtil.expireAt(key,seconds);
    }
 
    /**
     * expire at unixTime
     * @param key
     * @param unixTime
     * @return
     */
    public static long expireAt(String key, long unixTime) {
        return InitRedisUtil.expireAt(key,unixTime);
    }
 
    /**
     * 实现redis keys 模糊查询
     * @author hq
     * @param pattern
     * @return
     */
    public static List<String> keys(String pattern){
        return InitRedisUtil.keys(pattern);
    }
 
    public static void main(String[] args) {
 
    }
}