-
Notifications
You must be signed in to change notification settings - Fork 3
Transaction commands #137
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
Transaction commands #137
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e985b61
Transaction commands
alexr-bq bc7778d
Cleanup
alexr-bq 725f904
Merge branch 'main' into alexr/transactioncommands
alexr-bq 17004c8
Format
alexr-bq 25bf937
Resolve PR feedback
alexr-bq 190be96
Resolve PR feedback
alexr-bq 1af7e80
Fix
alexr-bq 7c92fbe
Fix lint
alexr-bq 75183aa
Format'
alexr-bq 69cd669
Format'
alexr-bq 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
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,53 @@ | ||
| // Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
|
||
| namespace Valkey.Glide.Commands; | ||
|
|
||
| /// <summary> | ||
| /// Supports commands for the "Transaction Commands" group for standalone and cluster clients. | ||
| /// <br /> | ||
| /// See more on <see href="https://valkey.io/commands/?group=transactions">valkey.io</see>. | ||
| /// </summary> | ||
| public interface ITransactionBaseCommands | ||
| { | ||
| /// <summary> | ||
| /// Marks the given keys to be watched for conditional execution of a transaction. Transactions | ||
| /// will only execute commands if the watched keys are not modified before execution of the | ||
| /// transaction. | ||
| /// </summary> | ||
| /// <param name="keys">The keys to watch.</param> | ||
| /// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param> | ||
| /// <returns>"OK" if the keys were successfully watched.</returns> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// In cluster mode, if keys in <paramref name="keys"/> map to different hash slots, the command | ||
| /// will be split across these slots and executed separately for each. This means the command | ||
| /// is atomic only at the slot level. If one or more slot-specific requests fail, the entire | ||
| /// call will return the first encountered error, even though some requests may have succeeded | ||
| /// while others did not. If this behavior impacts your application logic, consider splitting | ||
| /// the request into sub-requests per slot to ensure atomicity. | ||
| /// </para> | ||
| /// <example> | ||
| /// <code> | ||
| /// bool result = await client.WatchAsync(["sampleKey"]); | ||
| /// // result is "OK" | ||
| /// | ||
| /// // Execute transaction | ||
| /// var batch = new Batch(true) | ||
| /// .StringSetAsync("sampleKey", "foobar"); | ||
| /// object[] transactionResult = await client.Exec(batch, false); | ||
| /// // transactionResult is not null if transaction executed successfully | ||
| /// | ||
| /// // Watch key again | ||
| /// await client.WatchAsync(["sampleKey"]); | ||
| /// var batch2 = new Batch(true) | ||
| /// .StringSetAsync("sampleKey", "foobar"); | ||
| /// // Modify the watched key from another client/connection | ||
| /// await client.StringSetAsync("sampleKey", "hello world"); | ||
| /// object[] transactionResult2 = await client.Exec(batch2, true); | ||
| /// // transactionResult2 is null because the watched key was modified | ||
| /// </code> | ||
| /// </example> | ||
| /// </remarks> | ||
| /// <seealso href="https://valkey.io/commands/watch/"/> | ||
| Task<string> WatchAsync(ValkeyKey[] keys, CommandFlags flags = CommandFlags.None); | ||
alexr-bq marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
46 changes: 46 additions & 0 deletions
46
sources/Valkey.Glide/Commands/ITransactionClusterCommands.cs
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,46 @@ | ||
| // Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
|
||
| namespace Valkey.Glide.Commands; | ||
|
|
||
| /// <summary> | ||
| /// Supports commands for the "Transaction Commands" group for cluster clients. | ||
| /// <br /> | ||
| /// See more on <see href="https://valkey.io/commands/?group=transactions">valkey.io</see>. | ||
| /// </summary> | ||
| public interface ITransactionClusterCommands : ITransactionBaseCommands | ||
| { | ||
| /// <summary> | ||
| /// Flushes all the previously watched keys for a transaction. Executing a transaction will | ||
| /// automatically flush all previously watched keys. | ||
| /// The command will be routed to all primary nodes. | ||
| /// </summary> | ||
| /// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param> | ||
| /// <returns>"OK" if the keys were successfully unwatched.</returns> | ||
| /// <example> | ||
| /// <code> | ||
| /// await client.WatchAsync(["sampleKey"]); | ||
| /// string result = await client.UnwatchAsync(); | ||
| /// // result is "OK", "sampleKey" is no longer watched on all primary nodes | ||
| /// </code> | ||
| /// </example> | ||
| /// <seealso href="https://valkey.io/commands/unwatch/"/> | ||
| Task<string> UnwatchAsync(CommandFlags flags = CommandFlags.None); | ||
|
|
||
| /// <summary> | ||
| /// Flushes all the previously watched keys for a transaction. Executing a transaction will | ||
| /// automatically flush all previously watched keys. | ||
| /// </summary> | ||
| /// <param name="route">Specifies the routing configuration for the command. The client will route the | ||
| /// command to the nodes defined by <paramref name="route"/>.</param> | ||
| /// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param> | ||
| /// <returns>"OK" if the keys were successfully unwatched.</returns> | ||
| /// <example> | ||
| /// <code> | ||
| /// await client.WatchAsync(["sampleKey"]); | ||
| /// string result = await client.UnwatchAsync(Route.AllPrimaries); | ||
| /// // result is "OK", "sampleKey" is no longer watched on all primary nodes | ||
| /// </code> | ||
| /// </example> | ||
| /// <seealso href="https://valkey.io/commands/unwatch/"/> | ||
| Task<string> UnwatchAsync(Route route, CommandFlags flags = CommandFlags.None); | ||
| } |
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,27 @@ | ||
| // Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
|
||
| namespace Valkey.Glide.Commands; | ||
|
|
||
| /// <summary> | ||
| /// Supports commands for the "Transaction Commands" group for standalone clients. | ||
| /// <br /> | ||
| /// See more on <see href="https://valkey.io/commands/?group=transactions">valkey.io</see>. | ||
| /// </summary> | ||
| public interface ITransactionCommands : ITransactionBaseCommands | ||
| { | ||
| /// <summary> | ||
| /// Flushes all the previously watched keys for a transaction. Executing a transaction will | ||
| /// automatically flush all previously watched keys. | ||
| /// </summary> | ||
| /// <param name="flags">The flags to use for this operation. Currently flags are ignored.</param> | ||
| /// <returns>"OK" if the keys were successfully unwatched.</returns> | ||
| /// <example> | ||
| /// <code> | ||
| /// await client.WatchAsync(["sampleKey"]); | ||
| /// bool result = await client.UnwatchAsync(); | ||
| /// // result is "OK", "sampleKey" is no longer watched | ||
alexr-bq marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// </code> | ||
| /// </example> | ||
| /// <seealso href="https://valkey.io/commands/unwatch/"/> | ||
| Task<string> UnwatchAsync(CommandFlags flags = CommandFlags.None); | ||
| } | ||
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
26 changes: 26 additions & 0 deletions
26
sources/Valkey.Glide/Internals/Request.TransactionCommands.cs
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,26 @@ | ||
| // Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
|
||
| using static Valkey.Glide.Internals.FFI; | ||
|
|
||
| namespace Valkey.Glide.Internals; | ||
|
|
||
| internal partial class Request | ||
| { | ||
| /// <summary> | ||
| /// Creates a command to watch keys for conditional execution of a transaction. | ||
| /// </summary> | ||
| /// <param name="keys">The keys to watch.</param> | ||
| /// <returns>A command that watches the specified keys.</returns> | ||
| public static Cmd<string, string> Watch(ValkeyKey[] keys) | ||
| { | ||
| GlideString[] args = [.. keys.Select(k => (GlideString)k)]; | ||
| return new(RequestType.Watch, args, false, response => response); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a command to flush all previously watched keys for a transaction. | ||
| /// </summary> | ||
| /// <returns>A command that unwatches all previously watched keys.</returns> | ||
| public static Cmd<string, string> Unwatch() | ||
| => new(RequestType.UnWatch, [], false, response => response); | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.