Skip to content

Commit

Permalink
Remove set type
Browse files Browse the repository at this point in the history
Signed-off-by: umit <[email protected]>
  • Loading branch information
umit committed Oct 7, 2024
1 parent 93ec8c0 commit 7e949bb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 28 deletions.
1 change: 0 additions & 1 deletion go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ func (client *baseClient) RPush(key string, elements []string) (Result[int64], e
return handleLongResponse(result)
}


func (client *baseClient) SAdd(key string, members []string) (Result[int64], error) {
result, err := client.executeCommand(C.SAdd, append([]string{key}, members...))
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions go/api/response_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ func handleStringToStringMapResponse(response *C.struct_CommandResponse) (map[Re
func handleStringSetResponse(response *C.struct_CommandResponse) (map[Result[string]]struct{}, error) {
defer C.free_command_response(response)

typeErr := checkResponseType(response, C.Sets, false)
typeErr := checkResponseType(response, C.Array, false)
if typeErr != nil {
return nil, typeErr
}

slice := make(map[Result[string]]struct{}, response.sets_value_len)
for _, v := range unsafe.Slice(response.sets_value, response.sets_value_len) {
slice := make(map[Result[string]]struct{}, response.array_value_len)
for _, v := range unsafe.Slice(response.array_value, response.array_value_len) {
res, err := convertCharArrayToString(&v, true)
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion go/integTest/shared_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,6 @@ func (suite *GlideTestSuite) TestRPush() {
})
}


func (suite *GlideTestSuite) TestSAdd() {
suite.runWithDefaultClients(func(client api.BaseClient) {
key := uuid.NewString()
Expand Down
26 changes: 3 additions & 23 deletions go/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ pub struct CommandResponse {
map_key: *mut CommandResponse,
#[derivative(Default(value = "std::ptr::null_mut()"))]
map_value: *mut CommandResponse,

/// Below two values are related to each other.
/// `sets_value` represents the set of CommandResponse.
/// `sets_value_len` represents the length of the set.
#[derivative(Default(value = "std::ptr::null_mut()"))]
sets_value: *mut CommandResponse,
sets_value_len: c_long,
}

#[repr(C)]
Expand All @@ -77,7 +70,6 @@ pub enum ResponseType {
String = 4,
Array = 5,
Map = 6,
Sets = 7,
}

/// Success callback that is called when a command succeeds.
Expand Down Expand Up @@ -252,7 +244,6 @@ pub extern "C" fn get_response_type_string(response_type: ResponseType) -> *mut
ResponseType::String => "String",
ResponseType::Array => "Array",
ResponseType::Map => "Map",
ResponseType::Sets => "Sets",
};
let c_str = CString::new(s).unwrap_or_default();
c_str.into_raw()
Expand Down Expand Up @@ -300,17 +291,13 @@ pub unsafe extern "C" fn free_command_response(command_response_ptr: *mut Comman
/// * The contained `map_key` must be valid until `free_command_response` is called and it must outlive the `CommandResponse` that contains it.
/// * The contained `map_value` must be obtained from the `CommandResponse` returned in [`SuccessCallback`] from [`command`].
/// * The contained `map_value` must be valid until `free_command_response` is called and it must outlive the `CommandResponse` that contains it.
/// * The contained `sets_value` must be obtained from the `CommandResponse` returned in [`SuccessCallback`] from [`command`].
/// * The contained `sets_value` must be valid until `free_command_response` is called and it must outlive the `CommandResponse` that contains it.
fn free_command_response_elements(command_response: CommandResponse) {
let string_value = command_response.string_value;
let string_value_len = command_response.string_value_len;
let array_value = command_response.array_value;
let array_value_len = command_response.array_value_len;
let map_key = command_response.map_key;
let map_value = command_response.map_value;
let sets_value = command_response.sets_value;
let sets_value_len = command_response.sets_value_len;
if !string_value.is_null() {
let len = string_value_len as usize;
unsafe { Vec::from_raw_parts(string_value, len, len) };
Expand All @@ -328,13 +315,6 @@ fn free_command_response_elements(command_response: CommandResponse) {
if !map_value.is_null() {
unsafe { free_command_response(map_value) };
}
if !sets_value.is_null() {
let len = sets_value_len as usize;
let vec = unsafe { Vec::from_raw_parts(sets_value, len, len) };
for element in vec.into_iter() {
free_command_response_elements(element);
}
}
}

/// Frees the error_message received on a command failure.
Expand Down Expand Up @@ -482,9 +462,9 @@ fn valkey_value_to_command_response(value: Value) -> RedisResult<CommandResponse
})
.collect();
let (vec_ptr, len) = convert_vec_to_pointer(vec);
command_response.sets_value = vec_ptr;
command_response.sets_value_len = len;
command_response.response_type = ResponseType::Sets;
command_response.array_value = vec_ptr;
command_response.array_value_len = len;
command_response.response_type = ResponseType::Array;
Ok(command_response)
}
// TODO: Add support for other return types.
Expand Down

0 comments on commit 7e949bb

Please sign in to comment.