Skip to content

Commit

Permalink
Fix merge conflict
Browse files Browse the repository at this point in the history
Signed-off-by: EdricCua <[email protected]>
  • Loading branch information
EdricCua committed Jan 8, 2025
2 parents 51e6294 + 4341d66 commit 9e5d2e5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,14 @@ func (client *baseClient) BZPopMin(keys []string, timeoutSecs float64) (Result[K
return handleKeyWithMemberAndScoreResponse(result)
}

func (client *baseClient) Persist(key string) (Result[bool], error) {
result, err := client.executeCommand(C.Persist, []string{key})
if err != nil {
return CreateNilBoolResult(), err
}
return handleBooleanResponse(result)
}

func (client *baseClient) Restore(key string, ttl int64, value string) (Result[string], error) {
return client.RestoreWithOptions(key, ttl, value, NewRestoreOptionsBuilder())
}
Expand Down
19 changes: 19 additions & 0 deletions go/api/generic_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,25 @@ type GenericBaseCommands interface {
// [valkey.io]: https://valkey.io/commands/renamenx/
Renamenx(key string, newKey string) (Result[bool], error)

// Removes the existing timeout on key, turning the key from volatile
// (a key with an expire set) to persistent (a key that will never expire as no timeout is associated).
//
// Parameters:
// key - The key to remove the existing timeout on.
//
// Return value:
// false if key does not exist or does not have an associated timeout, true if the timeout has been removed.
//
// Example:
// result, err := client.Persist([]string{"key"})
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: true
//
// [valkey.io]: https://valkey.io/commands/persist/
Persist(key string) (Result[bool], error)

// Create a key associated with a value that is obtained by
// deserializing the provided serialized value (obtained via [valkey.io]: Https://valkey.io/commands/dump/).
//
Expand Down
28 changes: 28 additions & 0 deletions go/integTest/shared_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4457,6 +4457,34 @@ func (suite *GlideTestSuite) TestZRem() {
})
}

func (suite *GlideTestSuite) TestPersist() {
suite.runWithDefaultClients(func(client api.BaseClient) {
// Test 1: Check if persist command removes the expiration time of a key.
keyName := "{keyName}" + uuid.NewString()
t := suite.T()
suite.verifyOK(client.Set(keyName, initialValue))
resultExpire, err := client.Expire(keyName, 300)
assert.Nil(t, err)
assert.True(t, resultExpire.Value())
resultPersist, err := client.Persist(keyName)
assert.Nil(t, err)
assert.True(t, resultPersist.Value())

// Test 2: Check if persist command return false if key that doesnt have associated timeout.
keyNoExp := "{keyName}" + uuid.NewString()
suite.verifyOK(client.Set(keyNoExp, initialValue))
resultPersistNoExp, err := client.Persist(keyNoExp)
assert.Nil(t, err)
assert.False(t, resultPersistNoExp.Value())

// Test 3: Check if persist command return false if key not exist.
keyInvalid := "{invalidkey_forPersistTest}" + uuid.NewString()
resultInvalidKey, err := client.Persist(keyInvalid)
assert.Nil(t, err)
assert.False(t, resultInvalidKey.Value())
})
}

func (suite *GlideTestSuite) TestObjectEncoding() {
suite.runWithDefaultClients(func(client api.BaseClient) {
// Test 1: Check object encoding for embstr
Expand Down

0 comments on commit 9e5d2e5

Please sign in to comment.