Skip to content

Commit 1aa4b88

Browse files
authored
PfAdd fix return type from int to bool (valkey-io#4094)
1 parent 2f6b292 commit 1aa4b88

File tree

21 files changed

+107
-98
lines changed

21 files changed

+107
-98
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
* Java: Shadow netty dependencies. ([#3004](https://github.com/valkey-io/valkey-glide/pull/3004))
113113
* Go: Modify `requestTimeout` and `connectionTimeout` to be of type `time.Duration` ([#3857](https://github.com/valkey-io/valkey-glide/pull/3857))
114114
* Go: XRead and XReadGroup response update ([#4085](https://github.com/valkey-io/valkey-glide/pull/4085))
115+
* Modify `PFADD` to return a boolean rather than an integer ([#4094](https://github.com/valkey-io/valkey-glide/pull/4094))
115116

116117
#### Fixes
117118

glide-core/src/client/value_conversion.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ pub(crate) fn expected_type_for_cmd(cmd: &Cmd) -> Option<ExpectedReturnType> {
14581458
| b"SISMEMBER"
14591459
| b"PERSIST"
14601460
| b"SMOVE"
1461+
| b"PFADD"
14611462
| b"RENAMENX"
14621463
| b"MOVE"
14631464
| b"COPY"
@@ -3168,6 +3169,14 @@ mod tests {
31683169
));
31693170
}
31703171

3172+
#[test]
3173+
fn convert_pfadd_to_bool() {
3174+
assert!(matches!(
3175+
expected_type_for_cmd(redis::cmd("PFADD").arg("key1").arg("a").arg("b")),
3176+
Some(ExpectedReturnType::Boolean)
3177+
));
3178+
}
3179+
31713180
#[test]
31723181
fn test_convert_to_map_of_string_to_double() {
31733182
assert_eq!(

go/base_client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,16 +3780,16 @@ func (client *baseClient) PTTL(ctx context.Context, key string) (int64, error) {
37803780
// Return value:
37813781
//
37823782
// If the HyperLogLog is newly created, or if the HyperLogLog approximated cardinality is
3783-
// altered, then returns `1`. Otherwise, returns `0`.
3783+
// altered, then returns `true`. Otherwise, returns `false`.
37843784
//
37853785
// [valkey.io]: https://valkey.io/commands/pfadd/
3786-
func (client *baseClient) PfAdd(ctx context.Context, key string, elements []string) (int64, error) {
3786+
func (client *baseClient) PfAdd(ctx context.Context, key string, elements []string) (bool, error) {
37873787
result, err := client.executeCommand(ctx, C.PfAdd, append([]string{key}, elements...))
37883788
if err != nil {
3789-
return models.DefaultIntResponse, err
3789+
return models.DefaultBoolResponse, err
37903790
}
37913791

3792-
return handleIntResponse(result)
3792+
return handleBoolResponse(result)
37933793
}
37943794

37953795
// Estimates the cardinality of the data stored in a HyperLogLog structure for a single key or

go/hyperloglog_commands_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func ExampleClient_PfAdd() {
1717
}
1818
fmt.Println(result)
1919

20-
// Output: 1
20+
// Output: true
2121
}
2222

2323
func ExampleClusterClient_PfAdd() {
@@ -28,7 +28,7 @@ func ExampleClusterClient_PfAdd() {
2828
}
2929
fmt.Println(result)
3030

31-
// Output: 1
31+
// Output: true
3232
}
3333

3434
func ExampleClient_PfCount() {
@@ -43,7 +43,7 @@ func ExampleClient_PfCount() {
4343
fmt.Println(result1)
4444

4545
// Output:
46-
// 1
46+
// true
4747
// 3
4848
}
4949

@@ -59,7 +59,7 @@ func ExampleClusterClient_PfCount() {
5959
fmt.Println(result1)
6060

6161
// Output:
62-
// 1
62+
// true
6363
// 3
6464
}
6565

go/integTest/batch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,13 +1165,13 @@ func CreateHyperLogLogTest(batch *pipeline.ClusterBatch, isAtomic bool, serverVe
11651165
dest := atomicPrefix + "dest-" + uuid.NewString()
11661166

11671167
batch.PfAdd(key1, []string{"val"})
1168-
testData = append(testData, CommandTestData{ExpectedResponse: int64(1), TestName: "PfAdd(key1, [val])"})
1168+
testData = append(testData, CommandTestData{ExpectedResponse: true, TestName: "PfAdd(key1, [val])"})
11691169

11701170
batch.PfCount([]string{key1})
11711171
testData = append(testData, CommandTestData{ExpectedResponse: int64(1), TestName: "PfCount([key1])"})
11721172

11731173
batch.PfAdd(key1, []string{"val2"})
1174-
testData = append(testData, CommandTestData{ExpectedResponse: int64(1), TestName: "PfAdd(key2, [val2])"})
1174+
testData = append(testData, CommandTestData{ExpectedResponse: true, TestName: "PfAdd(key2, [val2])"})
11751175
batch.PfMerge(prefix+dest, []string{prefix + key1, prefix + key2})
11761176
testData = append(testData, CommandTestData{ExpectedResponse: "OK", TestName: "PfMerge(dest, [key1 key2])"})
11771177

go/integTest/shared_commands_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,7 +4117,7 @@ func (suite *GlideTestSuite) TestPfAdd_SuccessfulAddition() {
41174117
key := uuid.New().String()
41184118
res, err := client.PfAdd(context.Background(), key, []string{"a", "b", "c", "d", "e"})
41194119
assert.Nil(suite.T(), err)
4120-
assert.Equal(suite.T(), int64(1), res)
4120+
assert.True(suite.T(), res)
41214121
})
41224122
}
41234123

@@ -4128,25 +4128,25 @@ func (suite *GlideTestSuite) TestPfAdd_DuplicateElements() {
41284128
// case : Add elements and add same elements again
41294129
res, err := client.PfAdd(context.Background(), key, []string{"a", "b", "c", "d", "e"})
41304130
assert.Nil(suite.T(), err)
4131-
assert.Equal(suite.T(), int64(1), res)
4131+
assert.True(suite.T(), res)
41324132

41334133
res2, err := client.PfAdd(context.Background(), key, []string{"a", "b", "c", "d", "e"})
41344134
assert.Nil(suite.T(), err)
4135-
assert.Equal(suite.T(), int64(0), res2)
4135+
assert.False(suite.T(), res2)
41364136

41374137
// case : (mixed elements) add new elements with 1 duplicate elements
41384138
res1, err := client.PfAdd(context.Background(), key, []string{"f", "g", "h"})
41394139
assert.Nil(suite.T(), err)
4140-
assert.Equal(suite.T(), int64(1), res1)
4140+
assert.True(suite.T(), res1)
41414141

41424142
res2, err = client.PfAdd(context.Background(), key, []string{"i", "j", "g"})
41434143
assert.Nil(suite.T(), err)
4144-
assert.Equal(suite.T(), int64(1), res2)
4144+
assert.True(suite.T(), res2)
41454145

41464146
// case : add empty array(no elements to the HyperLogLog)
41474147
res, err = client.PfAdd(context.Background(), key, []string{})
41484148
assert.Nil(suite.T(), err)
4149-
assert.Equal(suite.T(), int64(0), res)
4149+
assert.False(suite.T(), res)
41504150
})
41514151
}
41524152

@@ -4155,7 +4155,7 @@ func (suite *GlideTestSuite) TestPfCount_SingleKey() {
41554155
key := uuid.New().String()
41564156
res, err := client.PfAdd(context.Background(), key, []string{"i", "j", "g"})
41574157
assert.Nil(suite.T(), err)
4158-
assert.Equal(suite.T(), int64(1), res)
4158+
assert.True(suite.T(), res)
41594159

41604160
resCount, err := client.PfCount(context.Background(), []string{key})
41614161
assert.Nil(suite.T(), err)
@@ -4170,11 +4170,11 @@ func (suite *GlideTestSuite) TestPfCount_MultipleKeys() {
41704170

41714171
res, err := client.PfAdd(context.Background(), key1, []string{"a", "b", "c"})
41724172
assert.Nil(suite.T(), err)
4173-
assert.Equal(suite.T(), int64(1), res)
4173+
assert.True(suite.T(), res)
41744174

41754175
res, err = client.PfAdd(context.Background(), key2, []string{"c", "d", "e"})
41764176
assert.Nil(suite.T(), err)
4177-
assert.Equal(suite.T(), int64(1), res)
4177+
assert.True(suite.T(), res)
41784178

41794179
resCount, err := client.PfCount(context.Background(), []string{key1, key2})
41804180
assert.Nil(suite.T(), err)
@@ -4201,11 +4201,11 @@ func (suite *GlideTestSuite) TestPfMerge() {
42014201

42024202
res, err := client.PfAdd(context.Background(), source1, []string{"a", "b", "c"})
42034203
assert.Nil(suite.T(), err)
4204-
assert.Equal(suite.T(), int64(1), res)
4204+
assert.True(suite.T(), res)
42054205

42064206
res, err = client.PfAdd(context.Background(), source2, []string{"c", "d", "e"})
42074207
assert.Nil(suite.T(), err)
4208-
assert.Equal(suite.T(), int64(1), res)
4208+
assert.True(suite.T(), res)
42094209

42104210
result, err := client.PfMerge(context.Background(), destination, []string{source1, source2})
42114211
assert.Nil(suite.T(), err)
@@ -4224,7 +4224,7 @@ func (suite *GlideTestSuite) TestPfMerge_SingleSource() {
42244224

42254225
res, err := client.PfAdd(context.Background(), source, []string{"a", "b", "c"})
42264226
assert.Nil(suite.T(), err)
4227-
assert.Equal(suite.T(), int64(1), res)
4227+
assert.True(suite.T(), res)
42284228

42294229
result, err := client.PfMerge(context.Background(), destination, []string{source})
42304230
assert.Nil(suite.T(), err)

go/internal/interfaces/hyperloglog_commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import "context"
1010
//
1111
// [valkey.io]: https://valkey.io/commands/#hyperloglog
1212
type HyperLogLogCommands interface {
13-
PfAdd(ctx context.Context, key string, elements []string) (int64, error)
13+
PfAdd(ctx context.Context, key string, elements []string) (bool, error)
1414

1515
PfCount(ctx context.Context, keys []string) (int64, error)
1616

go/pipeline/base_batch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,11 +2350,11 @@ func (b *BaseBatch[T]) PTTL(key string) *T {
23502350
// Command Response:
23512351
//
23522352
// If the HyperLogLog is newly created, or if the HyperLogLog approximated cardinality is
2353-
// altered, then returns `1`. Otherwise, returns `0`.
2353+
// altered, then returns `true`. Otherwise, returns `false`.
23542354
//
23552355
// [valkey.io]: https://valkey.io/commands/pfadd/
23562356
func (b *BaseBatch[T]) PfAdd(key string, elements []string) *T {
2357-
return b.addCmdAndTypeChecker(C.PfAdd, append([]string{key}, elements...), reflect.Int64, false)
2357+
return b.addCmdAndTypeChecker(C.PfAdd, append([]string{key}, elements...), reflect.Bool, false)
23582358
}
23592359

23602360
// Estimates the cardinality of the data stored in a HyperLogLog structure for a single key or

java/client/src/main/java/glide/api/BaseClient.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,15 +3804,16 @@ public CompletableFuture<Map<GlideString, Object>> bzmpop(
38043804
}
38053805

38063806
@Override
3807-
public CompletableFuture<Long> pfadd(@NonNull String key, @NonNull String[] elements) {
3807+
public CompletableFuture<Boolean> pfadd(@NonNull String key, @NonNull String[] elements) {
38083808
String[] arguments = ArrayUtils.addFirst(elements, key);
3809-
return commandManager.submitNewCommand(PfAdd, arguments, this::handleLongResponse);
3809+
return commandManager.submitNewCommand(PfAdd, arguments, this::handleBooleanResponse);
38103810
}
38113811

38123812
@Override
3813-
public CompletableFuture<Long> pfadd(@NonNull GlideString key, @NonNull GlideString[] elements) {
3813+
public CompletableFuture<Boolean> pfadd(
3814+
@NonNull GlideString key, @NonNull GlideString[] elements) {
38143815
GlideString[] arguments = ArrayUtils.addFirst(elements, key);
3815-
return commandManager.submitNewCommand(PfAdd, arguments, this::handleLongResponse);
3816+
return commandManager.submitNewCommand(PfAdd, arguments, this::handleBooleanResponse);
38163817
}
38173818

38183819
@Override

java/client/src/main/java/glide/api/commands/HyperLogLogBaseCommands.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public interface HyperLogLogBaseCommands {
2727
* altered, then returns <code>1</code>. Otherwise, returns <code>0</code>.
2828
* @example
2929
* <pre>{@code
30-
* Long result = client.pfadd("hll_1", new String[] { "a", "b", "c" }).get();
31-
* assert result == 1L; // A data structure was created or modified
30+
* Boolean result = client.pfadd("hll_1", new String[] { "a", "b", "c" }).get();
31+
* assert result; // A data structure was created or modified
3232
*
3333
* result = client.pfadd("hll_2", new String[0]).get();
34-
* assert result == 1L; // A new empty data structure was created
34+
* assert result; // A new empty data structure was created
3535
* }</pre>
3636
*/
37-
CompletableFuture<Long> pfadd(String key, String[] elements);
37+
CompletableFuture<Boolean> pfadd(String key, String[] elements);
3838

3939
/**
4040
* Adds all elements to the HyperLogLog data structure stored at the specified <code>key</code>.
@@ -49,17 +49,17 @@ public interface HyperLogLogBaseCommands {
4949
* @param key The <code>key</code> of the HyperLogLog data structure to add elements into.
5050
* @param elements An array of members to add to the HyperLogLog stored at <code>key</code>.
5151
* @return If the HyperLogLog is newly created, or if the HyperLogLog approximated cardinality is
52-
* altered, then returns <code>1</code>. Otherwise, returns <code>0</code>.
52+
* altered, then returns <code>true</code>. Otherwise, returns <code>false</code>.
5353
* @example
5454
* <pre>{@code
55-
* Long result = client.pfadd(gs("hll_1"), new GlideString[] { gs("a"), gs("b"), gs("c") }).get();
56-
* assert result == 1L; // A data structure was created or modified
55+
* Boolean result = client.pfadd(gs("hll_1"), new GlideString[] { gs("a"), gs("b"), gs("c") }).get();
56+
* assert result; // A data structure was created or modified
5757
*
5858
* result = client.pfadd(gs("hll_2"), new GlideString[0]).get();
59-
* assert result == 1L; // A new empty data structure was created
59+
* assert result; // A new empty data structure was created
6060
* }</pre>
6161
*/
62-
CompletableFuture<Long> pfadd(GlideString key, GlideString[] elements);
62+
CompletableFuture<Boolean> pfadd(GlideString key, GlideString[] elements);
6363

6464
/**
6565
* Estimates the cardinality of the data stored in a HyperLogLog structure for a single key or

0 commit comments

Comments
 (0)