Test-Warehouse/src/main/java/com/example/vuedemov20/Token/RedisUtil.java

27 lines
886 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.example.vuedemov20.Token;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class RedisUtil {
@Resource
private RedisTemplate<String, String> stringRedisTemplate;//这是一个使用redis的API可以直接用StringRedisTemplate
public void addTokens(String username, String token) {//存入token
ValueOperations valueOperations = stringRedisTemplate.opsForValue();
valueOperations.set(username, token);
}
public String getTokens(String username) {//获取token
return stringRedisTemplate.opsForValue().get(username);
}
public void delTokens(String username) {//删除token在前端已经进行
stringRedisTemplate.delete(username);
}
}