diff --git a/go/api/base_client.go b/go/api/base_client.go index 7118f2b85a..7816fba8fc 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -400,3 +400,17 @@ func (client *baseClient) HStrLen(key string, field string) (Result[int64], erro return handleLongResponse(result) } + +func (client *baseClient) Del(keys []string) (int64, error) { + result, err := client.executeCommand(C.Del, keys) + if err != nil { + return 0, err + } + + deletedCount, handleErr := handleLongResponse(result) + if handleErr != nil { + return 0, handleErr + } + + return deletedCount, nil +} diff --git a/go/api/commands.go b/go/api/commands.go index f1e924b676..ba3160896b 100644 --- a/go/api/commands.go +++ b/go/api/commands.go @@ -129,7 +129,7 @@ type StringCommands interface { // } // // [valkey.io]: https://valkey.io/commands/mget/ - MGet(keys []string) ([]Result[string], error) + MGet(keys []string) ([]string, error) // Sets multiple keys to values if the key does not exist. The operation is atomic, and if one or more keys already exist, // the entire operation fails. @@ -143,19 +143,17 @@ type StringCommands interface { // keyValueMap - A key-value map consisting of keys and their respective values to set. // // Return value: - // A Result[bool] containing true, if all keys were set. false, if no key was set. + // true, if all keys were set. false, if no key was set. // // For example: // 1. result, err := client.MSetNX(map[string]string{"key1": "value1", "key2": "value2"}) - // result.Value(): true - // result.IsNil(): false + // result: true // 2. key3: initialValue // result, err := client.MSetNX(map[string]string{"key3": "value3", "key4": "value4"}) - // result.Value(): false - // result.IsNil(): false + // result: false // // [valkey.io]: https://valkey.io/commands/msetnx/ - MSetNX(keyValueMap map[string]string) (Result[bool], error) + MSetNX(keyValueMap map[string]string) (bool, error) // Increments the number stored at key by one. If key does not exist, it is set to 0 before performing the operation. // @@ -165,16 +163,15 @@ type StringCommands interface { // key - The key to increment its value. // // Return value: - // The Result[int64] of key after the increment. + // The value of key after the increment. // // For example: // key: 1 // result, err := client.Incr("key"); - // result.Value(): 2 - // result.IsNil(): false + // result: 2 // // [valkey.io]: https://valkey.io/commands/incr/ - Incr(key string) (Result[int64], error) + Incr(key string) (int64, error) // Increments the number stored at key by amount. If key does not exist, it is set to 0 before performing the operation. // @@ -185,16 +182,15 @@ type StringCommands interface { // amount - The amount to increment. // // Return value: - // The Result[int64] of key after the increment. + // The value of key after the increment. // // For example: // key: 1 - // result, err := client.IncrBy("key", 2) - // result.Value(): 3 - // result.IsNil(): false + // result, err := client.IncrBy("key", 2); + // result: 3 // // [valkey.io]: https://valkey.io/commands/incrby/ - IncrBy(key string, amount int64) (Result[int64], error) + IncrBy(key string, amount int64) (int64, error) // Increments the string representing a floating point number stored at key by amount. By using a negative increment value, // the result is that the value stored at key is decremented. If key does not exist, it is set to 0 before performing the @@ -207,16 +203,15 @@ type StringCommands interface { // amount - The amount to increment. // // Return value: - // The Result[float64] of key after the increment. + // The value of key after the increment. // // For example: // key: 1 - // result, err := client.IncrBy("key", 0.5) - // result.Value(): 1.5 - // result.IsNil(): false + // result, err := client.IncrBy("key", 0.5); + // result: 1.5 // // [valkey.io]: https://valkey.io/commands/incrbyfloat/ - IncrByFloat(key string, amount float64) (Result[float64], error) + IncrByFloat(key string, amount float64) (float64, error) // Decrements the number stored at key by one. If key does not exist, it is set to 0 before performing the operation. // @@ -226,16 +221,15 @@ type StringCommands interface { // key - The key to decrement its value. // // Return value: - // The Result[int64] of key after the decrement. + // The value of key after the decrement. // // For example: // key: 1 - // result, err := client.Decr("key") - // result.Value(): 0 - // result.IsNil(): false + // result, err := client.Decr("key"); + // result: 0 // // [valkey.io]: https://valkey.io/commands/decr/ - Decr(key string) (Result[int64], error) + Decr(key string) (int64, error) // Decrements the number stored at code by amount. If key does not exist, it is set to 0 before performing the operation. // @@ -246,16 +240,15 @@ type StringCommands interface { // amount - The amount to decrement. // // Return value: - // The Result[int64] of key after the decrement. + // The value of key after the decrement. // // For example: // key: 1 - // result, err := client.DecrBy("key", 2) - // result.Value(): -1 - // result.IsNil(): false + // result, err := client.DecrBy("key", 2); + // result: -1 // // [valkey.io]: https://valkey.io/commands/decrby/ - DecrBy(key string, amount int64) (Result[int64], error) + DecrBy(key string, amount int64) (int64, error) // Returns the length of the string value stored at key. // @@ -265,17 +258,16 @@ type StringCommands interface { // key - The key to check its length. // // Return value: - // The length of the string value stored at key as Result[int64]. - // If key does not exist, it is treated as an empty string, and the command returns Result[int64] containing 0 . + // The length of the string value stored at key. + // If key does not exist, it is treated as an empty string, and the command returns 0. // // For example: // key: value - // result, err := client.Strlen("key") - // result.Value(): 5 - // result.IsNil(): false + // result, err := client.Strlen("key"); + // result: 5 // // [valkey.io]: https://valkey.io/commands/strlen/ - Strlen(key string) (Result[int64], error) + Strlen(key string) (int64, error) // Overwrites part of the string stored at key, starting at the specified byte's offset, for the entire length of value. // If the offset is larger than the current length of the string at key, the string is padded with zero bytes to make @@ -290,20 +282,19 @@ type StringCommands interface { // value - The string written with offset. // // Return value: - // The length of the string stored at key after it was modified as Result[int64]. + // The length of the string stored at key after it was modified. // // For example: // 1. result, err := client.SetRange("key", 6, "GLIDE"); - // result.Value(): 11 (New key created with length of 11 bytes) - // result.IsNil(): false + // result: 11 (New key created with length of 11 bytes) // value, err := client.Get("key") - // value.Value(): "\x00\x00\x00\x00\x00\x00GLIDE" + // value: "\x00\x00\x00\x00\x00\x00GLIDE" // 2. "key": "愛" (value char takes 3 bytes) // result, err = client.SetRange("key", 1, "a") - // result.Value(): �a� // (becomes an invalid UTF-8 string) + // "key": �a� // (becomes an invalid UTF-8 string) // // [valkey.io]: https://valkey.io/commands/setrange/ - SetRange(key string, offset int, value string) (Result[int64], error) + SetRange(key string, offset int, value string) (int64, error) // Returns the substring of the string value stored at key, determined by the byte's offsets start and end (both are // inclusive). @@ -318,24 +309,21 @@ type StringCommands interface { // end - The ending offset. // // Return value: - // A Result[string] containing substring extracted from the value stored at key. - // A [api.NilResult[string]] (api.CreateNilStringResult()) is returned if the offset is out of bounds. + // A substring extracted from the value stored at key. + // An ("") empty string is returned if the offset is out of bounds. // // For example: // 1. mykey: "This is a string" - // result, err := client.GetRange("mykey", 0, 3) - // result.Value(): "This" - // result.IsNil(): false - // result, err := client.GetRange("mykey", -3, -1) - // result.Value(): "ing" (extracted last 3 characters of a string) - // result.IsNil(): false + // result, err := client.GetRange("mykey", 0, 3); + // result: "This" + // result, err := client.GetRange("mykey", -3, -1); + // result: "ing" (extracted last 3 characters of a string) // 2. "key": "愛" (value char takes 3 bytes) // result, err = client.GetRange("key", 0, 1) - // result.Value(): "�" (returns an invalid UTF-8 string) - // result.IsNil(): false + // result: � // (returns an invalid UTF-8 string) // // [valkey.io]: https://valkey.io/commands/getrange/ - GetRange(key string, start int, end int) (Result[string], error) + GetRange(key string, start int, end int) (string, error) // Appends a value to a key. If key does not exist it is created and set as an empty string, so APPEND will be similar to // SET in this special case. @@ -347,15 +335,14 @@ type StringCommands interface { // value - The value to append. // // Return value: - // The Result[int64] containing the length of the string after appending the value. + // The length of the string after appending the value. // // For example: - // result, err := client.Append("key", "value") - // result.Value(): 5 - // result.IsNil(): false + // result, err := client.Append("key", "value"); + // result: 5 // // [valkey.io]: https://valkey.io/commands/append/ - Append(key string, value string) (Result[int64], error) + Append(key string, value string) (int64, error) // Returns the longest common subsequence between strings stored at key1 and key2. // @@ -372,17 +359,16 @@ type StringCommands interface { // key2 - The key that stores the second string. // // Return value: - // A Result[string] containing the longest common subsequence between the 2 strings. - // A Result[string] containing empty String is returned if the keys do not exist or have no common subsequences. + // A String containing the longest common subsequence between the 2 strings. + // An empty String is returned if the keys do not exist or have no common subsequences. // // For example: // testKey1: foo, testKey2: fao - // result, err := client.LCS("testKey1", "testKey2") - // result.Value(): "fo" - // result.IsNil(): false + // result, err := client.LCS("testKey1", "testKey2"); + // result: "fo" // // [valkey.io]: https://valkey.io/commands/lcs/ - LCS(key1 string, key2 string) (Result[string], error) + LCS(key1 string, key2 string) (string, error) // GetDel gets the value associated with the given key and deletes the key. // // Parameters: @@ -390,13 +376,34 @@ type StringCommands interface { // // Return value: // If key exists, returns the value of the key as a String and deletes the key. - // If key does not exist, returns a [api.NilResult[string]] (api.CreateNilStringResult()). + // If key does not exist, returns an empty string (""). // // For example: // result, err := client.GetDel("key") // //[valkey.io]: https://valkey.io/commands/getdel/ - GetDel(key string) (Result[string], error) + + GetDel(key string) (string, error) + + // Del removes the specified keys from the database. A key is ignored if it does not exist. + // + // @apiNote When in cluster mode, the command may route to multiple nodes when `keys` map to different hash slots. + // + // Parameters: + // keys - One or more keys to delete. + // + // Return value: + // Returns the number of keys that were removed. + // + // Example: + // result, err := client.Del([]string{"key1", "key2", "key3"}) + // if err != nil { + // // handle error + // } + // fmt.Println(result) // Output: 2 + // + // [valkey.io]: https://valkey.io/commands/del/ + Del(keys ...string) (int64, error) } // HashCommands supports commands and transactions for the "Hash Commands" group for standalone and cluster @@ -415,20 +422,18 @@ type HashCommands interface { // field - The field in the hash stored at key to retrieve from the database. // // Return value: - // The Result[string] associated with field, or [api.NilResult[string]](api.CreateNilStringResult()) when field is not - // present in the hash or key does not exist. + // The value associated with field, or an empty string when field is not present in the hash or key does not exist. // // For example: // Assume we have the following hash: // my_hash := map[string]string{"field1": "value", "field2": "another_value"} // payload, err := client.HGet("my_hash", "field1") - // // payload.Value(): "value" - // // payload.IsNil(): false + // // payload equals "value" // payload, err = client.HGet("my_hash", "nonexistent_field") - // // payload equals api.CreateNilStringResult() + // // payload equals "" // // [valkey.io]: https://valkey.io/commands/hget/ - HGet(key string, field string) (Result[string], error) + HGet(key string, field string) (string, error) // HGetAll returns all fields and values of the hash stored at key. // @@ -438,18 +443,14 @@ type HashCommands interface { // key - The key of the hash. // // Return value: - // A map of all fields and their values as Result[string] in the hash, or an empty map when key does not exist. + // A map of all fields and their values in the hash, or an empty map when key does not exist. // // For example: // fieldValueMap, err := client.HGetAll("my_hash") - // // field1 equals api.CreateStringResult("field1") - // // value1 equals api.CreateStringResult("value1") - // // field2 equals api.CreateStringResult("field2") - // // value2 equals api.CreateStringResult("value2") - // // fieldValueMap equals map[api.Result[string]]api.Result[string]{field1: value1, field2: value2} + // // fieldValueMap equals map[string]string{"field1": "value1", "field2": "value2"} // // [valkey.io]: https://valkey.io/commands/hgetall/ - HGetAll(key string) (map[Result[string]]Result[string], error) + HGetAll(key string) (map[string]string, error) // HMGet returns the values associated with the specified fields in the hash stored at key. // @@ -460,19 +461,16 @@ type HashCommands interface { // fields - The fields in the hash stored at key to retrieve from the database. // // Return value: - // An array of Result[string]s associated with the given fields, in the same order as they are requested. - // For every field that does not exist in the hash, a [api.NilResult[string]](api.CreateNilStringResult()) is - // returned. + // An array of values associated with the given fields, in the same order as they are requested. + // For every field that does not exist in the hash, a null value is returned. // If key does not exist, returns an empty string array. // // For example: // values, err := client.HMGet("my_hash", []string{"field1", "field2"}) - // // value1 equals api.CreateStringResult("value1") - // // value2 equals api.CreateStringResult("value2") - // // values equals []api.Result[string]{value1, value2} + // // values equals []string{"value1", "value2"} // // [valkey.io]: https://valkey.io/commands/hmget/ - HMGet(key string, fields []string) ([]Result[string], error) + HMGet(key string, fields []string) ([]string, error) // HSet sets the specified fields to their respective values in the hash stored at key. // This command overwrites the values of specified fields that exist in the hash. @@ -485,15 +483,14 @@ type HashCommands interface { // values - A map of field-value pairs to set in the hash. // // Return value: - // The Result[int64] containing number of fields that were added or updated. + // The number of fields that were added or updated. // // For example: // num, err := client.HSet("my_hash", map[string]string{"field": "value", "field2": "value2"}) - // // num.Value(): 2 - // // num.IsNil(): false + // // num equals 2 // // [valkey.io]: https://valkey.io/commands/hset/ - HSet(key string, values map[string]string) (Result[int64], error) + HSet(key string, values map[string]string) (int64, error) // HSetNX sets field in the hash stored at key to value, only if field does not yet exist. // If key does not exist, a new key holding a hash is created. @@ -507,19 +504,17 @@ type HashCommands interface { // value - The value to set. // // Return value: - // A Result[bool] containing true if field is a new field in the hash and value was set. + // true if field is a new field in the hash and value was set. // false if field already exists in the hash and no operation was performed. // // For example: // payload1, err := client.HSetNX("myHash", "field", "value") - // // payload1.Value(): true - // // payload1.IsNil(): false + // // payload1 equals true // payload2, err := client.HSetNX("myHash", "field", "newValue") - // // payload2.Value(): false - // // payload2.IsNil(): false + // // payload2 equals false // // [valkey.io]: https://valkey.io/commands/hsetnx/ - HSetNX(key string, field string, value string) (Result[bool], error) + HSetNX(key string, field string, value string) (bool, error) // HDel removes the specified fields from the hash stored at key. // Specified fields that do not exist within this hash are ignored. @@ -532,16 +527,14 @@ type HashCommands interface { // fields - The fields to remove from the hash stored at key. // // Return value: - // The Result[int64] containing number of fields that were removed from the hash, not including specified but non-existing - // fields. + // The number of fields that were removed from the hash, not including specified but non-existing fields. // // For example: // num, err := client.HDel("my_hash", []string{"field_1", "field_2"}) - // // num.Value(): 2 - // // num.IsNil(): false + // // num equals 2 // // [valkey.io]: https://valkey.io/commands/hdel/ - HDel(key string, fields []string) (Result[int64], error) + HDel(key string, fields []string) (int64, error) // HLen returns the number of fields contained in the hash stored at key. // @@ -551,19 +544,17 @@ type HashCommands interface { // key - The key of the hash. // // Return value: - // The Result[int64] containing number of fields in the hash, or 0 when key does not exist. + // The number of fields in the hash, or 0 when key does not exist. // If key holds a value that is not a hash, an error is returned. // // For example: // num1, err := client.HLen("myHash") - // // num.Value(): 3 - // // num.IsNil(): false + // // num1 equals 3 // num2, err := client.HLen("nonExistingKey") - // // num.Value(): 0 - // // num.IsNil(): false + // // num2 equals 0 // // [valkey.io]: https://valkey.io/commands/hlen/ - HLen(key string) (Result[int64], error) + HLen(key string) (int64, error) // HVals returns all values in the hash stored at key. // @@ -573,17 +564,14 @@ type HashCommands interface { // key - The key of the hash. // // Return value: - // A slice of Result[string]s containing all the values in the hash, or an empty slice when key does not exist. + // A slice of strings containing all the values in the hash, or an empty slice when key does not exist. // // For example: // values, err := client.HVals("myHash") - // // value1 equals api.CreateStringResult("value1") - // // value2 equals api.CreateStringResult("value2") - // // value3 equals api.CreateStringResult("value3") - // // values equals []api.Result[string]{value1, value2, value3} + // // values equals []string{"value1", "value2", "value3"} // // [valkey.io]: https://valkey.io/commands/hvals/ - HVals(key string) ([]Result[string], error) + HVals(key string) ([]string, error) // HExists returns if field is an existing field in the hash stored at key. // @@ -594,19 +582,17 @@ type HashCommands interface { // field - The field to check in the hash stored at key. // // Return value: - // A Result[bool] containing true if the hash contains the specified field. + // true if the hash contains the specified field. // false if the hash does not contain the field, or if the key does not exist. // // For example: // exists, err := client.HExists("my_hash", "field1") - // // exists.Value(): true - // // exists.IsNil(): false + // // exists equals true // exists, err = client.HExists("my_hash", "non_existent_field") - // // exists.Value(): false - // // exists.IsNil(): false + // // exists equals false // // [valkey.io]: https://valkey.io/commands/hexists/ - HExists(key string, field string) (Result[bool], error) + HExists(key string, field string) (bool, error) // HKeys returns all field names in the hash stored at key. // @@ -616,16 +602,14 @@ type HashCommands interface { // key - The key of the hash. // // Return value: - // A slice of Result[string]s containing all the field names in the hash, or an empty slice when key does not exist. + // A slice of strings containing all the field names in the hash, or an empty slice when key does not exist. // // For example: // names, err := client.HKeys("my_hash") - // // field1 equals api.CreateStringResult("field_1") - // // field2 equals api.CreateStringResult("field_2") - // // names equals []api.Result[string]{field1, field2} + // // names equals []string{"field_1", "field_2"} // // [valkey.io]: https://valkey.io/commands/hkeys/ - HKeys(key string) ([]Result[string], error) + HKeys(key string) ([]string, error) // HStrLen returns the string length of the value associated with field in the hash stored at key. // If the key or the field do not exist, 0 is returned. @@ -637,13 +621,141 @@ type HashCommands interface { // field - The field to get the string length of its value. // // Return value: - // The Result[int64] containing length of the string value associated with field, or 0 when field or key do not exist. + // The length of the string value associated with field, or 0 when field or key do not exist. // // For example: // strlen, err := client.HStrLen("my_hash", "my_field") - // // strlen.Value(): 10 - // // strlen.IsNil(): false + // // strlen equals 10 // // [valkey.io]: https://valkey.io/commands/hstrlen/ + HStrLen(key string, field string) (int64, error) + MGet(keys []string) ([]Result[string], error) + // A Result[bool] containing true, if all keys were set. false, if no key was set. + // result.Value(): true + // result.IsNil(): false + // result.Value(): false + // result.IsNil(): false + MSetNX(keyValueMap map[string]string) (Result[bool], error) + // The Result[int64] of key after the increment. + // result.Value(): 2 + // result.IsNil(): false + Incr(key string) (Result[int64], error) + // The Result[int64] of key after the increment. + // result, err := client.IncrBy("key", 2) + // result.Value(): 3 + // result.IsNil(): false + IncrBy(key string, amount int64) (Result[int64], error) + // The Result[float64] of key after the increment. + // result, err := client.IncrBy("key", 0.5) + // result.Value(): 1.5 + // result.IsNil(): false + IncrByFloat(key string, amount float64) (Result[float64], error) + // The Result[int64] of key after the decrement. + // result, err := client.Decr("key") + // result.Value(): 0 + // result.IsNil(): false + Decr(key string) (Result[int64], error) + // The Result[int64] of key after the decrement. + // result, err := client.DecrBy("key", 2) + // result.Value(): -1 + // result.IsNil(): false + DecrBy(key string, amount int64) (Result[int64], error) + // The length of the string value stored at key as Result[int64]. + // If key does not exist, it is treated as an empty string, and the command returns Result[int64] containing 0 . + // result, err := client.Strlen("key") + // result.Value(): 5 + // result.IsNil(): false + Strlen(key string) (Result[int64], error) + // The length of the string stored at key after it was modified as Result[int64]. + // result.Value(): 11 (New key created with length of 11 bytes) + // result.IsNil(): false + // value.Value(): "\x00\x00\x00\x00\x00\x00GLIDE" + // result.Value(): �a� // (becomes an invalid UTF-8 string) + SetRange(key string, offset int, value string) (Result[int64], error) + // A Result[string] containing substring extracted from the value stored at key. + // A [api.NilResult[string]] (api.CreateNilStringResult()) is returned if the offset is out of bounds. + // result, err := client.GetRange("mykey", 0, 3) + // result.Value(): "This" + // result.IsNil(): false + // result, err := client.GetRange("mykey", -3, -1) + // result.Value(): "ing" (extracted last 3 characters of a string) + // result.IsNil(): false + // result.Value(): "�" (returns an invalid UTF-8 string) + // result.IsNil(): false + GetRange(key string, start int, end int) (Result[string], error) + // The Result[int64] containing the length of the string after appending the value. + // result, err := client.Append("key", "value") + // result.Value(): 5 + // result.IsNil(): false + Append(key string, value string) (Result[int64], error) + // A Result[string] containing the longest common subsequence between the 2 strings. + // A Result[string] containing empty String is returned if the keys do not exist or have no common subsequences. + // result, err := client.LCS("testKey1", "testKey2") + // result.Value(): "fo" + // result.IsNil(): false + LCS(key1 string, key2 string) (Result[string], error) + // If key does not exist, returns a [api.NilResult[string]] (api.CreateNilStringResult()). + GetDel(key string) (Result[string], error) + // The Result[string] associated with field, or [api.NilResult[string]](api.CreateNilStringResult()) when field is not + // present in the hash or key does not exist. + // // payload.Value(): "value" + // // payload.IsNil(): false + // // payload equals api.CreateNilStringResult() + HGet(key string, field string) (Result[string], error) + // A map of all fields and their values as Result[string] in the hash, or an empty map when key does not exist. + // // field1 equals api.CreateStringResult("field1") + // // value1 equals api.CreateStringResult("value1") + // // field2 equals api.CreateStringResult("field2") + // // value2 equals api.CreateStringResult("value2") + // // fieldValueMap equals map[api.Result[string]]api.Result[string]{field1: value1, field2: value2} + HGetAll(key string) (map[Result[string]]Result[string], error) + // An array of Result[string]s associated with the given fields, in the same order as they are requested. + // For every field that does not exist in the hash, a [api.NilResult[string]](api.CreateNilStringResult()) is + // returned. + // // value1 equals api.CreateStringResult("value1") + // // value2 equals api.CreateStringResult("value2") + // // values equals []api.Result[string]{value1, value2} + HMGet(key string, fields []string) ([]Result[string], error) + // The Result[int64] containing number of fields that were added or updated. + // // num.Value(): 2 + // // num.IsNil(): false + HSet(key string, values map[string]string) (Result[int64], error) + // A Result[bool] containing true if field is a new field in the hash and value was set. + // // payload1.Value(): true + // // payload1.IsNil(): false + // // payload2.Value(): false + // // payload2.IsNil(): false + HSetNX(key string, field string, value string) (Result[bool], error) + // The Result[int64] containing number of fields that were removed from the hash, not including specified but non-existing + // fields. + // // num.Value(): 2 + // // num.IsNil(): false + HDel(key string, fields []string) (Result[int64], error) + // The Result[int64] containing number of fields in the hash, or 0 when key does not exist. + // // num.Value(): 3 + // // num.IsNil(): false + // // num.Value(): 0 + // // num.IsNil(): false + HLen(key string) (Result[int64], error) + // A slice of Result[string]s containing all the values in the hash, or an empty slice when key does not exist. + // // value1 equals api.CreateStringResult("value1") + // // value2 equals api.CreateStringResult("value2") + // // value3 equals api.CreateStringResult("value3") + // // values equals []api.Result[string]{value1, value2, value3} + HVals(key string) ([]Result[string], error) + // A Result[bool] containing true if the hash contains the specified field. + // // exists.Value(): true + // // exists.IsNil(): false + // // exists.Value(): false + // // exists.IsNil(): false + HExists(key string, field string) (Result[bool], error) + // A slice of Result[string]s containing all the field names in the hash, or an empty slice when key does not exist. + // // field1 equals api.CreateStringResult("field_1") + // // field2 equals api.CreateStringResult("field_2") + // // names equals []api.Result[string]{field1, field2} + HKeys(key string) ([]Result[string], error) + // The Result[int64] containing length of the string value associated with field, or 0 when field or key do not exist. + // // strlen.Value(): 10 + // // strlen.IsNil(): false HStrLen(key string, field string) (Result[int64], error) } diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index 87d4c9c5cc..771153f5e7 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -956,3 +956,32 @@ func (suite *GlideTestSuite) TestHStrLen_WithNotExistingField() { assert.Equal(suite.T(), int64(0), res2.Value()) }) } + +func (suite *GlideTestSuite) TestDel_MultipleKeys() { + suite.runWithDefaultClients(func(client api.BaseClient) { + key1 := "testKey1" + key2 := "testKey2" + key3 := "testKey3" + suite.verifyOK(client.Set(key1, initialValue)) + suite.verifyOK(client.Set(key2, initialValue)) + suite.verifyOK(client.Set(key3, initialValue)) + + deletedCount, err := client.Del(key1, key2, key3) + + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), int64(3), deletedCount) + + result1, err1 := client.Get(key1) + result2, err2 := client.Get(key2) + result3, err3 := client.Get(key3) + + assert.Nil(suite.T(), err1) + assert.Equal(suite.T(), "", result1) + + assert.Nil(suite.T(), err2) + assert.Equal(suite.T(), "", result2) + + assert.Nil(suite.T(), err3) + assert.Equal(suite.T(), "", result3) + }) +}