- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Java实现RedisUtils操作五大集合(增删改查)由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
前排提示,我在这个工具类加了@Component注解,如果在springboot的项目使用,记得通过@Autowired注入使用.
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.data.redis.core.*;
import
org.springframework.stereotype.Component;
import
java.io.Serializable;
import
java.util.List;
import
java.util.Set;
@Component
public
class
RedisUtils {
@Autowired
private
RedisTemplate redisTemplate;
/**
* 写入String型 [ 键,值]
*
* @param key
* @param value
* @return
*/
public
boolean
set(
final
String key, Object value) {
boolean
result =
false
;
try
{
ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
operations.set(key, value);
result =
true
;
}
catch
(Exception e) {
e.printStackTrace();
}
return
result;
}
/**
* 写入String型,顺便带有过期时间 [ 键,值]
*
* @param key
* @param value
* @return
*/
public
boolean
setWithTime(
final
String key, Object value,
int
seconds) {
boolean
result =
false
;
try
{
ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
operations.set(key, value,seconds, TimeUnit.SECONDS);
result =
true
;
}
catch
(Exception e) {
e.printStackTrace();
}
return
result;
}
/**
* 批量删除对应的value
*
* @param keys
*/
public
void
remove(
final
String... keys) {
for
(String key : keys) {
remove(key);
}
}
/**
* 批量删除key
*
* @param pattern
*/
public
void
removePattern(
final
String pattern) {
Set<Serializable> keys = redisTemplate.keys(pattern);
if
(keys.size() >
0
)
redisTemplate.delete(keys);
}
/**
* 删除对应的value
*
* @param key
*/
public
void
remove(
final
String key) {
if
(exists(key)) {
redisTemplate.delete(key);
}
}
/**
* 判断缓存中是否有对应的value
*
* @param key
* @return
*/
public
boolean
exists(
final
String key) {
return
redisTemplate.hasKey(key);
}
/**
* 读取缓存
*
* @param key
* @return
*/
public
Object get(
final
String key) {
Object result =
null
;
ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
result = operations.get(key);
return
result;
}
/**
* 哈希 添加
* hash 一个键值(key->value)对集合
*
* @param key
* @param hashKey
* @param value
*/
public
void
hmSet(String key, Object hashKey, Object value) {
HashOperations<String, Object, Object> hash = redisTemplate.opsForHash();
hash.put(key, hashKey, value);
}
/**
* Hash获取数据
*
* @param key
* @param hashKey
* @return
*/
public
Object hmGet(String key, Object hashKey) {
HashOperations<String, Object, Object> hash = redisTemplate.opsForHash();
return
hash.get(key, hashKey);
}
/**
* 列表添加
* list:lpush key value1
*
* @param k
* @param v
*/
public
void
lPush(String k, Object v) {
ListOperations<String, Object> list = redisTemplate.opsForList();
list.rightPush(k, v);
}
/**
* 列表List获取
* lrange: key 0 10 (读取的个数 从0开始 读取到下标为10 的数据)
*
* @param k
* @param l
* @param l1
* @return
*/
public
List<Object> lRange(String k,
long
l,
long
l1) {
ListOperations<String, Object> list = redisTemplate.opsForList();
return
list.range(k, l, l1);
}
/**
* Set集合添加
*
* @param key
* @param value
*/
public
void
add(String key, Object value) {
SetOperations<String, Object> set = redisTemplate.opsForSet();
set.add(key, value);
}
/**
* Set 集合获取
*
* @param key
* @return
*/
public
Set<Object> setMembers(String key) {
SetOperations<String, Object> set = redisTemplate.opsForSet();
return
set.members(key);
}
/**
* Sorted set :有序集合添加
*
* @param key
* @param value
* @param scoure
*/
public
void
zAdd(String key, Object value,
double
scoure) {
ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();
zset.add(key, value, scoure);
}
/**
* Sorted set:有序集合获取
*
* @param key
* @param scoure
* @param scoure1
* @return
*/
public
Set<Object> rangeByScore(String key,
double
scoure,
double
scoure1) {
ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();
return
zset.rangeByScore(key, scoure, scoure1);
}
/**
* 根据key获取Set中的所有值
*
* @param key 键
* @return
*/
public
Set<Integer> sGet(String key) {
try
{
return
redisTemplate.opsForSet().members(key);
}
catch
(Exception e) {
e.printStackTrace();
return
null
;
}
}
/**
* 根据value从一个set中查询,是否存在
*
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
public
boolean
sHasKey(String key, Object value) {
try
{
return
redisTemplate.opsForSet().isMember(key, value);
}
catch
(Exception e) {
e.printStackTrace();
return
false
;
}
}
}
|
到此这篇关于Java实现RedisUtils操作五大集合(增删改查)的文章就介绍到这了,更多相关Java RedisUtils操作内容请搜索我以前的文章或继续浏览下面的相关文章希望大家以后多多支持我! 。
原文链接:https://blog.csdn.net/qq_35387940/article/details/94392100 。
最后此篇关于Java实现RedisUtils操作五大集合(增删改查)的文章就讲到这里了,如果你想了解更多关于Java实现RedisUtils操作五大集合(增删改查)的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
数据库操纵基本流程为: 1、连接数据库服务器 2、选择数据库 3、执行SQL语句 4、处理结果集 5、打印操作信息 其中用到的相关函数有 •resource m
CRUD是Create(创建)、Read(读取)、Update(更新)和Delete(删除)的缩写,它是普通应用程序的缩影。如果您掌握了某框架的CRUD编写,那么意味可以使用该框架创建普通应用程序了
项目结构: 添加页面: &
本文实例讲述了android操作sqlite数据库(增、删、改、查、分页等)及listview显示数据的方法。分享给大家供大家参考,具体如下: 由于刚接触android开发,故此想把学到的基础知识
总括 pandas的索引函数主要有三种: loc 标签索引,行和列的名称 iloc 整型索引(绝对位置索引),绝对意义上的几行几列,起始索引为0 ix 是 iloc 和 loc的合体 at
1. [代码]Mybatis全局配置文件 ? 1
我是一名优秀的程序员,十分优秀!