Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cb23720
Implement LastSave command
EdricCua Feb 5, 2025
8c31d56
Fix review comment
EdricCua Feb 5, 2025
108f875
Merge branch 'main' into Go-Implement-LastSave
Yury-Fridlyand Feb 7, 2025
3c8a874
Update from main
EdricCua Feb 10, 2025
167e176
Fix docs comment
EdricCua Feb 10, 2025
ede6c11
Merge branch 'main' into Go-Implement-LastSave
Yury-Fridlyand Feb 10, 2025
0b1f5d6
Implement LastSave
EdricCua Feb 13, 2025
b486213
Update from main
EdricCua Feb 13, 2025
ef98d2a
update from main
EdricCua Mar 12, 2025
728bbad
add example doc
EdricCua Mar 12, 2025
9523341
add example doc
EdricCua Mar 12, 2025
5292cc3
add example doc
EdricCua Mar 12, 2025
f3855b5
Updates from main
EdricCua Mar 18, 2025
e910dea
Fix review comment
EdricCua Mar 18, 2025
fd4521b
Fix review comment
EdricCua Mar 18, 2025
d414cf5
Fix review comment
EdricCua Mar 18, 2025
ee1d155
Fix review comment
EdricCua Mar 18, 2025
a3ec505
fix review comment
EdricCua Mar 18, 2025
cc4f266
fix example
EdricCua Mar 18, 2025
8799409
update from main
EdricCua Mar 18, 2025
e274dd7
fix examples
EdricCua Mar 19, 2025
c369184
fix examples
EdricCua Mar 19, 2025
919f231
fix examples
EdricCua Mar 19, 2025
8bcf3e9
fix examples
EdricCua Mar 19, 2025
bbf62b4
fix examples
EdricCua Mar 19, 2025
2f5f5c2
update from main
EdricCua Mar 20, 2025
3f5d8d7
update from main
EdricCua Mar 20, 2025
a4b7c44
Merge branch 'main' into Go-Implement-LastSave
Yury-Fridlyand Mar 20, 2025
137808f
update from main
EdricCua Mar 20, 2025
80baefe
update from main
EdricCua Mar 24, 2025
79330d8
update from main
EdricCua Mar 24, 2025
a0246e5
update from main
EdricCua Mar 26, 2025
42a9eeb
update from main
EdricCua Mar 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Go: Add `GeoPos` ([#3409](https://github.com/valkey-io/valkey-glide/pull/3409))
* Go: Add `GeoDist` ([#3446](https://github.com/valkey-io/valkey-glide/pull/3446))
* Go: Add `ClientId` ([#3077](https://github.com/valkey-io/valkey-glide/pull/3077))
* Go: Add `LastSave` ([#3086](https://github.com/valkey-io/valkey-glide/pull/3086))

#### Breaking Changes

Expand Down
15 changes: 15 additions & 0 deletions go/api/glide_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,18 @@ func (client *GlideClient) ClientId() (int64, error) {
}
return handleIntResponse(result)
}

// Returns UNIX TIME of the last DB save timestamp or startup timestamp if no save was made since then.
//
// Return value:
//
// UNIX TIME of the last DB save executed with success.
//
// [valkey.io]: https://valkey.io/commands/lastsave/
func (client *GlideClient) LastSave() (int64, error) {
response, err := client.executeCommand(C.LastSave, []string{})
if err != nil {
return defaultIntResponse, err
}
return handleIntResponse(response)
}
52 changes: 52 additions & 0 deletions go/api/glide_cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,55 @@ func (client *GlideClusterClient) ClientIdWithOptions(opts options.RouteOption)
}
return createClusterSingleValue[int64](data), nil
}

// Returns UNIX TIME of the last DB save timestamp or startup timestamp if no save was made since then.
// The command is routed to a random node by default, which is safe for read-only commands.
//
// Return value:
//
// UNIX TIME of the last DB save executed with success.
//
// [valkey.io]: https://valkey.io/commands/lastsave/
func (client *GlideClusterClient) LastSave() (ClusterValue[int64], error) {
response, err := client.executeCommand(C.LastSave, []string{})
if err != nil {
return createEmptyClusterValue[int64](), err
}
data, err := handleIntResponse(response)
if err != nil {
return createEmptyClusterValue[int64](), err
}
return createClusterSingleValue[int64](data), nil
}

// Returns UNIX TIME of the last DB save timestamp or startup timestamp if no save was made since then.
//
// Parameters:
//
// route - Specifies the routing configuration for the command. The client will route the
// command to the nodes defined by route.
//
// Return value:
//
// UNIX TIME of the last DB save executed with success.
//
// [valkey.io]: https://valkey.io/commands/lastsave/
func (client *GlideClusterClient) LastSaveWithOptions(opts options.RouteOption) (ClusterValue[int64], error) {
response, err := client.executeCommandWithRoute(C.LastSave, []string{}, opts.Route)
if err != nil {
return createEmptyClusterValue[int64](), err
}
if opts.Route != nil &&
(opts.Route).IsMultiNode() {
data, err := handleStringIntMapResponse(response)
if err != nil {
return createEmptyClusterValue[int64](), err
}
return createClusterMultiValue[int64](data), nil
}
data, err := handleIntResponse(response)
if err != nil {
return createEmptyClusterValue[int64](), err
}
return createClusterSingleValue[int64](data), nil
}
4 changes: 4 additions & 0 deletions go/api/server_management_cluster_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ type ServerManagementClusterCommands interface {
Lolwut() (string, error)

LolwutWithOptions(lolwutOptions options.ClusterLolwutOptions) (ClusterValue[string], error)

LastSave() (ClusterValue[int64], error)

LastSaveWithOptions(routeOption options.RouteOption) (ClusterValue[int64], error)
}
28 changes: 28 additions & 0 deletions go/api/server_management_cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"

"github.com/google/uuid"
"github.com/valkey-io/valkey-glide/go/api/config"
"github.com/valkey-io/valkey-glide/go/api/options"
)
Expand Down Expand Up @@ -190,3 +191,30 @@ func ExampleGlideClusterClient_LolwutWithOptions() {
}
// Output: LOLWUT pattern generated successfully
}

func ExampleGlideClusterClient_LastSave() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
key := "key-" + uuid.NewString()
client.Set(key, "hello")
result, err := client.LastSave()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result.IsSingleValue())

// Output: true
}

func ExampleGlideClusterClient_LastSaveWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
opts := options.RouteOption{Route: nil}
key := "key-" + uuid.NewString()
client.Set(key, "hello")
result, err := client.LastSaveWithOptions(opts)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result.IsSingleValue())

