Skip to content

Commit

Permalink
Merge branch 'main' into go-zcount-command
Browse files Browse the repository at this point in the history
Signed-off-by: prateek-kumar-improving <[email protected]>
  • Loading branch information
prateek-kumar-improving authored Jan 15, 2025
2 parents d8ebf66 + 55ccdad commit 9496b58
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
33 changes: 33 additions & 0 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1665,3 +1665,36 @@ func (client *baseClient) XLen(key string) (int64, error) {
}
return handleIntResponse(result)
}

// Removes the specified entries by id from a stream, and returns the number of entries deleted.
//
// See [valkey.io] for details.
//
// Parameters:
//
// key - The key of the stream.
// ids - An array of entry ids.
//
// Return value:
//
// The number of entries removed from the stream. This number may be less than the number
// of entries in `ids`, if the specified `ids` don't exist in the stream.
//
// For example:
//
// xAddResult, err := client.XAddWithOptions(
// "key1",
// [][]string{{"f1", "foo1"}, {"f2", "bar2"}},
// options.NewXAddOptions().SetId(streamId1),
// )
// xDelResult, err := client.XDel("key1", []string{streamId1, streamId3})
// fmt.Println(xDelResult) // Output: 1
//
// [valkey.io]: https://valkey.io/commands/xdel/
func (client *baseClient) XDel(key string, ids []string) (int64, error) {
result, err := client.executeCommand(C.XDel, append([]string{key}, ids...))
if err != nil {
return defaultIntResponse, err
}
return handleIntResponse(result)
}
2 changes: 2 additions & 0 deletions go/api/stream_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@ type StreamCommands interface {
//
// [valkey.io]: https://valkey.io/commands/xlen/
XLen(key string) (int64, error)

XDel(key string, ids []string) (int64, error)
}
49 changes: 49 additions & 0 deletions go/integTest/shared_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4877,5 +4877,54 @@ func (suite *GlideTestSuite) TestZCount() {
_, err = client.ZCount(key2, zCountRange)
assert.NotNil(t, err)
assert.IsType(suite.T(), &api.RequestError{}, err)
})
}

func (suite *GlideTestSuite) Test_XDel() {
suite.runWithDefaultClients(func(client api.BaseClient) {
key1 := uuid.NewString()
key2 := uuid.NewString()
streamId1 := "0-1"
streamId2 := "0-2"
streamId3 := "0-3"
t := suite.T()

xAddResult, err := client.XAddWithOptions(
key1,
[][]string{{"f1", "foo1"}, {"f2", "bar2"}},
options.NewXAddOptions().SetId(streamId1),
)
assert.NoError(t, err)
assert.Equal(t, xAddResult.Value(), streamId1)

xAddResult, err = client.XAddWithOptions(
key1,
[][]string{{"f1", "foo1"}, {"f2", "bar2"}},
options.NewXAddOptions().SetId(streamId2),
)
assert.NoError(t, err)
assert.Equal(t, xAddResult.Value(), streamId2)

xLenResult, err := client.XLen(key1)
assert.NoError(t, err)
assert.Equal(t, xLenResult, int64(2))

// Deletes one stream id, and ignores anything invalid:
xDelResult, err := client.XDel(key1, []string{streamId1, streamId3})
assert.NoError(t, err)
assert.Equal(t, xDelResult, int64(1))

xDelResult, err = client.XDel(key2, []string{streamId3})
assert.NoError(t, err)
assert.Equal(t, xDelResult, int64(0))

// Throws error: Key exists - but it is not a stream
setResult, err := client.Set(key2, "xdeltest")
assert.NoError(t, err)
assert.Equal(t, "OK", setResult)

_, err = client.XDel(key2, []string{streamId3})
assert.NotNil(t, err)
assert.IsType(t, &api.RequestError{}, err)
})
}
2 changes: 2 additions & 0 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Linux:
- Ubuntu 22.04.1 (x86_64 and aarch64)
- Amazon Linux 2023 (AL2023) (x86_64)

**Note: Currently Alpine Linux / MUSL is NOT supported due to an incompatibility with a native Java component.**

macOS:

- macOS 14.7 (Apple silicon/aarch_64)
Expand Down

0 comments on commit 9496b58

Please sign in to comment.