RedisService.java
1.5 KB
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
package com.viontech.fanxing.commons.service;
import com.viontech.fanxing.commons.constant.RedisKeys;
import org.redisson.api.*;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* .
*
* @author 谢明辉
* @date 2021/7/26
*/
@Service
public class RedisService {
@Resource
private RedissonClient redissonClient;
public RMap<String, String> getTaskVaServerMap() {
return redissonClient.getMap(RedisKeys.SCHEDULING_TASK_VASERVER_MAP);
}
public RScoredSortedSet<String> getToBeExecutedTaskUnidSet() {
return redissonClient.getScoredSortedSet(RedisKeys.SCHEDULING_TO_BE_EXECUTED_TASK_UNID_SET);
}
public RScoredSortedSet<String> getToBeTerminatedTaskUnidSet() {
return redissonClient.getScoredSortedSet(RedisKeys.SCHEDULING_TO_BE_TERMINATED_TASK_UNID_SET);
}
public <T> RBucket<T> getValue(String key) {
return redissonClient.getBucket(key);
}
public RLock getLockMust(String lockName) {
RLock lock = redissonClient.getLock(lockName);
lock.lock();
return lock;
}
public RLock tryLock(String lockName) {
RLock lock = redissonClient.getLock(lockName);
boolean success = false;
try {
success = lock.tryLock(30, TimeUnit.SECONDS);
} catch (InterruptedException ignore) {
}
return success ? lock : null;
}
public RedissonClient getClient() {
return redissonClient;
}
}