docs/daprdocs/content/en/developing-applications/building-blocks/distributed-lock/howto-use-distributed-lock.md

1.6 KiB

type title linkTitle weight description
docs How-To: Use a lock How-To: Use a lock 2000 Learn how to use distributed locks to provide exclusive access to a resource

Now that you've learned what the Dapr distributed lock API building block provides, learn how it can work in your service. The example below describes an application that aquires a lock. This example uses the Redis lock component to demonstrate how to lock resources.

Diagram showing aquiring a lock from multiple instances of same application Diagram showing releasing a lock from multiple instances of same application Diagram showing aquiring multiple locks from different applications

Configure a lock component

Save the following component file to the [default components folder]({{< ref "install-dapr-selfhost.md#step-5-verify-components-directory-has-been-initialized" >}}) on your machine.

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: lock
spec:
  type: lock.redis
  metadata:
  - name: redisHost
    value: localhost:6379
  - name: redisPassword
    value: <PASSWORD>

Get configuration items using Dapr SDKs

{{< tabs Dotnet Java Python>}}

{{% codetab %}}


{{% /codetab %}}

{{% codetab %}}


{{% /codetab %}}

{{% codetab %}}


{{% /codetab %}}

{{< /tabs >}}

Next steps

  • Read [distributed lock API overview]({{< ref distributed-lock-api-overview.md >}})