Skip to content

Commit cdb4fe7

Browse files
committed
Addressed GitHub Copilot review comments
Signed-off-by: currantw <[email protected]>
1 parent 5c2f3e7 commit cdb4fe7

File tree

2 files changed

+62
-61
lines changed

2 files changed

+62
-61
lines changed

rust/src/lib.rs

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ pub unsafe extern "C" fn init(level: Option<Level>, file_name: *const c_char) ->
446446
/// * `client_ptr` must be a valid Client pointer from create_client
447447
/// * `cursor` must be "0" for initial scan or a valid cursor ID from previous scan
448448
/// * `args` and `arg_lengths` must be valid arrays of length `arg_count`
449-
/// * `args` format: [b"MATCH", pattern, b"COUNT", count, b"TYPE", type] (all optional)
449+
/// * `args` format: [b"MATCH", pattern_arg, b"COUNT", count, b"TYPE", type] (all optional)
450450
#[unsafe(no_mangle)]
451451
pub unsafe extern "C-unwind" fn request_cluster_scan(
452452
client_ptr: *const c_void,
@@ -577,15 +577,16 @@ unsafe fn build_cluster_scan_args(
577577

578578
let arg_vec = unsafe { convert_double_pointer_to_vec(args, arg_count, arg_lengths) };
579579

580-
let mut pattern: &[u8] = &[];
581-
let mut object_type: &[u8] = &[];
582-
let mut count: &[u8] = &[];
580+
// Parse arguments from vector.
581+
let mut pattern_arg: &[u8] = &[];
582+
let mut type_arg: &[u8] = &[];
583+
let mut count_arg: &[u8] = &[];
583584

584585
let mut iter = arg_vec.iter().peekable();
585586
while let Some(arg) = iter.next() {
586587
match *arg {
587588
b"MATCH" => match iter.next() {
588-
Some(pat) => pattern = pat,
589+
Some(p) => pattern_arg = p,
589590
None => {
590591
unsafe {
591592
report_error(
@@ -599,7 +600,7 @@ unsafe fn build_cluster_scan_args(
599600
}
600601
},
601602
b"TYPE" => match iter.next() {
602-
Some(obj_type) => object_type = obj_type,
603+
Some(t) => type_arg = t,
603604
None => {
604605
unsafe {
605606
report_error(
@@ -613,7 +614,7 @@ unsafe fn build_cluster_scan_args(
613614
}
614615
},
615616
b"COUNT" => match iter.next() {
616-
Some(c) => count = c,
617+
Some(c) => count_arg = c,
617618
None => {
618619
unsafe {
619620
report_error(
@@ -640,66 +641,66 @@ unsafe fn build_cluster_scan_args(
640641
}
641642
}
642643

643-
// Convert back to proper types
644-
let converted_count = match std::str::from_utf8(count) {
645-
Ok(v) => {
646-
if !count.is_empty() {
647-
match v.parse::<u32>() {
648-
Ok(v) => v,
649-
Err(_) => {
650-
unsafe {
651-
report_error(
652-
failure_callback,
653-
callback_index,
654-
"Invalid COUNT value".into(),
655-
RequestErrorType::Unspecified,
656-
);
657-
}
658-
return None;
659-
}
644+
// Build cluster scan arguments.
645+
let mut cluster_scan_args_builder = redis::ClusterScanArgs::builder();
646+
647+
if !pattern_arg.is_empty() {
648+
cluster_scan_args_builder = cluster_scan_args_builder.with_match_pattern(pattern_arg);
649+
}
650+
651+
if !type_arg.is_empty() {
652+
let converted_type = match std::str::from_utf8(type_arg) {
653+
Ok(t) => redis::ObjectType::from(t.to_string()),
654+
Err(_) => {
655+
unsafe {
656+
report_error(
657+
failure_callback,
658+
callback_index,
659+
"Invalid UTF-8 in TYPE argument".into(),
660+
RequestErrorType::Unspecified,
661+
);
660662
}
661-
} else {
662-
10 // default count value
663+
return None;
663664
}
664-
}
665-
Err(_) => {
666-
unsafe {
667-
report_error(
668-
failure_callback,
669-
callback_index,
670-
"Invalid UTF-8 in COUNT argument".into(),
671-
RequestErrorType::Unspecified,
672-
);
665+
};
666+
667+
cluster_scan_args_builder = cluster_scan_args_builder.with_object_type(converted_type);
668+
}
669+
670+
if !count_arg.is_empty() {
671+
let count_str = match std::str::from_utf8(count_arg) {
672+
Ok(c) => c,
673+
Err(_) => {
674+
unsafe {
675+
report_error(
676+
failure_callback,
677+
callback_index,
678+
"Invalid UTF-8 in COUNT argument".into(),
679+
RequestErrorType::Unspecified,
680+
);
681+
}
682+
return None;
673683
}
674-
return None;
675-
}
676-
};
684+
};
677685

678-
let converted_type = match std::str::from_utf8(object_type) {
679-
Ok(v) => redis::ObjectType::from(v.to_string()),
680-
Err(_) => {
681-
unsafe {
682-
report_error(
683-
failure_callback,
684-
callback_index,
685-
"Invalid UTF-8 in TYPE argument".into(),
686-
RequestErrorType::Unspecified,
687-
);
686+
let converted_count = match count_str.parse::<u32>() {
687+
Ok(c) => c,
688+
Err(_) => {
689+
unsafe {
690+
report_error(
691+
failure_callback,
692+
callback_index,
693+
"Invalid COUNT value".into(),
694+
RequestErrorType::Unspecified,
695+
);
696+
}
697+
return None;
688698
}
689-
return None;
690-
}
691-
};
699+
};
692700

693-
let mut cluster_scan_args_builder = redis::ClusterScanArgs::builder();
694-
if !count.is_empty() {
695701
cluster_scan_args_builder = cluster_scan_args_builder.with_count(converted_count);
696702
}
697-
if !pattern.is_empty() {
698-
cluster_scan_args_builder = cluster_scan_args_builder.with_match_pattern(pattern);
699-
}
700-
if !object_type.is_empty() {
701-
cluster_scan_args_builder = cluster_scan_args_builder.with_object_type(converted_type);
702-
}
703+
703704
Some(cluster_scan_args_builder.build())
704705
}
705706

sources/Valkey.Glide/GlideClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public async IAsyncEnumerable<ValkeyKey> KeysAsync(int database = -1, ValkeyValu
178178
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
179179

180180
string currentCursor = cursor.ToString();
181-
long currentOffset = pageOffset;
181+
int currentOffset = pageOffset;
182182

183183
do
184184
{
@@ -190,7 +190,7 @@ public async IAsyncEnumerable<ValkeyKey> KeysAsync(int database = -1, ValkeyValu
190190

191191
if (currentOffset > 0)
192192
{
193-
keys = [.. keys.Skip(pageOffset)];
193+
keys = [.. keys.Skip(currentOffset)];
194194
currentOffset = 0;
195195
}
196196

0 commit comments

Comments
 (0)