Solon v3.0.3

lettuce-solon-plugin

</> markdown

此插件,由社区成员(Sorghum)贡献

<dependency>
    <groupId>org.noear</groupId>
    <artifactId>lettuce-solon-plugin</artifactId>
</dependency>

1、描述

数据扩展插件,基于 lettuce 封装(代码仓库),为 Solon Data 提供了 redis 的操作能力扩展。(v2.4.2 之后支持)

//这个插件,主要是为构建客户端提供小便利。其实也可以不用适配,直接使用。

2、配置示例

配置分格有两种:1,将配置内容独立为一个文件;2,将配置做为主配置的内容(注意 "|" 符号)。

### 任意选一种
### 模式一
redis.ds2:
  # Redis模式 (standalone, cluster, sentinel)
  redis-mode: standalone
  redis-uri: redis://localhost:6379/0

#### 模式二
lettuce.rd2:
  # Redis模式 (standalone, cluster, sentinel)
  redis-mode: standalone
  config:
    host: localhost
    port: 6379
#    socket: xxxx
#    client-name: myClientName
#    database: 0
#    sentinel-masterId: 'mymaster'
#    username: 'myusername'
#    password: 'mypassword'
#    ssl: false
#    verify-mode: FULL
#    startTls: false
#    timeout: 10000
#    sentinels:
#      - host: localhost
#        port: 16379
#        password: 'mypassword'
#      - host: localhost
#        port: 26379
#        password: 'mypassword'

3、应用示例

@Configuration
public class Config {
    @Bean(value = "redisDs1", typed = true)
    public RedisClient demo1(@Inject("${redis.ds1}") LettuceSupplier supplier) {
        return (RedisClient)supplier.get();
    }

    @Bean("redisDs2")
    public RedisClient demo2(@Inject("${redis.ds2}") LettuceSupplier supplier) {
        return (RedisClient)supplier.get(); //集群类的用 RedisClusterClient
    }
    
    //或者直接用 AbstractRedisClient
}

@Component
public class DemoService {
    
    @Inject //@Inject("redisDs1")
    RedisClient demo1;

    @Inject("redisDs2")
    RedisClient demo2;
    
}