服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Redis - redis监听key过期事件的详细步骤

redis监听key过期事件的详细步骤

2022-08-10 20:45ypp91zr Redis

本文主要介绍了redis监听key过期事件的详细步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

1、配置redis.conf文件

配置文件默认是#注释了的,改为notify-keyspace-events Ex    重启redis,记住指定redis.conf配置文件启动

如果是阿里云的redis,进入redis管理页面==>>左边导航栏的参数设置

redis监听key过期事件的详细步骤

2、 配置一个key过期事件的监听器

?
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
package com.shinedata.config.redis;
 
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.JedisPubSub;
 
/**
 * @ClassName RedisKeyExpiredListener  监听订阅类
 * @Author yupanpan
 * @Date 2020/4/17 13:44
 */
public class RedisKeyExpiredListener extends JedisPubSub {
    /**
     * 日志
     */
    private static Logger logger    = LoggerFactory.getLogger(RedisKeyExpiredListener.class);
 
    /**
     *
     * @Title: onMessage
     * @Description: 取得订阅的消息后的处理
     * @param channel
     *            频道
     * @param message
     *            消息内容
     *
     * @author
     * @date
     */
    @Override
    public void onMessage(String channel, String message) {
        logger.info("channel{" + channel + "}message{" + message + "}");
    }
 
    /**
     *
     * @Title: onPMessage
     * @Description: 取得按表达式的方式订阅的消息后的处理
     *
     * @author
     * @date
     */
    @Override
    public void onPMessage(String pattern, String channel, String message) {
        logger.info("Redis订阅监听超时通知开始pattern{" + pattern + "}channel{" + channel + "}message{" + message + "}");
        long starTime = System.currentTimeMillis();
        if (StringUtils.isBlank(message)) {
            logger.info("Redis订阅监听超时通知,message为空");
            return;
        }
        long endTime = System.currentTimeMillis();
        logger.info("Redis订阅监听超时通知完成pattern{" + pattern + "}channel{" + channel + "}message{" + message + "}共耗时{"
                + (endTime - starTime) / 1000 + "}秒");
    }
}

3、订阅key过期事件

key过期时redis会自动把key推进订阅事件,配置上面自己的监听器,有key过期事件会通过onMessage方法进入,处理自己的业务逻辑,删除key不会通知

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.shinedata.config.redis;
 
import redis.clients.jedis.Jedis;
 
/**
 * @ClassName Subscriber 订阅是阻塞的,单独开线程发起订阅,订阅过期key,索引库1
 * @Author yupanpan
 * @Date 2020/4/17 14:29
 */
public class RedisKeyExpiredSubscriberRunnable implements Runnable{
 
    @Override
    public void run() {
        Jedis jedis = JedisUtils.getJedis();
        RedisKeyExpiredListener listener=new RedisKeyExpiredListener();
        jedis.subscribe(listener,"__keyevent@1__:expired");
        JedisUtils.returnResource(jedis);
    }
}

索引库根据自己业务需要选择,__keyevent@1__:expired       1代表为订阅索引库1中的key过期,索引库有0-15

如果不写为全部索引库,为 __keyevent@__:expired

4、发起订阅

这里在程序应用启动时发起(使用Spring自带的Runner,在服务启动时会执行相应的run方法)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package com.shinedata.config.redis;
 
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
 
/**
 * @ClassName RedisPublisherRunner 应用启用发起订阅
 * @Author yupanpan
 * @Date 2020/4/20 14:11
 */
@Component
public class RedisPublisherRunner implements CommandLineRunner {
 
    @Override
    public void run(String... args) throws Exception {
        new Thread(new RedisKeyExpiredSubscriberRunnable()).start();
    }
}

测试

?
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
package com.shinedata;
 
import com.google.common.collect.Lists;
import com.shinedata.config.redis.JedisUtils;
import com.shinedata.enums.InstScaleEnum;
import com.shinedata.enums.SchoolTypeEnum;
import com.shinedata.enums.StatusEnum;
import com.shinedata.enums.UserTypeEnum;
import com.shinedata.order.UserInstOrder;
import com.shinedata.order.UserOrder;
import com.shinedata.service.order.OrderAsyncService;
import com.shinedata.util.RetryUtils;
import com.shinedata.util.list.ListUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
import com.shinedata.service.UserService;
import com.shinedata.timer.HuifuBillTimer;
import redis.clients.jedis.Jedis;
 
