-
Notifications
You must be signed in to change notification settings - Fork 71
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
Go: Implement FlushAll, FlushDB commands #3117
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,3 +302,99 @@ func (client *GlideClient) PingWithOptions(pingOptions options.PingOptions) (str | |
} | ||
return handleStringResponse(result) | ||
} | ||
|
||
// FlushAll deletes all the keys of all the existing databases. | ||
// | ||
// See [valkey.io] for details. | ||
// | ||
// Return value: | ||
// | ||
// `"OK"` response on success. | ||
// | ||
// Example: | ||
// | ||
// res, err := client.FlushAll() | ||
// fmt.Println(res) // OK | ||
// | ||
// [valkey.io]: https://valkey.io/commands/flushall/ | ||
func (client *GlideClient) FlushAll() (string, error) { | ||
result, err := client.executeCommand(C.FlushAll, []string{}) | ||
if err != nil { | ||
return defaultStringResponse, err | ||
} | ||
return handleStringResponse(result) | ||
} | ||
|
||
// Deletes all the keys of all the existing databases. | ||
// | ||
// See [valkey.io] for details. | ||
// | ||
// Parameters: | ||
// | ||
// mode - The flushing mode, could be either [options.SYNC] or [options.ASYNC}. | ||
// | ||
// Return value: | ||
// | ||
// `"OK"` response on success. | ||
// | ||
// Example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Examples should not exist in the document block and instead should be placed in the relevant test file. See the Go Developer Guide for Valkey-Glide. |
||
// | ||
// res, err := client.FlushAllWithOptions(options.SYNC) | ||
// fmt.Println(res) // OK | ||
// | ||
// [valkey.io]: https://valkey.io/commands/flushall/ | ||
func (client *GlideClient) FlushAllWithOptions(mode options.FlushMode) (string, error) { | ||
result, err := client.executeCommand(C.FlushAll, []string{string(mode)}) | ||
if err != nil { | ||
return defaultStringResponse, err | ||
} | ||
return handleStringResponse(result) | ||
} | ||
|
||
// Deletes all the keys of the currently selected database. | ||
// | ||
// See [valkey.io] for details. | ||
// | ||
// Return value: | ||
// | ||
// `"OK"` response on success. | ||
// | ||
// Example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Examples should not exist in the document block and instead should be placed in the relevant test file. See the Go Developer Guide for Valkey-Glide. |
||
// | ||
// res, err := client.FlushDB() | ||
// fmt.Println(res) // OK | ||
// | ||
// [valkey.io]: https://valkey.io/commands/flushdb/ | ||
func (client *GlideClient) FlushDB() (string, error) { | ||
result, err := client.executeCommand(C.FlushDB, []string{}) | ||
if err != nil { | ||
return defaultStringResponse, err | ||
} | ||
return handleStringResponse(result) | ||
} | ||
|
||
// Deletes all the keys of the currently selected database. | ||
// | ||
// See [valkey.io] for details. | ||
// | ||
// Parameters: | ||
// | ||
// mode - The flushing mode, could be either [options.SYNC] or [options.ASYNC}. | ||
// | ||
// Return value: | ||
// | ||
// `"OK"` response on success. | ||
// | ||
// Example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Examples should not exist in the document block and instead should be placed in the relevant test file. See the Go Developer Guide for Valkey-Glide. |
||
// | ||
// res, err := client.FlushDBWithOptions(options.SYNC) | ||
// fmt.Println(res) // OK | ||
// | ||
// [valkey.io]: https://valkey.io/commands/flushdb/ | ||
func (client *GlideClient) FlushDBWithOptions(mode options.FlushMode) (string, error) { | ||
result, err := client.executeCommand(C.FlushDB, []string{string(mode)}) | ||
if err != nil { | ||
return defaultStringResponse, err | ||
} | ||
return handleStringResponse(result) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,6 +330,62 @@ func (client *GlideClusterClient) DBSizeWithOptions(opts options.RouteOption) (i | |
return handleIntResponse(result) | ||
} | ||
|
||
// Deletes all the keys of all the existing databases. | ||
// | ||
// See [valkey.io] for details. | ||
// | ||
// Parameters: | ||
// | ||
// mode - The flushing mode, could be either [options.SYNC] or [options.ASYNC}. | ||
// routeOption - The RouteOption type. | ||
// | ||
// Return value: | ||
// | ||
// `"OK"` response on success. | ||
// | ||
// Example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Examples should not exist in the document block and instead should be placed in the relevant test file. See the Go Developer Guide for Valkey-Glide. |
||
// | ||
// route := options.RouteOption{Route: config.AllPrimaries} | ||
// res, err := client.FlushAllWithOptions(options.SYNC, route) | ||
// fmt.Println(res) // OK | ||
// | ||
// [valkey.io]: https://valkey.io/commands/flushall/ | ||
func (client *GlideClusterClient) FlushAllWithOptions(mode options.FlushMode, opts options.RouteOption) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can create type FlushClusterOptions struct {
*FlushMode
*RouteOption
} In client API check for |
||
result, err := client.executeCommandWithRoute(C.FlushAll, []string{string(mode)}, opts.Route) | ||
if err != nil { | ||
return defaultStringResponse, err | ||
} | ||
return handleStringResponse(result) | ||
} | ||
|
||
// Deletes all the keys of the currently selected database. | ||
// | ||
// See [valkey.io] for details. | ||
// | ||
// Parameters: | ||
// | ||
// mode - The flushing mode, could be either [options.SYNC] or [options.ASYNC}. | ||
// routeOption - The RouteOption type. | ||
// | ||
// Return value: | ||
// | ||
// `"OK"` response on success. | ||
// | ||
// Example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Examples should not exist in the document block and instead should be placed in the relevant test file. See the Go Developer Guide for Valkey-Glide. |
||
// | ||
// route := options.RouteOption{Route: config.AllPrimaries} | ||
// res, err := client.FlushDBWithOptions(options.SYNC, route) | ||
// fmt.Println(res) // OK | ||
// | ||
// [valkey.io]: https://valkey.io/commands/flushdb/ | ||
func (client *GlideClusterClient) FlushDBWithOptions(mode options.FlushMode, opts options.RouteOption) (string, error) { | ||
result, err := client.executeCommandWithRoute(C.FlushDB, []string{string(mode)}, opts.Route) | ||
if err != nil { | ||
return defaultStringResponse, err | ||
} | ||
return handleStringResponse(result) | ||
} | ||
|
||
// Echo the provided message back. | ||
// The command will be routed a random node, unless `Route` in `echoOptions` is provided. | ||
// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
||
package options | ||
|
||
// FlushMode represents the database flush operation mode | ||
type FlushMode string | ||
|
||
const ( | ||
// SYNC flushes synchronously. | ||
// Since Valkey 6.2 and above. | ||
SYNC FlushMode = "SYNC" | ||
|
||
// ASYNC flushes asynchronously. | ||
ASYNC FlushMode = "ASYNC" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples should not exist in the document block and instead should be placed in the relevant test file. See the Go Developer Guide for Valkey-Glide.