Redis
要设置 Redis 状态储存,请创建一个类型为 的组件。 请参阅本指南,了解如何创建和应用状态存储配置。
TLS: 如果Redis 实例支持公开证书的TLS,它可以配置为启用或禁用 TLS true
或 fals
Failover: When set to true
enables the failover feature. The redisHost should be the sentinel host address. See
Warning
以上示例将密钥明文存储, It is recommended to use a secret store for the secrets as described .
If you wish to use Redis as an actor store, append the following to the yaml.
Dapr can use any Redis instance - containerized, running on your local dev machine, or a managed cloud service. If you already have a Redis store, move on to the Configuration section.
We can use to quickly create a Redis instance in our Kubernetes cluster. 这种方法需要安装Helm。
安装 Redis 到你的集群: Note that we’re explicitly setting an image tag to get a version greater than 5, which is what Dapr’ pub/sub functionality requires. If you’re intending on using Redis as just a state store (and not for pub/sub), you do not have to set the image version.
执行
kubectl get pods
来查看现在正在集群中运行的Redis容器。Add as the
redisHost
in your file. 例如:Next, we’ll get the Redis password, which is slightly different depending on the OS we’re using:
Windows:执行
kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" > encoded.b64
,这将创建一个有你的加密后密码的文件。 接下来,执行certutil -decode encoded.b64 password.txt
,它将把你的redis密码放在一个名为password.txt
的文本文件中。 复制密码,删除这两个文件。
Add this password as the
redisPassword
value in your redis.yaml file. 例如:
Note: this approach requires having an Azure Subscription.
- Fill out necessary information and check the “Unblock port 6379” box, which will allow us to persist state without SSL.
- 点击“创建”来启动您的 Redis 实例的部署。
- Once your instance is created, you’ll need to grab the Host name (FQDN) and your access key.
- for the Host name navigate to the resources “Overview” and copy “Host name”
- for your access key navigate to “Access Keys” under “Settings” and copy your key.
- Finally, we need to add our key and our host to a
redis.yaml
file that Dapr can apply to our cluster. If you’re running a sample, you’ll add the host and key to the providedredis.yaml
. If you’re creating a project from the ground up, you’ll create aredis.yaml
file as specified in . Set theredisHost
key to[HOST NAME FROM PREVIOUS STEP]:6379
and theredisPassword
key to the key you copied in step 4. Note: In a production-grade application, follow secret management instructions to securely manage your secrets.
Note
作为dapr init
命令的一部分,Dapr CLI会在自托管模式下自动部署本地redis实例。
- Dapr组件的基本格式
- 阅读 以获取配置状态存储组件的说明