连接redis成功

main
XiaoHH 2 years ago
parent 4859673e2b
commit 373e6c0ae6

@ -7,3 +7,4 @@ spring:
config: config:
server-addr: 192.168.3.231:8848 server-addr: 192.168.3.231:8848
namespace: taxi-dev namespace: taxi-dev
file-extension: yaml

@ -43,6 +43,12 @@
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency> </dependency>
<!-- 连接redis的依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- util 工具模块 --> <!-- util 工具模块 -->
<dependency> <dependency>
<groupId>com.greateme</groupId> <groupId>com.greateme</groupId>

@ -5,9 +5,13 @@ import com.greateme.verification.entity.dto.PassengerVerificationCodeDTO;
import com.greateme.verification.entity.dto.PassengerVerificationCodeRedisDTO; import com.greateme.verification.entity.dto.PassengerVerificationCodeRedisDTO;
import com.greateme.verification.entity.vo.PassengerVerificationCodeVO; import com.greateme.verification.entity.vo.PassengerVerificationCodeVO;
import com.greateme.verification.service.VerificationCodeService; import com.greateme.verification.service.VerificationCodeService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit;
/** /**
* <p> * <p>
@ -22,6 +26,17 @@ import java.util.UUID;
@Service @Service
public class VerificationCodeServiceImpl implements VerificationCodeService { public class VerificationCodeServiceImpl implements VerificationCodeService {
/**
* redis
*/
@Autowired
private RedisTemplate redisTemplate;
/**
* redis
*/
private static final String PASSENGER_PHONE_VERIFICATION_CODE_PREFIX = "PASSENGER::PHONE::VERIFICATION::CODE::";
/** /**
* *
* *
@ -40,7 +55,8 @@ public class VerificationCodeServiceImpl implements VerificationCodeService {
verificationCodeRedis.setVerificationCode(code); verificationCodeRedis.setVerificationCode(code);
verificationCodeRedis.setPassengerPhone(verificationCode.getPassengerPhone()); verificationCodeRedis.setPassengerPhone(verificationCode.getPassengerPhone());
verificationCodeRedis.setToken(token); verificationCodeRedis.setToken(token);
// TODO 将 verificationCodeRedis 存入redis // 将 verificationCodeRedis 存入redis
this.redisTemplate.opsForValue().set(PASSENGER_PHONE_VERIFICATION_CODE_PREFIX + token, verificationCodeRedis, 5, TimeUnit.MINUTES);
// 将token和code返回 // 将token和code返回
PassengerVerificationCodeVO result = new PassengerVerificationCodeVO(); PassengerVerificationCodeVO result = new PassengerVerificationCodeVO();
result.setVerificationCode(code); result.setVerificationCode(code);

@ -7,3 +7,4 @@ spring:
config: config:
server-addr: 192.168.3.231:8848 server-addr: 192.168.3.231:8848
namespace: taxi-dev namespace: taxi-dev
file-extension: yaml

Loading…
Cancel
Save