27 lines
886 B
Java
27 lines
886 B
Java
|
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);
|
|||
|
}
|
|||
|
}
|