Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into java/integ_yuryf_FC…
Browse files Browse the repository at this point in the history
…ALL_RO

Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Jun 15, 2024
2 parents 0ca35e5 + 0b30286 commit 2a4ea43
Show file tree
Hide file tree
Showing 38 changed files with 2,720 additions and 111 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
* Python: Added ZINTER, ZUNION commands ([#1478](https://github.com/aws/glide-for-redis/pull/1478))
* Python: Added SINTERCARD command ([#1511](https://github.com/aws/glide-for-redis/pull/1511))
* Python: Added SORT command ([#1439](https://github.com/aws/glide-for-redis/pull/1439))
* Node: Added OBJECT ENCODING command ([#1518](https://github.com/aws/glide-for-redis/pull/1518))
* Node: Added OBJECT ENCODING command ([#1518](https://github.com/aws/glide-for-redis/pull/1518), [#1559](https://github.com/aws/glide-for-redis/pull/1559))
* Python: Added LMOVE and BLMOVE commands ([#1536](https://github.com/aws/glide-for-redis/pull/1536))
* Node: Added SUNIONSTORE command ([#1549](https://github.com/aws/glide-for-redis/pull/1549))
* Node: Added PFCOUNT command ([#1545](https://github.com/aws/glide-for-redis/pull/1545))
* Node: Added OBJECT FREQ command ([#1542](https://github.com/aws/glide-for-redis/pull/1542))
* Node: Added OBJECT FREQ command ([#1542](https://github.com/aws/glide-for-redis/pull/1542), [#1559](https://github.com/aws/glide-for-redis/pull/1559))
* Node: Added LINSERT command ([#1544](https://github.com/aws/glide-for-redis/pull/1544))
* Node: Added XLEN command ([#1555](https://github.com/aws/glide-for-redis/pull/1555))
* Node: Added ZINTERCARD command ([#1553](https://github.com/aws/glide-for-redis/pull/1553))
* Python: Added LMPOP and BLMPOP commands ([#1547](https://github.com/aws/glide-for-redis/pull/1547))
* Node: Added OBJECT IDLETIME command ([#1567](https://github.com/aws/glide-for-redis/pull/1567))
* Node: Added OBJECT REFCOUNT command ([#1568](https://github.com/aws/glide-for-redis/pull/1568))
* Python: Added SETBIT command ([#1571](https://github.com/aws/glide-for-redis/pull/1571))

### Breaking Changes
* Node: Update XREAD to return a Map of Map ([#1494](https://github.com/aws/glide-for-redis/pull/1494))
Expand Down
4 changes: 2 additions & 2 deletions glide-core/THIRD_PARTY_LICENSES_RUST
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----

Package: backtrace:0.3.72
Package: backtrace:0.3.73

The following copyrights and licenses were found in the source code of this package:

Expand Down Expand Up @@ -14496,7 +14496,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----

Package: object:0.35.0
Package: object:0.36.0

The following copyrights and licenses were found in the source code of this package:

Expand Down
261 changes: 261 additions & 0 deletions glide-core/src/client/value_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub(crate) enum ExpectedReturnType<'a> {
ArrayOfMemberScorePairs,
ZMPopReturnType,
KeyWithMemberAndScore,
FunctionStatsReturnType,
}

pub(crate) fn convert_to_expected_type(
Expand Down Expand Up @@ -442,6 +443,87 @@ pub(crate) fn convert_to_expected_type(
)
.into()),
},
// `FUNCTION STATS` returns nested maps with different types of data
/* RESP2 response example
1) "running_script"
2) 1) "name"
2) "<function name>"
3) "command"
4) 1) "fcall"
2) "<function name>"
... rest `fcall` args ...
5) "duration_ms"
6) (integer) 24529
3) "engines"
4) 1) "LUA"
2) 1) "libraries_count"
2) (integer) 3
3) "functions_count"
4) (integer) 5
1) "running_script"
2) (nil)
3) "engines"
4) ...
RESP3 response example
1# "running_script" =>
1# "name" => "<function name>"
2# "command" =>
1) "fcall"
2) "<function name>"
... rest `fcall` args ...
3# "duration_ms" => (integer) 5000
2# "engines" =>
1# "LUA" =>
1# "libraries_count" => (integer) 3
2# "functions_count" => (integer) 5
*/
// First part of the response (`running_script`) is converted as `Map[str, any]`
// Second part is converted as `Map[str, Map[str, int]]`
ExpectedReturnType::FunctionStatsReturnType => match value {
// TODO reuse https://github.com/Bit-Quill/glide-for-redis/pull/331 and https://github.com/aws/glide-for-redis/pull/1489
Value::Map(map) => {
if map[0].0 == Value::BulkString(b"running_script".into()) {
// already a RESP3 response - do nothing
Ok(Value::Map(map))
} else {
// cluster (multi-node) response - go recursive
convert_map_entries(
map,
Some(ExpectedReturnType::BulkString),
Some(ExpectedReturnType::FunctionStatsReturnType),
)
}
}
Value::Array(mut array) if array.len() == 4 => {
let mut result: Vec<(Value, Value)> = Vec::with_capacity(2);
let running_script_info = array.remove(1);
let running_script_converted = match running_script_info {
Value::Nil => Ok(Value::Nil),
Value::Array(inner_map_as_array) => {
convert_array_to_map_by_type(inner_map_as_array, None, None)
}
_ => Err((ErrorKind::TypeError, "Response couldn't be converted").into()),
};
result.push((array.remove(0), running_script_converted?));
let Value::Array(engines_info) = array.remove(1) else {
return Err((ErrorKind::TypeError, "Incorrect value type received").into());
};
let engines_info_converted = convert_array_to_map_by_type(
engines_info,
Some(ExpectedReturnType::BulkString),
Some(ExpectedReturnType::Map {
key_type: &None,
value_type: &None,
}),
);
result.push((array.remove(0), engines_info_converted?));

Ok(Value::Map(result))
}
_ => Err((ErrorKind::TypeError, "Response couldn't be converted").into()),
},
}
}

Expand Down Expand Up @@ -740,6 +822,7 @@ pub(crate) fn expected_type_for_cmd(cmd: &Cmd) -> Option<ExpectedReturnType> {
b"FUNCTION LIST" => Some(ExpectedReturnType::ArrayOfMaps(
&ExpectedReturnType::ArrayOfMaps(&ExpectedReturnType::StringOrSet),
)),
b"FUNCTION STATS" => Some(ExpectedReturnType::FunctionStatsReturnType),
_ => None,
}
}
Expand Down Expand Up @@ -1297,6 +1380,184 @@ mod tests {
);
}

#[test]
fn convert_function_stats() {
assert!(matches!(
expected_type_for_cmd(redis::cmd("FUNCTION").arg("STATS")),
Some(ExpectedReturnType::FunctionStatsReturnType)
));

let resp2_response_non_empty_first_part_data = vec![
Value::BulkString(b"running_script".into()),
Value::Array(vec![
Value::BulkString(b"name".into()),
Value::BulkString(b"<function name>".into()),
Value::BulkString(b"command".into()),
Value::Array(vec![
Value::BulkString(b"fcall".into()),
Value::BulkString(b"<function name>".into()),
Value::BulkString(b"... rest `fcall` args ...".into()),
]),
Value::BulkString(b"duration_ms".into()),
Value::Int(24529),
]),
];

let resp2_response_empty_first_part_data =
vec![Value::BulkString(b"running_script".into()), Value::Nil];

let resp2_response_second_part_data = vec![
Value::BulkString(b"engines".into()),
Value::Array(vec![
Value::BulkString(b"LUA".into()),
Value::Array(vec![
Value::BulkString(b"libraries_count".into()),
Value::Int(3),
Value::BulkString(b"functions_count".into()),
Value::Int(5),
]),
]),
];
let resp2_response_with_non_empty_first_part = Value::Array(
[
resp2_response_non_empty_first_part_data.clone(),
resp2_response_second_part_data.clone(),
]
.concat(),
);

let resp2_response_with_empty_first_part = Value::Array(
[
resp2_response_empty_first_part_data.clone(),
resp2_response_second_part_data.clone(),
]
.concat(),
);

let resp2_cluster_response = Value::Map(vec![
(
Value::BulkString(b"node1".into()),
resp2_response_with_non_empty_first_part.clone(),
),
(
Value::BulkString(b"node2".into()),
resp2_response_with_empty_first_part.clone(),
),
(
Value::BulkString(b"node3".into()),
resp2_response_with_empty_first_part.clone(),
),
]);

let resp3_response_non_empty_first_part_data = vec![(
Value::BulkString(b"running_script".into()),
Value::Map(vec![
(
Value::BulkString(b"name".into()),
Value::BulkString(b"<function name>".into()),
),
(
Value::BulkString(b"command".into()),
Value::Array(vec![
Value::BulkString(b"fcall".into()),
Value::BulkString(b"<function name>".into()),
Value::BulkString(b"... rest `fcall` args ...".into()),
]),
),
(Value::BulkString(b"duration_ms".into()), Value::Int(24529)),
]),
)];

let resp3_response_empty_first_part_data =
vec![(Value::BulkString(b"running_script".into()), Value::Nil)];

let resp3_response_second_part_data = vec![(
Value::BulkString(b"engines".into()),
Value::Map(vec![(
Value::BulkString(b"LUA".into()),
Value::Map(vec![
(Value::BulkString(b"libraries_count".into()), Value::Int(3)),
(Value::BulkString(b"functions_count".into()), Value::Int(5)),
]),
)]),
)];

let resp3_response_with_non_empty_first_part = Value::Map(
[
resp3_response_non_empty_first_part_data.clone(),
resp3_response_second_part_data.clone(),
]
.concat(),
);

let resp3_response_with_empty_first_part = Value::Map(
[
resp3_response_empty_first_part_data.clone(),
resp3_response_second_part_data.clone(),
]
.concat(),
);

let resp3_cluster_response = Value::Map(vec![
(
Value::BulkString(b"node1".into()),
resp3_response_with_non_empty_first_part.clone(),
),
(
Value::BulkString(b"node2".into()),
resp3_response_with_empty_first_part.clone(),
),
(
Value::BulkString(b"node3".into()),
resp3_response_with_empty_first_part.clone(),
),
]);

let conversion_type = Some(ExpectedReturnType::FunctionStatsReturnType);
// resp2 -> resp3 conversion with non-empty `running_script` block
assert_eq!(
convert_to_expected_type(
resp2_response_with_non_empty_first_part.clone(),
conversion_type
),
Ok(resp3_response_with_non_empty_first_part.clone())
);
// resp2 -> resp3 conversion with empty `running_script` block
assert_eq!(
convert_to_expected_type(
resp2_response_with_empty_first_part.clone(),
conversion_type
),
Ok(resp3_response_with_empty_first_part.clone())
);
// resp2 -> resp3 cluster response
assert_eq!(
convert_to_expected_type(resp2_cluster_response.clone(), conversion_type),
Ok(resp3_cluster_response.clone())
);
// resp3 -> resp3 conversion with non-empty `running_script` block
assert_eq!(
convert_to_expected_type(
resp3_response_with_non_empty_first_part.clone(),
conversion_type
),
Ok(resp3_response_with_non_empty_first_part.clone())
);
// resp3 -> resp3 conversion with empty `running_script` block
assert_eq!(
convert_to_expected_type(
resp3_response_with_empty_first_part.clone(),
conversion_type
),
Ok(resp3_response_with_empty_first_part.clone())
);
// resp3 -> resp3 cluster response
assert_eq!(
convert_to_expected_type(resp3_cluster_response.clone(), conversion_type),
Ok(resp3_cluster_response.clone())
);
}

#[test]
fn convert_smismember() {
assert!(matches!(
Expand Down
4 changes: 4 additions & 0 deletions glide-core/src/protobuf/redis_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ enum RequestType {
BLMPop = 158;
XLen = 159;
Sort = 160;
FunctionKill = 161;
FunctionStats = 162;
FCallReadOnly = 163;
LSet = 165;
XDel = 166;
Expand All @@ -215,6 +217,8 @@ enum RequestType {
XRevRange = 176;
Copy = 178;
MSetNX = 179;
LPos = 180;
LCS = 181;
}

message Command {
Expand Down
12 changes: 12 additions & 0 deletions glide-core/src/request_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ pub enum RequestType {
BLMPop = 158,
XLen = 159,
Sort = 160,
FunctionKill = 161,
FunctionStats = 162,
FCallReadOnly = 163,
LSet = 165,
XDel = 166,
Expand All @@ -185,6 +187,8 @@ pub enum RequestType {
XRevRange = 176,
Copy = 178,
MSetNX = 179,
LPos = 180,
LCS = 181,
}

fn get_two_word_command(first: &str, second: &str) -> Cmd {
Expand Down Expand Up @@ -357,6 +361,8 @@ impl From<::protobuf::EnumOrUnknown<ProtobufRequestType>> for RequestType {
ProtobufRequestType::ExpireTime => RequestType::ExpireTime,
ProtobufRequestType::PExpireTime => RequestType::PExpireTime,
ProtobufRequestType::XLen => RequestType::XLen,
ProtobufRequestType::FunctionKill => RequestType::FunctionKill,
ProtobufRequestType::FunctionStats => RequestType::FunctionStats,
ProtobufRequestType::FCallReadOnly => RequestType::FCallReadOnly,
ProtobufRequestType::LSet => RequestType::LSet,
ProtobufRequestType::XDel => RequestType::XDel,
Expand All @@ -373,6 +379,8 @@ impl From<::protobuf::EnumOrUnknown<ProtobufRequestType>> for RequestType {
ProtobufRequestType::Sort => RequestType::Sort,
ProtobufRequestType::XRevRange => RequestType::XRevRange,
ProtobufRequestType::MSetNX => RequestType::MSetNX,
ProtobufRequestType::LPos => RequestType::LPos,
ProtobufRequestType::LCS => RequestType::LCS,
}
}
}
Expand Down Expand Up @@ -541,6 +549,8 @@ impl RequestType {
RequestType::ExpireTime => Some(cmd("EXPIRETIME")),
RequestType::PExpireTime => Some(cmd("PEXPIRETIME")),
RequestType::XLen => Some(cmd("XLEN")),
RequestType::FunctionKill => Some(get_two_word_command("FUNCTION", "KILL")),
RequestType::FunctionStats => Some(get_two_word_command("FUNCTION", "STATS")),
RequestType::FCallReadOnly => Some(cmd("FCALL_RO")),
RequestType::LSet => Some(cmd("LSET")),
RequestType::XDel => Some(cmd("XDEL")),
Expand All @@ -557,6 +567,8 @@ impl RequestType {
RequestType::Sort => Some(cmd("SORT")),
RequestType::XRevRange => Some(cmd("XREVRANGE")),
RequestType::MSetNX => Some(cmd("MSETNX")),
RequestType::LPos => Some(cmd("LPOS")),
RequestType::LCS => Some(cmd("LCS")),
}
}
}
Loading

0 comments on commit 2a4ea43

Please sign in to comment.