提交 | 用户 | 时间
|
97edd7
|
1 |
package com.iailab.module.shasteel.framework.captcha.core; |
H |
2 |
|
|
3 |
import com.xingyuv.captcha.service.CaptchaCacheService; |
|
4 |
import lombok.Setter; |
|
5 |
import org.springframework.data.redis.core.StringRedisTemplate; |
|
6 |
|
|
7 |
import java.util.concurrent.TimeUnit; |
|
8 |
|
|
9 |
/** |
|
10 |
* 基于 Redis 实现验证码的存储 |
|
11 |
* |
|
12 |
* @author 星语 |
|
13 |
*/ |
|
14 |
@Setter |
|
15 |
public class RedisCaptchaServiceImpl implements CaptchaCacheService { |
|
16 |
|
|
17 |
private StringRedisTemplate stringRedisTemplate; |
|
18 |
|
|
19 |
@Override |
|
20 |
public String type() { |
|
21 |
return "redis"; |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
public void set(String key, String value, long expiresInSeconds) { |
|
26 |
stringRedisTemplate.opsForValue().set(key, value, expiresInSeconds, TimeUnit.SECONDS); |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
public boolean exists(String key) { |
|
31 |
return Boolean.TRUE.equals(stringRedisTemplate.hasKey(key)); |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public void delete(String key) { |
|
36 |
stringRedisTemplate.delete(key); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public String get(String key) { |
|
41 |
return stringRedisTemplate.opsForValue().get(key); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public Long increment(String key, long val) { |
|
46 |
return stringRedisTemplate.opsForValue().increment(key,val); |
|
47 |
} |
|
48 |
|
|
49 |
} |