-
Notifications
You must be signed in to change notification settings - Fork 373
Add support for Bulk State, i.e. SaveBulkStateAsync(...) method #962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,6 +91,9 @@ bld/ | |
| # VS Code | ||
| .vscode/ | ||
|
|
||
| # Jetbrains | ||
| .idea/ | ||
|
|
||
| # coverlet code coverage results | ||
| coverage.json | ||
| .fake | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Dapr.Client; | ||
|
|
||
| namespace Samples.Client | ||
| { | ||
| public class BulkStateExample : Example | ||
| { | ||
| private static readonly string firstKey = "testKey1"; | ||
| private static readonly string secondKey = "testKey2"; | ||
| private static readonly string firstEtag = "123"; | ||
| private static readonly string secondEtag = "456"; | ||
| private static readonly string storeName = "statestore"; | ||
|
|
||
| public override string DisplayName => "Using the State Store"; | ||
|
|
||
| public override async Task RunAsync(CancellationToken cancellationToken) | ||
| { | ||
| using var client = new DaprClientBuilder().Build(); | ||
|
|
||
| var state1 = new Widget() { Size = "small", Color = "yellow", }; | ||
| var state2 = new Widget() { Size = "big", Color = "green", }; | ||
|
|
||
| var stateItem1 = new SaveStateItem<Widget>(firstKey, state1, firstEtag); | ||
| var stateItem2 = new SaveStateItem<Widget>(secondKey, state2, secondEtag); | ||
|
|
||
| await client.SaveBulkStateAsync(storeName, new List<SaveStateItem<Widget>>() { stateItem1, stateItem2}); | ||
|
|
||
| Console.WriteLine("Saved 2 States!"); | ||
|
|
||
| await Task.Delay(2000); | ||
|
|
||
| IReadOnlyList<BulkStateItem> states = await client.GetBulkStateAsync(storeName, | ||
| new List<string>(){firstKey, secondKey}, null); | ||
|
|
||
| Console.WriteLine($"Got {states.Count} States: "); | ||
|
|
||
| var deleteBulkStateItem1 = new BulkDeleteStateItem(states[0].Key, states[0].ETag); | ||
| var deleteBulkStateItem2 = new BulkDeleteStateItem(states[1].Key, states[1].ETag); | ||
|
|
||
| await client.DeleteBulkStateAsync(storeName, new List<BulkDeleteStateItem>() { deleteBulkStateItem1, deleteBulkStateItem2 }); | ||
|
|
||
| Console.WriteLine("Deleted States!"); | ||
| } | ||
|
|
||
| private class Widget | ||
| { | ||
| public string? Size { get; set; } | ||
| public string? Color { get; set; } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // ------------------------------------------------------------------------ | ||
| // Copyright 2021 The Dapr Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ------------------------------------------------------------------------ | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace Dapr.Client | ||
| { | ||
| /// <summary> | ||
| /// Represents a state object used for bulk delete state operation | ||
| /// </summary> | ||
| public readonly struct SaveStateItem<TValue> | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SaveStateItem{TValue}"/> class. | ||
| /// </summary> | ||
| /// <param name="key">The state key.</param> | ||
| /// <param name="value">The state value.</param> | ||
| /// <param name="etag">The ETag.</param> | ||
| /// <param name="stateOptions">The stateOptions.</param> | ||
| /// <param name="metadata">The metadata.</param> | ||
| public SaveStateItem(string key, TValue value, string etag, StateOptions stateOptions = default, IReadOnlyDictionary<string, string> metadata = default) | ||
| { | ||
| this.Key = key; | ||
| this.Value = value; | ||
| this.ETag = etag; | ||
| this.StateOptions = stateOptions; | ||
| this.Metadata = metadata; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the state key. | ||
| /// </summary> | ||
| public string Key { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the state value. | ||
| /// </summary> | ||
| public TValue Value { get; } | ||
|
|
||
| /// <summary> | ||
| /// Get the ETag. | ||
| /// </summary> | ||
| public string ETag { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the StateOptions. | ||
| /// </summary> | ||
| public StateOptions StateOptions { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the Metadata. | ||
| /// </summary> | ||
| public IReadOnlyDictionary<string, string> Metadata { get; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.