import java.util.List;
 
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class )//这里是启动类
public class HuiBillTest extends BaseTest {
    @Autowired
    UserService userService;
 
    @Autowired
    private HuifuBillTimer huifuBillTimer;
 
    @Autowired
    OrderAsyncService orderAsyncService;
    
    @Test
    public void sendHuifuBill() throws InterruptedException {
        Jedis jedis = JedisUtils.getJedis();
        jedis.select(1);
        jedis.setex("ypp", 20, "ypp");
    }
 
}

结果:

redis监听key过期事件的详细步骤

其他配置redis和工具类,这里配置的默认索引库为0.如果操作其他索引库,自行配置或者直接使用jedis.select(int database)

JedisConfig

?
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
package com.shinedata.config.redis;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
 
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
 
/**
 * @ClassName JedisConfig
 * @Author yupanpan
 * @Date 2019/10/10 16:46
 */
@Component
public class JedisConfig extends RedisProperties {
    
    private static final Logger logger      = LoggerFactory.getLogger(JedisConfig.class);
    
    private static JedisPool    jedisPool   = null;
    
    private static void initialPool() {
        try {
            JedisPoolConfig config = new JedisPoolConfig();
            //最大空闲连接数, 应用自己评估,不要超过ApsaraDB for Redis每个实例最大的连接数
            config.setMaxIdle(500);
            config.setMinIdle(100);
            //最大连接数, 应用自己评估,不要超过ApsaraDB for Redis每个实例最大的连接数
            config.setMaxTotal(6000);
            config.setMaxWaitMillis(5000);
            //每timeBetweenEvictionRunsMillis毫秒秒检查一次连接池中空闲的连接,把空闲时间超过minEvictableIdleTimeMillis毫秒的连接断开,直到连接池中的连接数到minIdle为止
            config.setTimeBetweenEvictionRunsMillis(600);
            config.setMinEvictableIdleTimeMillis(100);
            config.setTestOnBorrow(true);
            config.setTestOnReturn(false);
            jedisPool = new JedisPool(config, redisHost, redisPort, 5000, redisPassword);
        } catch (Exception e) {
            if (jedisPool != null) {
                jedisPool.close();
            }
            logger.error("初始化Redis连接池失败", e);
        }
    }
    
    /**
     * 初始化Redis连接池
     */
    static {
        initialPool();
    }
    
    /**
     * 在多线程环境同步初始化
     */
    private static synchronized void poolInit() {
        if (jedisPool == null) {
            initialPool();
        }
    }
    
    /**
     * 同步获取Jedis实例
     *
     * @return Jedis
     */
    public Jedis getJedis() {
        if (jedisPool == null) {
            poolInit();
        }
        Jedis jedis = null;
        try {
            if (jedisPool != null) {
                jedis = jedisPool.getResource();
            }
        } catch (Exception e) {
            logger.error("同步获取Jedis实例失败" + e.getMessage(), e);
            returnResource(jedis);
        }
        
        return jedis;
    }
    
    /**
     * 释放jedis资源
     *
     * @param jedis
     */
    @SuppressWarnings("deprecation")
    public static void returnResource(final Jedis jedis) {
        if (jedis != null) {
            jedis.close();
        }
    }
}

JedisUtils

?
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
package com.shinedata.config.redis;
 
import org.checkerframework.checker.units.qual.min;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.BinaryClient;
import redis.clients.jedis.BitOP;
import redis.clients.jedis.BitPosParams;
import redis.clients.jedis.Jedis;
 
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
/**
 * @ClassName JedisUtils
 * @Author yupanpan
 * @Date 2019/10/9 15:10
 */
@Component
public class JedisUtils {
 
    private static final Logger logger = LoggerFactory.getLogger(JedisUtils.class);
 
    @Autowired
    private JedisConfig jedisConfig;
 
