-
Notifications
You must be signed in to change notification settings - Fork 90
Go: Batch #3938
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
Go: Batch #3938
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7000503
BAAAAAAAAAAAAAAAAAAAAAATCH
Yury-Fridlyand 166ee3e
linter + remove dbg
Yury-Fridlyand 8cb2d8c
oops
Yury-Fridlyand 19443b1
oops
Yury-Fridlyand 2cf9ed1
Merge remote-tracking branch 'upstream/main' into go/yuryf-transaction
Yury-Fridlyand 5bc73e9
fixes and tests.
Yury-Fridlyand 026abf5
more tests
Yury-Fridlyand b60a207
fixes
Yury-Fridlyand 5c117cf
Apply suggestions from code review
Yury-Fridlyand 6b28f35
more tests
Yury-Fridlyand 74e92d3
docs
Yury-Fridlyand 14cc399
Examples
Yury-Fridlyand 84864ff
Merge branch 'main' into go/yuryf-transaction
Yury-Fridlyand b53daeb
Update go/base_client.go
Yury-Fridlyand d1d47ac
linter
Yury-Fridlyand 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,158 @@ | ||
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
||
package glide | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/valkey-io/valkey-glide/go/v2/config" | ||
"github.com/valkey-io/valkey-glide/go/v2/pipeline" | ||
) | ||
|
||
// TODO replace CustomCommand | ||
|
||
func ExampleClient_Exec_transaction() { | ||
var client *Client = getExampleClient() // example helper function | ||
// Example 1: Atomic Batch (Transaction) | ||
batch := pipeline.NewStandaloneBatch(true) | ||
batch.Set("key", "1").CustomCommand([]string{"incr", "key"}).Get("key") | ||
|
||
result, err := client.Exec(context.Background(), *batch, true) | ||
if err != nil { | ||
fmt.Println("Glide example failed with an error: ", err) | ||
} | ||
fmt.Println(result) | ||
|
||
// Output: [OK 2 2] | ||
} | ||
|
||
func ExampleClient_Exec_pipeline() { | ||
var client *Client = getExampleClient() // example helper function | ||
// Example 2: Non-Atomic Batch (Pipeline) | ||
batch := pipeline.NewStandaloneBatch(false) | ||
batch.Set("key1", "value1").Set("key2", "value2").Get("key1").Get("key2") | ||
|
||
result, err := client.Exec(context.Background(), *batch, true) | ||
if err != nil { | ||
fmt.Println("Glide example failed with an error: ", err) | ||
} | ||
fmt.Println(result) | ||
|
||
// Output: [OK OK value1 value2] | ||
} | ||
|
||
func ExampleClient_ExecWithOptions_transaction() { | ||
var client *Client = getExampleClient() // example helper function | ||
// Example 1: Atomic Batch (Transaction) | ||
batch := pipeline.NewStandaloneBatch(true) | ||
batch.Set("key", "1").CustomCommand([]string{"incr", "key"}).Get("key") | ||
// Set a timeout of 1000 milliseconds | ||
options := pipeline.NewStandaloneBatchOptions().WithTimeout(1000) | ||
|
||
result, err := client.ExecWithOptions(context.Background(), *batch, false, *options) | ||
if err != nil { | ||
fmt.Println("Glide example failed with an error: ", err) | ||
} | ||
fmt.Println(result) | ||
|
||
// Output: [OK 2 2] | ||
} | ||
|
||
func ExampleClient_ExecWithOptions_pipeline() { | ||
var client *Client = getExampleClient() // example helper function | ||
// Example 2: Non-Atomic Batch (Pipeline) | ||
batch := pipeline.NewStandaloneBatch(false) | ||
batch.Set("key1", "value1").Set("key2", "value2").Get("key1").Get("key2") | ||
// Set a timeout of 1000 milliseconds | ||
options := pipeline.NewStandaloneBatchOptions().WithTimeout(1000) | ||
|
||
result, err := client.ExecWithOptions(context.Background(), *batch, false, *options) | ||
if err != nil { | ||
fmt.Println("Glide example failed with an error: ", err) | ||
} | ||
fmt.Println(result) | ||
|
||
// Output: [OK OK value1 value2] | ||
} | ||
|
||
func ExampleClusterClient_Exec_transaction() { | ||
var client *ClusterClient = getExampleClusterClient() // example helper function | ||
// Example 1: Atomic Batch (Transaction) | ||
batch := pipeline.NewClusterBatch(true) | ||
batch.Set("key", "1").CustomCommand([]string{"incr", "key"}).Get("key") | ||
|
||
result, err := client.Exec(context.Background(), *batch, false) | ||
if err != nil { | ||
fmt.Println("Glide example failed with an error: ", err) | ||
} | ||
fmt.Println(result) | ||
|
||
// Output: [OK 2 2] | ||
} | ||
|
||
func ExampleClusterClient_Exec_pipeline() { | ||
var client *ClusterClient = getExampleClusterClient() // example helper function | ||
// Example 2: Non-Atomic Batch (Pipeline) | ||
batch := pipeline.NewClusterBatch(false) | ||
batch.Set("key1", "value1").Set("key2", "value2").Get("key1").Get("key2") | ||
|
||
result, err := client.Exec(context.Background(), *batch, false) | ||
if err != nil { | ||
fmt.Println("Glide example failed with an error: ", err) | ||
} | ||
fmt.Println(result) | ||
|
||
// Output: [OK OK value1 value2] | ||
} | ||
|
||
func ExampleClusterClient_ExecWithOptions_transaction() { | ||
var client *ClusterClient = getExampleClusterClient() // example helper function | ||
// Example 1: Atomic Batch (Transaction) | ||
batch := pipeline.NewClusterBatch(true) | ||
batch.Set("key", "1").CustomCommand([]string{"incr", "key"}).Get("key") | ||
// Set a timeout of 1000 milliseconds | ||
options := pipeline.NewClusterBatchOptions().WithTimeout(1000) | ||
|
||
result, err := client.ExecWithOptions(context.Background(), *batch, false, *options) | ||
if err != nil { | ||
fmt.Println("Glide example failed with an error: ", err) | ||
} | ||
fmt.Println(result) | ||
|
||
// Output: [OK 2 2] | ||
} | ||
|
||
func ExampleClusterClient_ExecWithOptions_pipeline() { | ||
var client *ClusterClient = getExampleClusterClient() // example helper function | ||
// Example 2: Non-Atomic Batch (Pipeline) | ||
batch := pipeline.NewClusterBatch(false) | ||
batch.Set("key1", "value1").Set("key2", "value2").Get("key1").Get("key2") | ||
// Set command retry parameters | ||
retryStrategy := pipeline.NewClusterBatchRetryStrategy().WithRetryServerError(true).WithRetryConnectionError(true) | ||
options := pipeline.NewClusterBatchOptions().WithRetryStrategy(*retryStrategy) | ||
|
||
result, err := client.ExecWithOptions(context.Background(), *batch, false, *options) | ||
if err != nil { | ||
fmt.Println("Glide example failed with an error: ", err) | ||
} | ||
fmt.Println(result) | ||
|
||
// Output: [OK OK value1 value2] | ||
} | ||
|
||
func ExampleClusterClient_ExecWithOptions_route() { | ||
var client *ClusterClient = getExampleClusterClient() // example helper function | ||
// Example 2: Non-Atomic Batch (Pipeline) | ||
batch := pipeline.NewClusterBatch(true) | ||
batch.CustomCommand([]string{"info", "server"}) | ||
// Set batch route | ||
route := config.NewSlotKeyRoute(config.SlotTypePrimary, "abc") | ||
options := pipeline.NewClusterBatchOptions().WithRoute(route) | ||
|
||
_, err := client.ExecWithOptions(context.Background(), *batch, false, *options) | ||
if err != nil { | ||
fmt.Println("Glide example failed with an error: ", err) | ||
} | ||
// Output: | ||
} |
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.