diff --git a/go/api/base_client.go b/go/api/base_client.go index 0156a60b92..8dcd258a3b 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -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) +} diff --git a/go/api/stream_commands.go b/go/api/stream_commands.go index 4aa295a753..c40e962aa7 100644 --- a/go/api/stream_commands.go +++ b/go/api/stream_commands.go @@ -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) } diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index 918ba95264..23bf7500f6 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -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) }) } diff --git a/java/README.md b/java/README.md index 4264d4c838..48dbc0ec91 100644 --- a/java/README.md +++ b/java/README.md @@ -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)