    private static JedisUtils jedisUtils;
 
    @PostConstruct
    public void init() {
        jedisUtils = this;
        jedisUtils.jedisConfig = this.jedisConfig;
    }
 
    public static Jedis getJedis() {
        return jedisUtils.jedisConfig.getJedis();
    }
 
    /**
     * 获取指定key的值,如果key不存在返回null,如果该Key存储的不是字符串,会抛出一个错误
     *
     * @param key
     * @return
     */
    public static String get(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.get(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    public static byte[] get(byte[] key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.get(key);
        } finally {
            returnResource(jedis);
        }
    }
 
 
    /**
     * 设置key的值为value
     *
     * @param key
     * @param value
     * @return
     */
    public static String set(String key, String value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.set(key, value);
        } finally {
            returnResource(jedis);
        }
    }
 
    public static String set(byte[] key, byte[] value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.set(key, value);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 删除指定的key,也可以传入一个包含key的数组
     *
     * @param keys
     * @return
     */
    public static Long del(String... keys) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.del(keys);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key向指定的value值追加值
     *
     * @param key
     * @param str
     * @return
     */
    public static Long append(String key, String str) {
 
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.append(key, str);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 判断key是否存在
     *
     * @param key
     * @return
     */
    public static Boolean exists(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        Boolean exists;
        try {
            exists = jedis.exists(key);
        } finally {
            jedis.close();
        }
        return exists;
    }
 
    /**
     * 设置key value,如果key已经存在则返回0
     *
     * @param key
     * @param value
     * @return
     */
    public static Long setnx(String key, String value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.setnx(key, value);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 设置key value并指定这个键值的有效期-秒
     *
     * @param key
     * @param seconds
     * @param value
     * @return
     */
    public static String setex(String key, String value, int seconds) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        String setex;
        try {
            setex = jedis.setex(key, seconds, value);
        } finally {
            jedis.close();
        }
        return setex;
    }
 
    public static String setex(byte[] key, byte[] value, int seconds) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        String setex;
        try {
            setex = jedis.setex(key, seconds, value);
        } finally {
            jedis.close();
        }
        return setex;
    }
 
    /**
     * 通过key 和offset 从指定的位置开始将原先value替换
     *
     * @param key
     * @param offset
     * @param str
     * @return
     */
    public static Long setrange(String key, int offset, String str) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        Long setrange;
        try {
            setrange = jedis.setrange(key, offset, str);
        } finally {
            jedis.close();
        }
        return setrange;
    }
 
