Redis Streams

关于Redis Streams pubsub组件的详细文档

配置

要设置Redis Streams pubsub,请创建一个类型为pubsub.redis的组件。 See this guide on how to create and apply a pubsub configuration.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: redis-pubsub
  5. namespace: default
  6. spec:
  7. type: pubsub.redis
  8. version: v1
  9. metadata:
  10. - name: redisHost
  11. value: localhost:6379
  12. - name: redisPassword
  13. value: "KeFg23!"
  14. - name: consumerID
  15. value: "myGroup"
  16. - name: enableTLS
  17. value: "false"

Warning

以上示例将密钥明文存储, It is recommended to use a secret store for the secrets as described here.

元数据字段规范

字段必填详情Example
redisHostYRedis的连接地址. If “redisType” is “cluster” it can be multiple hosts separated by commas or just a single hostlocalhost:6379, redis-master.default.svc.cluster.local:6379
redisPasswordYRedis的密码 无默认值 可以用secretKeyRef来引用密钥。“”, “KeFg23!”
consumerIDN消费组 ID“mygroup”
enableTLSN如果Redis实例支持使用公共证书的TLS,可以配置为启用或禁用。 默认值为 “false”“true”, “false”
redeliverIntervalNThe interval between checking for pending messages to redelivery. Defaults to “60s”. “0” disables redelivery.“30s”
processingTimeoutNThe amount time a message must be pending before attempting to redeliver it. Defaults to “15s”. “0” disables redelivery.“30s”
queueDepthNThe size of the message queue for processing. 默认值为 “100”.“1000”
并发(Concurrency)NThe number of concurrent workers that are processing messages. 默认值为 “10”.“15”
redisTypeNThe type of redis. There are two valid values, one is “node” for single node mode, the other is “cluster” for redis cluster mode. Defaults to “node”.“cluster”
redisDBNDatabase selected after connecting to redis. If “redisType” is “cluster” this option is ignored. 默认值为 “0”.“0”
redisMaxRetriesNMaximum number of times to retry commands before giving up. Default is to not retry failed commands.“5”
redisMinRetryIntervalNMinimum backoff for redis commands between each retry. Default is “8ms”; “-1” disables backoff.“8ms”
redisMaxRetryIntervalNMaximum backoff for redis commands between each retry. Default is “512ms”;“-1” disables backoff.“5s”
dialTimeoutNDial timeout for establishing new connections. Defaults to “5s”.“5s”
readTimeoutNTimeout for socket reads. If reached, redis commands will fail with a timeout instead of blocking. Defaults to “3s”, “-1” for no timeout.“3s”
writeTimeoutNTimeout for socket writes. If reached, redis commands will fail with a timeout instead of blocking. Defaults is readTimeout.“3s”
poolSizeNMaximum number of socket connections. Default is 10 connections per every CPU as reported by runtime.NumCPU.“20”
poolTimeoutNAmount of time client waits for a connection if all connections are busy before returning an error. Default is readTimeout + 1 second.“5s”
maxConnAgeNConnection age at which the client retires (closes) the connection. Default is to not close aged connections.“30m”
minIdleConnsNMinimum number of idle connections to keep open in order to avoid the performance degradation associated with creating new connections. 默认值为 “0”.“2”
idleCheckFrequencyNFrequency of idle checks made by idle connections reaper. Default is “1m”. “-1” disables idle connections reaper.“-1”
idleTimeoutNAmount of time after which the client closes idle connections. Should be less than server’s timeout. Default is “5m”. “-1” disables idle timeout check.“10m”
maxLenApproxNMaximum number of items inside a stream.The old entries are automatically evicted when the specified length is reached, so that the stream is left at a constant size. Defaults to unlimited.“10000”

创建Redis实例

Dapr可以使用任何Redis实例,无论是容器化的,运行在本地开发机器上的,或者是托管的云服务,前提是Redis的版本是5.0.0或更高。

Dapr CLI将自动为你创建和设置一个Redis Streams实例。 当你执行dapr init时,Redis实例将通过Docker安装,组件文件将在默认目录下创建。 (默认目录位于$HOME/.dapr/components (Mac/Linux) ,%USERPROFILE%\.dapr\components (Windows)).

您可以使用 helm 在我们的 Kubernetes 集群中快速创建 dapr 实例。 这种方法需要安装Helm

  1. 安装 Redis 到你的集群:

    1. helm repo add bitnami https://charts.bitnami.com/bitnami
    2. helm install redis bitnami/redis
  2. 执行kubectl get pods来查看现在正在集群中运行的Redis容器。

  3. 在您的redis.yaml文件中添加redis-master:6379作为redisHost。 例如:

    1. metadata:
    2. - name: redisHost
    3. value: redis-master:6379
  4. 接下来,我们会获取到我们的Redis密码,根据我们使用的操作系统不同,密码也会略有不同:

    • Windows:执行kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" > encoded.b64,这将创建一个有你的加密后密码的文件。 接下来,执行certutil -decode encoded.b64 password.txt,它将把你的redis密码放在一个名为password.txt的文本文件中。 复制密码,删除这两个文件。

    • Linux/MacOS:执行 kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 --decode并复制输出的密码。

    将此密码设置为redis.yaml文件的redisPassword的值。 例如:

    1. - name: redisPassword
    2. value: "lhDOkwTlp0"

AWS Redis

GCP Cloud MemoryStore

Azure Redis

Note

作为dapr init命令的一部分,Dapr CLI会在自托管模式下自动部署本地redis实例。

相关链接