Add distributed lock api reference (#2596)

* add distributed lock api reference

Signed-off-by: yaron2 <schneider.yaron@live.com>

* Update daprdocs/content/en/reference/api/distributed_lock_api.md

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* add info

Signed-off-by: yaron2 <schneider.yaron@live.com>

* add info

Signed-off-by: yaron2 <schneider.yaron@live.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>
This commit is contained in:
Yaron Schneider 2022-07-05 13:15:59 -07:00 committed by GitHub
parent f11a20fc14
commit 09b7e18dc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 156 additions and 0 deletions

View File

@ -0,0 +1,156 @@
---
type: docs
title: "Distributed Lock API reference"
linkTitle: "Distributed Lock API"
description: "Detailed documentation on the distributed lock API"
weight: 660
---
## Lock
This endpoint lets you acquire a lock by supplying a named lock owner and the resource ID to lock.
### HTTP Request
```
POST http://localhost:<daprPort>/v1.0-alpha1/lock/<storename>
```
#### URL Parameters
Parameter | Description
--------- | -----------
`daprPort` | The Dapr port
`storename` | The `metadata.name` field component file. Refer to the [component schema] ({{< ref component-schema.md>}})
#### Query Parameters
None
### HTTP Response codes
Code | Description
---- | -----------
200 | Request successful
204 | Empty Response
400 | Malformed request
500 | Request failed
### HTTP Request Body
The lock endpoint receives the following JSON payload:
```json
{
"resourceId": "",
"lockOwner": "",
"expiryInSeconds": 0
}
```
Field | Description
---- | -----------
resourceId | The ID of the resource to lock. Can be any value
lockOwner | The name of the lock owner. Should be set to a unique value per-request
expiryInSeconds | The time in seconds to hold the lock before it expires
### HTTP Response Body
The lock endpoint returns the following payload:
```json
{
"success": true
}
```
### Examples
```shell
curl -X POST http://localhost:3500/v1.0-alpha/lock/redisStore \
-H "Content-Type: application/json" \
-d '{
"resourceId": "lock1",
"lockOwner": "vader",
"expiryInSeconds": 60
}'
{
"success": "true"
}
```
## Unlock
This endpoint lets you unlock an existing lock based on the lock owner and resource Id
### HTTP Request
```
POST http://localhost:<daprPort>/v1.0-alpha1/unlock/<storename>
```
#### URL Parameters
Parameter | Description
--------- | -----------
`daprPort` | The Dapr port
`storename` | The `metadata.name` field component file. Refer to the [component schema] ({{< ref component-schema.md>}})
#### Query Parameters
None
### HTTP Response codes
Code | Description
---- | -----------
200 | Request successful
204 | Empty Response
400 | Malformed request
500 | Request failed
### HTTP Request Body
The unlock endpoint receives the following JSON payload:
```json
{
"resourceId": "",
"lockOwner": ""
}
```
### HTTP Response Body
The unlock endpoint returns the following payload:
```json
{
"status": 0
}
```
The `status` field contains the following response codes:
Code | Description
---- | -----------
0 | Success
1 | Lock doesn't exist
2 | Lock belongs to another owner
3 | Internal error
### Examples
```shell
curl -X POST http://localhost:3500/v1.0-alpha/unlock/redisStore \
-H "Content-Type: application/json" \
-d '{
"resourceId": "lock1",
"lockOwner": "vader"
}'
{
"status": 0
}
```