    /**
     * 通过批量的key获取批量的value
     *
     * @param keys
     * @return
     */
    public static List<String> mget(String... keys) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.mget(keys);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 批量的设置key:value,也可以一个
     *
     * @param keysValues
     * @return
     */
    public static String mset(String... keysValues) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.mset(keysValues);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 批量的设置key:value,可以一个,如果key已经存在则会失败,操作会回滚
     *
     * @param keysValues
     * @return
     */
    public static Long msetnx(String... keysValues) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.msetnx(keysValues);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 设置key的值,并返回一个旧值
     *
     * @param key
     * @param value
     * @return
     */
    public static String getSet(String key, String value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.getSet(key, value);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过下标 和key 获取指定下标位置的 value
     *
     * @param key
     * @param startOffset
     * @param endOffset
     * @return
     */
    public static String getrange(String key, int startOffset, int endOffset) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.getrange(key, startOffset, endOffset);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key 对value进行加值+1操作,当value不是int类型时会返回错误,当key不存在是则value为1
     *
     * @param key
     * @return
     */
    public static Long incr(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.incr(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key给指定的value加值,如果key不存在,则这是value为该值
     *
     * @param key
     * @param integer
     * @return
     */
    public static Long incrBy(String key, long integer) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.incrBy(key, integer);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 对key的值做减减操作,如果key不存在,则设置key为-1
     *
     * @param key
     * @return
     */
    public static Long decr(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.decr(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 减去指定的值
     *
     * @param key
     * @param integer
     * @return
     */
    public static Long decrBy(String key, long integer) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.decrBy(key, integer);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取value值的长度
     *
     * @param key
     * @return
     */
    public static Long strLen(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.strlen(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key给field设置指定的值,如果key不存在则先创建,如果field已经存在,返回0
     *
     * @param key
     * @param field
     * @param value
     * @return
     */
    public static Long hsetnx(String key, String field, String value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hsetnx(key, field, value);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key给field设置指定的值,如果key不存在,则先创建
     *
     * @param key
     * @param field
     * @param value
     * @return
     */
    public static Long hset(String key, String field, String value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hset(key, field, value);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key同时设置 hash的多个field
     *
     * @param key
     * @param hash
     * @return
     */
    public static String hmset(String key, Map<String, String> hash) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hmset(key, hash);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key 和 field 获取指定的 value
     *
     * @param key
     * @param failed
     * @return
     */
    public static String hget(String key, String failed) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hget(key, failed);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 设置key的超时时间为seconds
     *
     * @param key
     * @param seconds
     * @return
     */
    public static Long expire(String key, int seconds) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.expire(key, seconds);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key 和 fields 获取指定的value 如果没有对应的value则返回null
     *
     * @param key
     * @param fields 可以是 一个String 也可以是 String数组
     * @return
     */
    public static List<String> hmget(String key, String... fields) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hmget(key, fields);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key给指定的field的value加上给定的值
     *
     * @param key
     * @param field
     * @param value
     * @return
     */
    public static Long hincrby(String key, String field, Long value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hincrBy(key, field,
                    value);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key和field判断是否有指定的value存在
     *
     * @param key
     * @param field
     * @return
     */
    public static Boolean hexists(String key, String field) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hexists(key,
                    field);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回field的数量
     *
     * @param key
     * @return
     */
    public static Long hlen(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hlen(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key 删除指定的 field
     *
     * @param key
     * @param fields 可以是 一个 field
     *               也可以是 一个数组
     * @return
     */
    public static Long hdel(String key, String... fields) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hdel(key
                    , fields);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回所有的field
     *
     * @param key
     * @return
     */
    public static Set<String> hkeys(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hkeys(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回所有和key有关的value
     *
     * @param key
     * @return
     */
    public static List<String> hvals(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hvals(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取所有的field和value
     *
     * @param key
     * @return
     */
    public static Map<String, String> hgetall(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.hgetAll(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key向list头部添加字符串
     *
     * @param key
     * @param strs 可以是一个string 也可以是string数组
     * @return 返回list的value个数
     */
    public static Long lpush(String key, String... strs) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.lpush(key, strs);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key向list尾部添加字符串
     *
     * @param key
     * @param strs 可以是一个string 也可以是string数组
     * @return 返回list的value个数
     */
    public static Long rpush(String key, String... strs) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.rpush(key, strs);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key在list指定的位置之前或者之后 添加字符串元素
     *
     * @param key
     * @param where LIST_POSITION枚举类型
     * @param pivot list里面的value
     * @param value 添加的value
     * @return
     */
    public static Long linsert(String key, BinaryClient.LIST_POSITION where, String pivot, String value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.linsert(key, where, pivot, value);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key设置list指定下标位置的value
     * 如果下标超过list里面value的个数则报错
     *
     * @param key
     * @param index 从0开始
     * @param value
     * @return 成功返回OK
     */
    public static String lset(String key, Long index, String value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.lset(key, index, value);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key从对应的list中删除指定的count个 和 value相同的元素
     *
     * @param key
     * @param count 当count为0时删除全部
     * @param value
     * @return 返回被删除的个数
     */
    public static Long lrem(String key, long count, String value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.lrem(key, count, value);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key保留list中从strat下标开始到end下标结束的value值
     *
     * @param key
     * @param start
     * @param end
     * @return 成功返回OK
     */
    public static String ltrim(String key, long start, long end) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.ltrim(key, start, end);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key从list的头部删除一个value,并返回该value
     *
     * @param key
     * @return
     */
    public static String lpop(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.lpop(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key从list尾部删除一个value,并返回该元素
     *
     * @param key
     * @return
     */
    public static String rpop(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.rpop(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key从一个list的尾部删除一个value并添加到另一个list的头部,并返回该value
     * 如果第一个list为空或者不存在则返回null
     *
     * @param srckey
     * @param dstkey
     * @return
     */
    public static String rpoplpush(String srckey, String dstkey) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.rpoplpush(srckey, dstkey);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取list中指定下标位置的value
     *
     * @param key
     * @param index
     * @return 如果没有返回null
     */
    public static String lindex(String key,
                                long index) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.lindex(key, index);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回list的长度
     *
     * @param key
     * @return
     */
    public static Long llen(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.llen(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取list指定下标位置的value
     * 如果start 为 0 end 为 -1 则返回全部的list中的value
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public static List<String> lrange(String key,
                                      long start,
                                      long end) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.lrange(key, start, end);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key向指定的set中添加value
     *
     * @param key
     * @param members 可以是一个String 也可以是一个String数组
     * @return 添加成功的个数
     */
    public static Long sadd(String key, String... members) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.sadd(key, members);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key删除set中对应的value值
     *
     * @param key
     * @param members 可以是一个String 也可以是一个String数组
     * @return 删除的个数
     */
    public static Long srem(String key, String... members) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.srem(key, members);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key随机删除一个set中的value并返回该值
     *
     * @param key
     * @return
     */
    public static String spop(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.spop(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取set中的差集
     * 以第一个set为标准
     *
     * @param keys 可以 是一个string 则返回set中所有的value 也可以是string数组
     * @return
     */
    public static Set<String> sdiff(String... keys) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.sdiff(keys);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取set中的差集并存入到另一个key中
     * 以第一个set为标准
     *
     * @param dstkey 差集存入的key
     * @param keys   可以 是一个string 则返回set中所有的value 也可以是string数组
     * @return
     */
    public static Long sdiffstore(String dstkey, String... keys) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.sdiffstore(dstkey, keys);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取指定set中的交集
     *
     * @param keys 可以 是一个string 也可以是一个string数组
     * @return
     */
    public static Set<String> sinter(String... keys) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.sinter(keys);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取指定set中的交集 并将结果存入新的set中
     *
     * @param dstkey
     * @param keys   可以 是一个string 也可以是一个string数组
     * @return
     */
    public static Long sinterstore(String dstkey, String... keys) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.sinterstore(dstkey, keys);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回所有set的并集
     *
     * @param keys 可以 是一个string 也可以是一个string数组
     * @return
     */
    public static Set<String> sunion(String... keys) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.sunion(keys);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回所有set的并集,并存入到新的set中
     *
     * @param dstkey
     * @param keys   可以 是一个string 也可以是一个string数组
     * @return
     */
    public static Long sunionstore(String dstkey, String... keys) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.sunionstore(dstkey, keys);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key将set中的value移除并添加到第二个set中
     *
     * @param srckey 需要移除的
     * @param dstkey 添加的
     * @param member set中的value
     * @return
     */
    public static Long smove(String srckey, String dstkey, String member) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.smove(srckey, dstkey, member);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取set中value的个数
     *
     * @param key
     * @return
     */
    public static Long scard(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.scard(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key判断value是否是set中的元素
     *
     * @param key
     * @param member
     * @return
     */
    public static Boolean sismember(String key, String member) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.sismember(key, member);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取set中随机的value,不删除元素
     *
     * @param key
     * @return
     */
    public static String srandmember(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.srandmember(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取set中所有的value
     *
     * @param key
     * @return
     */
    public static Set<String> smembers(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.smembers(key);
        } finally {
            returnResource(jedis);
        }
    }
 
 
    /**
     * 通过key向zset中添加value,score,其中score就是用来排序的
     * 如果该value已经存在则根据score更新元素
     *
     * @param key
     * @param score
     * @param member
     * @return
     */
    public static Long zadd(String key, double score, String member) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zadd(key, score, member);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key删除在zset中指定的value
     *
     * @param key
     * @param members 可以 是一个string 也可以是一个string数组
     * @return
     */
    public static Long zrem(String key, String... members) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zrem(key, members);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key增加该zset中value的score的值
     *
     * @param key
     * @param score
     * @param member
     * @return
     */
    public static Double zincrby(String key, double score, String member) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zincrby(key, score, member);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回zset中value的排名
     * 下标从小到大排序
     *
     * @param key
     * @param member
     * @return
     */
    public static Long zrank(String key, String member) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zrank(key, member);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回zset中value的排名
     * 下标从大到小排序
     *
     * @param key
     * @param member
     * @return
     */
    public static Long zrevrank(String key, String member) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zrevrank(key, member);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key将获取score从start到end中zset的value
     * socre从大到小排序
     * 当start为0 end为-1时返回全部
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public static Set<String> zrevrange(String key, long start, long end) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zrevrange(key, start, end);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回指定score内zset中的value
     *
     * @param key
     * @param max
     * @param min
     * @return
     */
    public static Set<String> zrangebyscore(String key, String max, String min) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zrevrangeByScore(key, max, min);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回指定score内zset中的value
     *
     * @param key
     * @param max
     * @param min
     * @return
     */
    public static Set<String> zrangeByScore(String key, double max, double min) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zrevrangeByScore(key, max, min);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 返回指定区间内zset中value的数量
     *
     * @param key
     * @param min
     * @param max
     * @return
     */
    public static Long zcount(String key, String min, String max) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zcount(key, min, max);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key返回zset中的value个数
     *
     * @param key
     * @return
     */
    public static Long zcard(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zcard(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key获取zset中value的score值
     *
     * @param key
     * @param member
     * @return
     */
    public static Double zscore(String key, String member) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zscore(key, member);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key删除给定区间内的元素
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public static Long zremrangeByRank(String key, long start, long end) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zremrangeByRank(key, start, end);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key删除指定score内的元素
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public static Long zremrangeByScore(String key, double start, double end) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.zremrangeByScore(key, start, end);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 返回满足pattern表达式的所有key
     * keys(*)  尽量不要用此方法,数据量太多会导致线程阻塞,匹配可控制范围数据量小情况下可以使用
     * 返回所有的key
     *
     * @param pattern
     * @return
     */
    @Deprecated
    public static Set<String> keys(String pattern) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.keys(pattern);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**
     * 通过key判断值得类型
     *
     * @param key
     * @return
     */
    public static String type(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.type(key);
        } finally {
            returnResource(jedis);
        }
    }
 
    /**bit map*/
    /**
     * 设置key指定偏移量的值
     * @author yupanpan
     * @date 2019/11/15 11:09
     * @param key
     * @param offset
     * @param value
     * @return java.lang.Boolean
     */
    public static Boolean setbit(String key, long offset, boolean value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.setbit(key,offset,value);
        } finally {
            returnResource(jedis);
        }
    }
    /**
     * 设置key指定偏移量的值
     * @author yupanpan
     * @date 2019/11/15 11:09
     * @param key
     * @param offset
     * @param value  只能是1或0字符串
     * @return java.lang.Boolean
     */
    public static Boolean setbit(String key, long offset, String value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.setbit(key,offset,value);
        } finally {
            returnResource(jedis);
        }
    }
    /**
     * 获取key指定偏移量的值
     * @author yupanpan
     * @date 2019/11/15 11:09
     * @param key
     * @param offset
     * @return java.lang.Boolean
     */
    public static Boolean getbit(String key, long offset) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.getbit(key,offset);
        } finally {
            returnResource(jedis);
        }
    }
    /**
     * 统计key 偏移量被设置为1的bit数.
     * @author yupanpan
     * @date 2019/11/15 11:09
     * @param key
     * @return java.lang.Boolean
     */
    public static Long bitcount(String key) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.bitcount(key);
        } finally {
            returnResource(jedis);
        }
    }
    /**
     * 一般情况下,给定的整个字符串都会被进行计数,通过指定额外的 start 或 end 参数,可以让计数只在特定的位上进行。
     * start 和 end 参数的设置和 GETRANGE 命令类似,都可以使用负数值:比如 -1 表示最后一个位,而 -2 表示倒数第二个位,以此类推。
     * 不存在的 key 被当成是空字符串来处理,因此对一个不存在的 key 进行 BITCOUNT 操作,结果为 0 。
     * @author yupanpan
     * @date 2019/11/15 11:12
     * @param key
     * @param start
     * @param end
     * @return java.lang.Long
     */
    public static Long bitcount(String key, long start, long end) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.bitcount(key, start, end);
        } finally {
            returnResource(jedis);
        }
    }
    /**
     * 对一个或多个保存二进制位的字符串 key 进行位元操作,并将结果保存到 destkey 上,时间复杂度:O(N),尽量少用
     * 支持 AND 、 OR 、 NOT 、 XOR 这四种操作中的任意一种参数--BitOP
     * @author yupanpan
     * @date 2019/11/15 11:14
     * @param op
     * @param destKey
     * @param srcKeys
     * @return java.lang.Long
     */
    public static Long bitop(BitOP op, String destKey, String... srcKeys) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.bitop(op, destKey, srcKeys);
        } finally {
            returnResource(jedis);
        }
    }
    /**
     * 返回字符串里面第一个被设置为value的bit位/偏移量
     * @author yupanpan
     * @date 2019/11/15 11:18
     * @param key
     * @param value true在redis bitmap二进制字符串代表为1 false为0
     * @return java.lang.Long
     */
    public static Long bitpos(String key, boolean value) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.bitpos(key,value);
        } finally {
            returnResource(jedis);
        }
    }
    public static Long bitpos(String key, boolean value, BitPosParams params) {
        Jedis jedis = jedisUtils.jedisConfig.getJedis();
        try {
            return jedis.bitpos(key,value,params);
        } finally {
            returnResource(jedis);
        }
    }
 
 
    /**
     * 释放jedis资源
     *
     * @param jedis
     */
    @SuppressWarnings("deprecation")
    public static void returnResource(final Jedis jedis) {
        if (jedis != null) {
            jedis.close();
        }
    }
}

代码复制粘贴可用,需要修改为自己的redis链接信息

到此这篇关于redis监听key过期事件的详细步骤的文章就介绍到这了,更多相关redis监听key过期事件内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/ypp91zr/article/details/105635225

延伸 · 阅读

精彩推荐
  • RedisRedis集群水平扩展、集群中添加以及删除节点的操作

    Redis集群水平扩展、集群中添加以及删除节点的操作

    这篇文章主要介绍了Redis集群水平扩展、集群中添加以及删除节点的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...

    只管努力,剩下的交给时8262021-07-28
  • Redis压缩Redis里的字符串大对象操作

    压缩Redis里的字符串大对象操作

    这篇文章主要介绍了压缩Redis里的字符串大对象操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...

    持盾的紫眸8822021-08-11
  • Redisredis锁机制介绍与实例

    redis锁机制介绍与实例

    今天小编就为大家分享一篇关于redis锁机制介绍与实例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看...

    qq_431937972922019-11-22
  • Redis基于redis+lua进行限流的方法

    基于redis+lua进行限流的方法

    这篇文章主要介绍了基于redis+lua进行限流,通过实例代码详细介绍了lua+redis进行限流的做法,开发环境使用idea+redis+lua,本文给大家介绍的非常详细,需要的...

    枯枫叶10452022-07-24
  • RedisRedis过期数据是否会被立马删除

    Redis过期数据是否会被立马删除

    这篇文章主要为大家介绍了Redis过期数据会被立马删除么的问题解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪...

    码哥字节5152022-07-22
  • RedisRedis 2.8-4.0过期键优化过程全纪录

    Redis 2.8-4.0过期键优化过程全纪录

    这篇文章主要给大家介绍了关于Redis 2.8-4.0过期键优化的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Redis具有一定的参考学习价值,...

    白馨3272019-11-23
  • RedisRedis教程(十一):虚拟内存介绍

    Redis教程(十一):虚拟内存介绍

    这篇文章主要介绍了Redis教程(十一):虚拟内存介绍,本文讲解了虚拟内存简介、应用场景和配置方法等内容,需要的朋友可以参考下 ...

    Redis教程网2352019-10-24
  • Redisredis实现简单队列

    redis实现简单队列

    这篇文章主要为大家详细介绍了redis实现简单队列的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 ...

    王立新2672019-10-31