Skip to content

Commit

Permalink
Merge pull request #3238 from hhunter-ms/issue_3119
Browse files Browse the repository at this point in the history
Add .NET, Go, Java state store TTL examples
  • Loading branch information
hhunter-ms committed Mar 17, 2023
2 parents a08d67e + 9ba3c29 commit ed26d86
Showing 1 changed file with 56 additions and 1 deletion.
Expand Up @@ -28,10 +28,12 @@ Refer to the TTL column in the [state store components guide]({{< ref supported-

You can set state TTL in the metadata as part of the state store set request:

{{< tabs Python "HTTP API (Bash)" "HTTP API (PowerShell)">}}
{{< tabs ".NET" Python Go "HTTP API (Bash)" "HTTP API (PowerShell)">}}

{{% codetab %}}

<!--python-->

```python
#dependencies

Expand All @@ -58,6 +60,59 @@ dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-g

{{% codetab %}}

<!--dotnet-->

```csharp
// dependencies
using Dapr.Client;

// code
await client.SaveStateAsync(storeName, stateKeyName, state, metadata: new Dictionary<string, string>() {
{
"metadata.ttlInSeconds", "120"
}
});
```

To launch a Dapr sidecar and run the above example application, you'd then run a command similar to the following:

```bash
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 dotnet run
```

{{% /codetab %}}

{{% codetab %}}

<!--go-->

```go
// dependencies

import (
dapr "github.com/dapr/go-sdk/client"
)

// code

md := map[string]string{"ttlInSeconds": "120"}
if err := client.SaveState(ctx, store, "key1", []byte("hello world"), md); err != nil {
panic(err)
}
```

To launch a Dapr sidecar and run the above example application, you'd then run a command similar to the following:

```bash
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 go run .
```

{{% /codetab %}}

{{% codetab %}}

```bash
curl -X POST -H "Content-Type: application/json" -d '[{ "key": "order_1", "value": "250", "metadata": { "ttlInSeconds": "120" } }]' http://localhost:3601/v1.0/state/statestore
```
Expand Down

0 comments on commit ed26d86

Please sign in to comment.