package com.ruoyi.framework.config;

import cn.dev33.satoken.dao.SaTokenDao;
import cn.dev33.satoken.dao.SaTokenDaoForRedisson;
import com.ruoyi.common.utils.RedisUtil;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.redisson.api.RedissonClient;
import org.redisson.solon.RedissonClientOriginalSupplier;

/**
 * Redis配置
 * @author ruoyi
 */
@Configuration
public class RedisConfig {

    /**
     * RedissonClient
     * @param supplier
     * @return
     */
    @Bean
    public RedissonClient redissonClient(@Inject("${redis.cache_source}") RedissonClientOriginalSupplier supplier) {
        return supplier.get();
    }

    /**
     * SaTokenDao
     * @param redissonClient
     * @return
     */
    @Bean
    @Condition(onClass = RedissonClient.class)
    public SaTokenDao saTokenDaoInit(RedissonClient redissonClient) {
        return new SaTokenDaoForRedisson(redissonClient);
    }

    /**
     * RedisUtil
     * @return
     */
    @Bean
    @Condition(onClass = RedissonClient.class)
    public RedisUtil redisUtil(RedissonClient redissonClient) {
        return new RedisUtil(redissonClient);
    }

}
