Skip to content

Commit

Permalink
Remove set type
Browse files Browse the repository at this point in the history
Signed-off-by: umit <umit.unal.89@gmail.com>
  • Loading branch information
umit committed Oct 3, 2024
1 parent 93ec8c0 commit c2fd14c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
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
26 changes: 4 additions & 22 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 All @@ -87,7 +79,7 @@ pub enum ResponseType {
/// `index_ptr` is a baton-pass back to the caller language to uniquely identify the promise.
/// `message` is the value returned by the command. The 'message' is managed by Rust and is freed when the callback returns control back to the caller.
pub type SuccessCallback =
unsafe extern "C" fn(index_ptr: usize, message: *const CommandResponse) -> ();
unsafe extern "C" fn(index_ptr: usize, message: *const CommandResponse) -> ();

/// Failure callback that is called when a command fails.
///
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 @@ -309,8 +300,6 @@ fn free_command_response_elements(command_response: CommandResponse) {
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 +317,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 +464,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 c2fd14c

Please sign in to comment.