java110
2023-05-09 c8b3b13e07a14bfb99aa87b839f15b4ab9046427
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
199
200
201
202
203
204
205
206
207
208
package com.java110.core.cache;
 
import com.java110.utils.cache.Jedis;
import com.java110.utils.factory.ApplicationContextFactory;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
 
import java.io.IOException;
import java.util.List;
import java.util.Set;
 
@Component
public class JedisClientPool implements Jedis {
    @Override
    public String set(String key, String value) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
           return jedis.set(key, value);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public String set(byte[] key, byte[] value) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.set(key, value);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public String set(String key, String value, String nxxx, String expx, int time) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.set(key, value,nxxx,expx,time);
        }finally {
            jedis.close();
        }
    }
 
 
    @Override
    public String get(String key) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.get(key);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public byte[] get(byte[] key) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.get(key);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public Boolean exists(String key) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.exists(key);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public Long expire(String key, int seconds) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.expire(key, seconds);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public Long ttl(String key) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.ttl(key);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public Long incr(String key) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.incr(key);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public Long hset(String key, String field, String value) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.hset(key, field, value);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public String hget(String key, String field) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.hget(key, field);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public Long hdel(String key, String... field) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.hdel(key, field);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public Long del(String key) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.del(key);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public Long del(byte[] key) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.del(key);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public void close() {
//        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
//        jedisPool.getResource().close();
    }
 
    @Override
    public Set<String> keys(String pattern) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.keys(pattern);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public Object eval(String script, int keyCount, String... params) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.eval(script,keyCount,params);
        }finally {
            jedis.close();
        }
    }
 
    @Override
    public Object eval(String script, List<String> keys, List<String> args) {
        JedisPool jedisPool = (JedisPool) ApplicationContextFactory.getBean("jedisPool");
        redis.clients.jedis.Jedis jedis = jedisPool.getResource();
        try {
            return jedis.eval(script,keys,args);
        }finally {
            jedis.close();
        }
    }
}