How-To: Configure state store and pub/sub message broker

In order to get up and running with the state and pub/sub building blocks two components are needed:

  1. A state store component for persistence and restoration
  2. As pub/sub message broker component for async-style message delivery

A full list of supported components can be found here:

The rest of this page describes how to get up and running with Redis.

Self-hosted mode

When initialized in self-hosted mode, Dapr automatically runs a Redis container and sets up the required component yaml files. You can skip this page and go to

Dapr can use any Redis instance - either containerized on your local dev machine or a managed cloud service. If you already have a Redis store, move on to the configuration section.

Redis is automatically installed in self-hosted environments by the Dapr CLI as part of the initialization process. You are all set and can skip to the next steps

You can use to quickly create a Redis instance in our Kubernetes cluster. This approach requires Installing Helm v3.

  1. Install Redis into your cluster:

  2. Run to see the Redis containers now running in your cluster:

    1. $ kubectl get pods
    2. NAME READY STATUS RESTARTS AGE
    3. redis-master-0 1/1 Running 0 69s
    4. redis-replicas-0 1/1 Running 0 69s
    5. redis-replicas-1 1/1 Running 0 22s

Note that the hostname is redis-master.default.svc.cluster.local:6379, and a Kubernetes secret, redis, is created automatically.

This method requires having an Azure Subscription.

  1. Open the to start the Azure Redis Cache creation flow. Log in if necessary.
  2. Fill out the necessary information
    • Dapr pub/sub uses Redis streams that was introduced by Redis 5.0. If you would like to use Azure Redis Cache for pub/sub make sure to set the version to (PREVIEW) 6.
  3. Click “Create” to kickoff deployment of your Redis instance.
  4. You’ll need the hostname of your Redis instance, which you can retrieve from the “Overview” in Azure. It should look like xxxxxx.redis.cache.windows.net:6380. Note this for later.
  5. Once your instance is created, you’ll need to grab your access key. Navigate to “Access Keys” under “Settings” and create a Kubernetes secret to store your Redis password:

    1. Visit to deploy a Redis instance
    2. Note the Redis hostname in the AWS portal for use later
    3. Create a Kubernetes secret to store your Redis password:

    1. Visit GCP Cloud MemoryStore to deploy a MemoryStore instance
    2. Note the Redis hostname in the GCP portal for use later
    3. Create a Kubernetes secret to store your Redis password:

      1. kubectl create secret generic redis --from-literal=redis-password=*********

    Dapr uses components to define what resources to use for building block functionality. These steps go through how to connect the resources you created above to Dapr for state and pub/sub.

    In self-hosted mode, component files are automatically created under:

    • Windows: %USERPROFILE%\.dapr\components\
    • Linux/MacOS: $HOME/.dapr/components

    Create a file named redis-state.yaml, and paste the following:

    1. apiVersion: dapr.io/v1alpha1
    2. kind: Component
    3. metadata:
    4. name: statestore
    5. namespace: default
    6. spec:
    7. type: state.redis
    8. version: v1
    9. metadata:
    10. value: <REPLACE WITH HOSTNAME FROM ABOVE - for Redis on Kubernetes it is redis-master.default.svc.cluster.local:6379>
    11. - name: redisPassword
    12. secretKeyRef:
    13. name: redis
    14. key: redis-password
    15. # uncomment below for connecting to redis cache instances over TLS (ex - Azure Redis Cache)
    16. # - name: enableTLS
    17. # value: true

    This example uses the kubernetes secret that was created when setting up a cluster with the above instructions.

    Other stores

    If using a state store other than Redis, refer to the supported state stores for information on what options to set.

    Create a file called redis-pubsub.yaml, and paste the following:

    This example uses the kubernetes secret that was created when setting up a cluster with the above instructions.

    Other stores

    If using a pub/sub message broker other than Redis, refer to the supported pub/sub message brokers for information on what options to set.

    For development purposes only you can skip creating kubernetes secrets and place passwords directly into the Dapr component file:

    1. apiVersion: dapr.io/v1alpha1
    2. kind: Component
    3. metadata:
    4. name: statestore
    5. namespace: default
    6. spec:
    7. version: v1
    8. metadata:
    9. - name: redisHost
    10. value: <HOST>
    11. - name: redisPassword
    12. value: <PASSWORD>
    13. # uncomment below for connecting to redis cache instances over TLS (ex - Azure Redis Cache)
    14. # - name: enableTLS
    1. apiVersion: dapr.io/v1alpha1
    2. kind: Component
    3. metadata:
    4. name: pubsub
    5. namespace: default
    6. spec:
    7. type: pubsub.redis
    8. version: v1
    9. metadata:
    10. - name: redisHost
    11. value: <HOST>
    12. - name: redisPassword
    13. value: <PASSWORD>
    14. # uncomment below for connecting to redis cache instances over TLS (ex - Azure Redis Cache)
    15. # - name: enableTLS
    16. # value: true

    By default the Dapr CLI creates a local Redis instance when you run dapr init. However, if you want to configure a different Redis instance you can either:

    • Update the existing component files or create new ones in the default components directory
      • Linux/MacOS: $HOME/.dapr/components
      • Windows: %USERPROFILE%\.dapr\components
    • Create a new components directory in your app folder containing the YAML files and provide the path to the dapr run command with the flag --components-path

    Self-hosted slim mode

    1. kubectl apply -f redis-pubsub.yaml