package com.xintong.system.securityTools;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

@Component
public class RedisCacheUtil {
	@Autowired
	private RedisTemplate redisTemplate;
	
	
	public UserDetails getUserByUserName(String username){
		return (UserDetails)redisTemplate.opsForValue().get(username);
	}
	
	public void setUser(String username,UserDetails user,int timeout){
		redisTemplate.opsForValue().set(username, user, timeout, TimeUnit.MILLISECONDS);
	}
	
	public void removeForUserName(String username){
		redisTemplate.delete(username);
	}
	

}