// Output: true
}
2 changes: 2 additions & 0 deletions go/api/server_management_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ type ServerManagementCommands interface {
Lolwut() (string, error)

LolwutWithOptions(opts options.LolwutOptions) (string, error)

LastSave() (int64, error)
}
14 changes: 14 additions & 0 deletions go/api/server_management_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"time"

"github.com/google/uuid"
"github.com/valkey-io/valkey-glide/go/api/options"
)

Expand Down Expand Up @@ -200,3 +201,16 @@ func ExampleGlideClient_LolwutWithOptions() {
// LOLWUT version result is of type string
// LOLWUT version with args result is of type string
}

func ExampleGlideClient_LastSave() {
var client *GlideClient = getExampleGlideClient() // example helper function
key := "key-" + uuid.NewString()
client.Set(key, "hello")
response, err := client.LastSave()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(response > 0)

// Output: true
}
17 changes: 17 additions & 0 deletions go/integTest/cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,3 +1196,20 @@ func (suite *GlideTestSuite) TestClientIdWithOptionsCluster() {
assert.NoError(t, err)
assert.True(t, response.IsMultiValue())
}

func (suite *GlideTestSuite) TestLastSaveCluster() {
client := suite.defaultClusterClient()
t := suite.T()
response, err := client.LastSave()
assert.NoError(t, err)
assert.True(t, response.IsSingleValue())
}

func (suite *GlideTestSuite) TestLastSaveWithOptionCluster() {
client := suite.defaultClusterClient()
t := suite.T()
opts := options.RouteOption{Route: nil}
response, err := client.LastSaveWithOptions(opts)
assert.NoError(t, err)
assert.True(t, response.IsSingleValue())
}
8 changes: 8 additions & 0 deletions go/integTest/standalone_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,3 +820,11 @@ func (suite *GlideTestSuite) TestClientId() {
assert.Nil(suite.T(), err)
assert.Greater(suite.T(), result, int64(0))
}

func (suite *GlideTestSuite) TestLastSave() {
client := suite.defaultClient()
t := suite.T()
result, err := client.LastSave()
assert.Nil(t, err)
assert.Greater(t, result, int64(0))
}
Loading