package com.codvision.auth.core.token;

import com.codvision.authcore.bean.SysUserBean;
import com.codvision.authcore.constants.AuthCoreConstant;
import com.codvision.cachecore.utils.RedisUtil;

/**
 * redis管理器接口
 *
 * @author lingee
 * @date 2023/11/22
 */
public class RedisTokenManager implements ITokenManager {


    @Override
    public void setTokenUser(String token, SysUserBean sysUser) {
        sysUser.setToken(token);
        sysUser.setPassword(null);
        RedisUtil.set(AuthCoreConstant.LOGIN_USER_EXPIRE_PREFIX + token, sysUser);
    }

    @Override
    public SysUserBean getTokenUser(String token) {
        return RedisUtil.get(AuthCoreConstant.LOGIN_USER_EXPIRE_PREFIX + token);
    }

    @Override
    public void removeTokenUser(String token) {
        String key = AuthCoreConstant.LOGIN_USER_EXPIRE_PREFIX + token;
        if (RedisUtil.hasKey(key)) {
            RedisUtil.del(key);
        }
    }
}
