seninel部署
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Sentinel DataSource Redis
  2. Sentinel DataSource Redis provides integration with Redis. The data source leverages Redis pub-sub feature to implement push model (listener).
  3. The data source uses [Lettuce](https://lettuce.io/) as the Redis client, which requires JDK 1.8 or later.
  4. > **NOTE**: Currently we do not support Redis Cluster now.
  5. ## Usage
  6. To use Sentinel DataSource Redis, you should add the following dependency:
  7. ```xml
  8. <dependency>
  9. <groupId>com.alibaba.csp</groupId>
  10. <artifactId>sentinel-datasource-redis</artifactId>
  11. <version>x.y.z</version>
  12. </dependency>
  13. ```
  14. Then you can create an `RedisDataSource` and register to rule managers.
  15. For instance:
  16. ```java
  17. ReadableDataSource<String, List<FlowRule>> redisDataSource = new RedisDataSource<List<FlowRule>>(redisConnectionConfig, ruleKey, channel, flowConfigParser);
  18. FlowRuleManager.register2Property(redisDataSource.getProperty());
  19. ```
  20. - `redisConnectionConfig`: use `RedisConnectionConfig` class to build your Redis connection config
  21. - `ruleKey`: the rule persistence key of a Redis String
  22. - `channel`: the channel to subscribe
  23. You can also create multi data sources to subscribe for different rule type.
  24. Note that the data source first loads initial rules from a Redis String (provided `ruleKey`) during initialization.
  25. So for consistency, users should publish the value and save the value to the `ruleKey` simultaneously like this (using Redis transaction):
  26. ```
  27. MULTI
  28. SET ruleKey value
  29. PUBLISH channel value
  30. EXEC
  31. ```
  32. An example using Lettuce Redis client:
  33. ```java
  34. public <T> void pushRules(List<T> rules, Converter<List<T>, String> encoder) {
  35. StatefulRedisPubSubConnection<String, String> connection = client.connectPubSub();
  36. RedisPubSubCommands<String, String> subCommands = connection.sync();
  37. String value = encoder.convert(rules);
  38. subCommands.multi();
  39. subCommands.set(ruleKey, value);
  40. subCommands.publish(ruleChannel, value);
  41. subCommands.exec();
  42. }
  43. ```
  44. ## How to build RedisConnectionConfig
  45. ### Build with Redis standalone mode
  46. ```java
  47. RedisConnectionConfig config = RedisConnectionConfig.builder()
  48. .withHost("localhost")
  49. .withPort(6379)
  50. .withPassword("pwd")
  51. .withDataBase(2)
  52. .build();
  53. ```
  54. ### Build with Redis Sentinel mode
  55. ```java
  56. RedisConnectionConfig config = RedisConnectionConfig.builder()
  57. .withRedisSentinel("redisSentinelServer1",5000)
  58. .withRedisSentinel("redisSentinelServer2",5001)
  59. .withRedisSentinelMasterId("redisSentinelMasterId").build();
  60. ```