Add namespace state strategy (#2474)

* Add namespace state strategy

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

* Update daprdocs/content/en/developing-applications/building-blocks/state-management/howto-share-state.md

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

Co-authored-by: Mark Fussell <markfussell@gmail.com>
This commit is contained in:
Yaron Schneider 2022-05-31 21:29:04 -07:00 committed by GitHub
parent bf906df360
commit 11b02ca9aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 0 deletions

View File

@ -16,6 +16,8 @@ To enable state sharing, Dapr supports the following key prefixes strategies:
* **`appid`** - This is the default strategy. the `appid` prefix allows state to be managed only by the app with the specified `appid`. All state keys will be prefixed with the `appid`, and are scoped for the application.
* **`namespace`** - If set, this setting prefixes the `appid` key with the configured namespace, resulting in a key that is scoped to a given namespace. This allows apps in different namespace with the same `appid` to reuse the same state store. If a namespace is not configured, the setting fallbacks to the `appid` strategy. For more information on namespaces in Dapr see [How-To: Scope components to one or more applications]({{< ref component-scopes.md >}})
* **`name`** - This setting uses the name of the state store component as the prefix. Multiple applications can share the same state for a given state store.
* **`none`** - This setting uses no prefixing. Multiple applications share state across different state stores.
@ -59,6 +61,23 @@ curl -X POST http://localhost:3500/v1.0/state/redis \
The key will be saved as `myApp||darth`.
### `namespace`
A Dapr application running in namespace `production` with app id `myApp` is saving state into a state store named `redis`:
```shell
curl -X POST http://localhost:3500/v1.0/state/redis \
-H "Content-Type: application/json"
-d '[
{
"key": "darth",
"value": "nihilus"
}
]'
```
The key will be saved as `production.myApp||darth`.
### `name`
A Dapr application with app id `myApp` is saving state into a state store named `redis`: