以 CacheService ，Sa-Token Dao，及原生客户端三者复用为例

###  1、基于 redisx

依赖包配置

```yml
<dependency>
    <groupId>org.noear</groupId>
    <artifactId>solon-cache-jedis</artifactId>
    <!-- 或者用 （如果不需要 CacheService，直接用它）
    <artifactId>redisx</artifactId>
    -->
</dependency>

<dependency>
   <groupId>cn.dev33</groupId>
    <artifactId>sa-token-solon-plugin</artifactId>
    <version>最新版本</version>
</dependency>

<dependency>
   <groupId>cn.dev33</groupId>
    <artifactId>cn.dev33:sa-token-redisx</artifactId>
    <version>最新版本</version>
</dependency>

<dependency>
   <groupId>cn.dev33</groupId>
    <artifactId>cn.dev33:sa-token-snack3</artifactId> <!-- 序列化方案，按需选择 -->
    <version>最新版本</version>
</dependency>
```

应用配置（参考：[https://gitee.com/noear/redisx](https://gitee.com/noear/redisx)）

```yml
demo.redis:
  server: "localhost:6379"
  db: 0 #默认为 0，可不配置
  password: ""
  maxTotal: 200 #默认为 200，可不配
```

代码应用

```java
@Configuration
public class Config {
    // 构建 redis client（如直接用）
    @Bean
    public RedisClient redisClient(@Inject("${demo.redis}") RedisClient client) {
        return client;
    }
    
    //构建 Cache Service（给 @Cache 用）
    @Bean
    public CacheService cacheService(@Inject RedisClient client){
        return new RedisCacheService(client, 30);
    }
    
    //构建 SaToken Dao
    @Bean
    public SaTokenDao saTokenDao(@Inject RedisClient client){
        return new SaTokenDaoForRedisx(client, 30);
    }
}
```


###  2、基于 redisson



依赖包配置

```yml
<dependency>
    <groupId>org.noear</groupId>
    <artifactId>solon-cache-redisson</artifactId> 
    <!-- 或者用 （如果不需要 CacheService，直接用它）
    <artifactId>redisson-solon-plugin</artifactId>
    -->
</dependency>

<dependency>
   <groupId>cn.dev33</groupId>
    <artifactId>sa-token-solon-plugin</artifactId>
    <version>最新版本</version>
</dependency>

<dependency>
   <groupId>cn.dev33</groupId>
    <artifactId>cn.dev33:sa-token-redisson</artifactId>
    <version>最新版本</version>
</dependency>

<dependency>
   <groupId>cn.dev33</groupId>
    <artifactId>cn.dev33:sa-token-jackson</artifactId> <!-- 序列化方案，按需选择 -->
    <version>最新版本</version>
</dependency>
```

应用配置（参考：[redisson-solon-plugin](/article/533)）

```yml
demo.redis:
  config: |
    singleServerConfig:
      password: "123456"
      address: "redis://localhost:6379"
      database: 0
```

代码应用

```java
@Configuration
public class Config {
    // 构建 redis client（如直接用）；RedissonClientOriginalSupplier 支持 Redisson 的原始风格配置
    @Bean
    public RedissonClient redisClient(@Inject("${demo.redis}") RedissonClientOriginalSupplier supplier) {
        return supplier.get();
    }
    
    //构建 Cache Service（给 @Cache 用）
    @Bean
    public CacheService cacheService(@Inject RedissonClient client){
        return new RedissonCacheService(client, 30);
    }
    
    //构建 SaToken Dao //v2.4.3 后支持
    @Bean
    public SaTokenDao saTokenDao(@Inject RedissonClient client){
        return new SaTokenDaoForRedisson(client, 30);
    }
}
```















