Skip to content

Commit

Permalink
update method comments and style
Browse files Browse the repository at this point in the history
Signed-off-by: umit <[email protected]>
  • Loading branch information
umit committed Sep 20, 2024
1 parent 632d990 commit a5c3570
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
16 changes: 9 additions & 7 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (client *baseClient) MSet(keyValueMap map[string]string) (string, error) {
if err != nil {
return "", err
}

return handleStringResponse(result)
}

Expand All @@ -200,6 +201,7 @@ func (client *baseClient) Incr(key string) (int64, error) {
if err != nil {
return 0, err
}

return handleLongResponse(result)
}

Expand All @@ -208,6 +210,7 @@ func (client *baseClient) IncrBy(key string, amount int64) (int64, error) {
if err != nil {
return 0, err
}

return handleLongResponse(result)
}

Expand All @@ -228,6 +231,7 @@ func (client *baseClient) Decr(key string) (int64, error) {
if err != nil {
return 0, err
}

return handleLongResponse(result)
}

Expand All @@ -236,6 +240,7 @@ func (client *baseClient) DecrBy(key string, amount int64) (int64, error) {
if err != nil {
return 0, err
}

return handleLongResponse(result)
}

Expand All @@ -244,6 +249,7 @@ func (client *baseClient) Strlen(key string) (int64, error) {
if err != nil {
return 0, err
}

return handleLongResponse(result)
}

Expand All @@ -252,6 +258,7 @@ func (client *baseClient) SetRange(key string, offset int, value string) (int64,
if err != nil {
return 0, err
}

return handleLongResponse(result)
}

Expand Down Expand Up @@ -310,18 +317,13 @@ func (client *baseClient) HGetAll(key string) (map[string]string, error) {
return nil, err
}

res, err := handleStringToStringMapResponse(result)
if err != nil {
return nil, err
}

return res, nil
return handleStringToStringMapResponse(result)
}

func (client *baseClient) HMGet(key string, fields []string) ([]string, error) {
result, err := client.executeCommand(C.HMGet, append([]string{key}, fields...))
if err != nil {
return []string{}, err
return nil, err
}

return handleStringArrayResponse(result)
Expand Down
8 changes: 3 additions & 5 deletions go/api/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,10 @@ type HashCommands interface {
// 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 equals "value"
//
// payload, err = client.HGet("my_hash", "nonexistent_field")
// // payload equals ""
//
Expand Down Expand Up @@ -429,7 +430,7 @@ type HashCommands interface {
// Return value:
// 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, it is treated as an empty hash, and it returns an array of null values.
// If key does not exist, returns an empty string array.
//
// For example:
// values, err := client.HMGet("my_hash", []string{"field1", "field2"})
Expand Down Expand Up @@ -476,7 +477,6 @@ type HashCommands interface {
// For example:
// payload1, err := client.HSetNX("myHash", "field", "value")
// // payload1 equals true
//
// payload2, err := client.HSetNX("myHash", "field", "newValue")
// // payload2 equals false
//
Expand Down Expand Up @@ -517,7 +517,6 @@ type HashCommands interface {
// For example:
// num1, err := client.HLen("myHash")
// // num1 equals 3
//
// num2, err := client.HLen("nonExistingKey")
// // num2 equals 0
//
Expand Down Expand Up @@ -556,7 +555,6 @@ type HashCommands interface {
// For example:
// exists, err := client.HExists("my_hash", "field1")
// // exists equals true
//
// exists, err = client.HExists("my_hash", "non_existent_field")
// // exists equals false
//
Expand Down
11 changes: 4 additions & 7 deletions go/api/response_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,12 @@ func handleStringToStringMapResponse(response *C.struct_CommandResponse) (map[st
}

defer C.free_command_response(response)

result := make(map[string]string, response.array_value_len)
values := unsafe.Slice(response.array_value, response.array_value_len)

for _, v := range values {
m := make(map[string]string, response.array_value_len)
for _, v := range unsafe.Slice(response.array_value, response.array_value_len) {
key := convertCharArrayToString(v.map_key.string_value, v.map_key.string_value_len)
value := convertCharArrayToString(v.map_value.string_value, v.map_value.string_value_len)
result[key] = value
m[key] = value
}

return result, nil
return m, nil
}

0 comments on commit a5c3570

Please sign in to comment.