seninel部署
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
Eric Zhao a0196b6b00 Bump version to 1.8.0-SNAPSHOT il y a 4 ans
..
src Make build faster by reducing fixed waiting time in tests (#449) il y a 5 ans
README.md Update document to meet Markdown lint il y a 6 ans
pom.xml Bump version to 1.8.0-SNAPSHOT il y a 4 ans

README.md

Sentinel DataSource Redis

Sentinel DataSource Redis provides integration with Redis. The data source leverages Redis pub-sub feature to implement push model (listener).

The data source uses Lettuce as the Redis client internal. Requires JDK 1.8 or later.

NOTE: Currently we do not support Redis Cluster now.

Usage

To use Sentinel DataSource Redis, you should add the following dependency:

<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-datasource-redis</artifactId>
    <version>x.y.z</version>
</dependency>

Then you can create an RedisDataSource and register to rule managers. For instance:

ReadableDataSource<String, List<FlowRule>> redisDataSource = new RedisDataSource<List<FlowRule>>(redisConnectionConfig, ruleKey, channel, flowConfigParser);
FlowRuleManager.register2Property(redisDataSource.getProperty());
  • redisConnectionConfig: use RedisConnectionConfig class to build your Redis connection config
  • ruleKey: the rule persistence key of a Redis String
  • channel: the channel to subscribe

You can also create multi data sources to subscribe for different rule type.

Note that the data source first loads initial rules from a Redis String (provided ruleKey) during initialization. So for consistency, users should publish the value and save the value to the ruleKey simultaneously like this (using Redis transaction):

MULTI
SET ruleKey value
PUBLISH channel value
EXEC

An example using Lettuce Redis client:

public <T> void pushRules(List<T> rules, Converter<List<T>, String> encoder) {
    StatefulRedisPubSubConnection<String, String> connection = client.connectPubSub();
    RedisPubSubCommands<String, String> subCommands = connection.sync();
    String value = encoder.convert(rules);
    subCommands.multi();
    subCommands.set(ruleKey, value);
    subCommands.publish(ruleChannel, value);
    subCommands.exec();
}

How to build RedisConnectionConfig

Build with Redis standalone mode

RedisConnectionConfig config = RedisConnectionConfig.builder()
                .withHost("localhost")
                .withPort(6379)
                .withPassword("pwd")
                .withDataBase(2)
                .build();

Build with Redis Sentinel mode

RedisConnectionConfig config = RedisConnectionConfig.builder()
                .withRedisSentinel("redisSentinelServer1",5000)
                .withRedisSentinel("redisSentinelServer2",5001)
                .withRedisSentinelMasterId("redisSentinelMasterId").build();