Skip to content

Commit

Permalink
Rename RedisRequest to CommandRequest (#1695)
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon authored Jul 7, 2024
1 parent 0edbfc3 commit e26f3a0
Show file tree
Hide file tree
Showing 43 changed files with 1,203 additions and 1,184 deletions.
20 changes: 10 additions & 10 deletions glide-core/benches/rotating_buffer_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::io::Write;
use bytes::BufMut;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use glide_core::{
redis_request::{command, redis_request},
redis_request::{Command, RedisRequest, RequestType},
command_request::{command, command_request},
command_request::{Command, CommandRequest, RequestType},
rotating_buffer::RotatingBuffer,
};
use integer_encoding::VarInt;
Expand Down Expand Up @@ -118,7 +118,7 @@ fn write_length(buffer: &mut Vec<u8>, length: u32) {
u32::encode_var(length, &mut buffer[new_len - required_space..]);
}

fn message_buffer(request: RedisRequest) -> Vec<u8> {
fn message_buffer(request: CommandRequest) -> Vec<u8> {
let message_length = request.compute_size() as usize;
let mut buffer = Vec::with_capacity(message_length);
write_length(&mut buffer, message_length as u32);
Expand Down Expand Up @@ -164,8 +164,8 @@ fn split_data() -> Vec<Vec<u8>> {
vec![vec, vec1, vec2]
}

fn create_request(args: Vec<bytes::Bytes>, args_pointer: bool) -> RedisRequest {
let mut request = RedisRequest::new();
fn create_request(args: Vec<bytes::Bytes>, args_pointer: bool) -> CommandRequest {
let mut request = CommandRequest::new();
request.callback_idx = 1;
let mut command = Command::new();
command.request_type = RequestType::CustomCommand.into();
Expand All @@ -178,15 +178,15 @@ fn create_request(args: Vec<bytes::Bytes>, args_pointer: bool) -> RedisRequest {
args_array.args = args;
command.args = Some(command::Args::ArgsArray(args_array));
}
request.command = Some(redis_request::Command::SingleCommand(command));
request.command = Some(command_request::Command::SingleCommand(command));
request
}

fn short_request() -> RedisRequest {
fn short_request() -> CommandRequest {
create_request(vec!["GET".into(), "goo".into(), "bar".into()], false)
}

fn medium_request() -> RedisRequest {
fn medium_request() -> CommandRequest {
create_request(
vec![
"GET".into(),
Expand All @@ -197,7 +197,7 @@ fn medium_request() -> RedisRequest {
)
}

fn long_request(args_pointer: bool) -> RedisRequest {
fn long_request(args_pointer: bool) -> CommandRequest {
create_request(
vec![
"GET".into(),
Expand All @@ -215,7 +215,7 @@ macro_rules! run_bench {
$test_name($c, "rotating_buffer", |test_data: &Vec<Vec<u8>>| {
for data in test_data {
$rotating_buffer.current_buffer().put(&data[..]);
$rotating_buffer.get_requests::<RedisRequest>().unwrap();
$rotating_buffer.get_requests::<CommandRequest>().unwrap();
}
$rotating_buffer.current_buffer().clear()
});
Expand Down
2 changes: 1 addition & 1 deletion glide-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn build_protobuf() {
protobuf_codegen::Codegen::new()
.cargo_out_dir("protobuf")
.include("src")
.input("src/protobuf/redis_request.proto")
.input("src/protobuf/command_request.proto")
.input("src/protobuf/response.proto")
.input("src/protobuf/connection_request.proto")
.customize(customization_options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package redis_request;
package command_request;

enum SimpleRoutes {
AllNodes=0;
Expand Down Expand Up @@ -286,7 +286,7 @@ message ClusterScan {
optional string object_type = 4;
}

message RedisRequest {
message CommandRequest {
uint32 callback_idx = 1;

oneof command {
Expand Down
2 changes: 1 addition & 1 deletion glide-core/src/request_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use redis::{cmd, Cmd};

#[cfg(feature = "socket-layer")]
use crate::redis_request::RequestType as ProtobufRequestType;
use crate::command_request::RequestType as ProtobufRequestType;

#[repr(C)]
#[derive(Debug)]
Expand Down
16 changes: 8 additions & 8 deletions glide-core/src/rotating_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl RotatingBuffer {
#[cfg(test)]
mod tests {
use super::*;
use crate::redis_request::{command, redis_request};
use crate::redis_request::{Command, RedisRequest, RequestType};
use crate::command_request::{command, command_request};
use crate::command_request::{Command, CommandRequest, RequestType};
use bytes::BufMut;
use rand::{distributions::Alphanumeric, Rng};
use rstest::rstest;
Expand All @@ -83,8 +83,8 @@ mod tests {
args: Vec<Bytes>,
request_type: RequestType,
args_pointer: bool,
) -> RedisRequest {
let mut request = RedisRequest::new();
) -> CommandRequest {
let mut request = CommandRequest::new();
request.callback_idx = callback_index;
let mut command = Command::new();
command.request_type = request_type.into();
Expand All @@ -97,7 +97,7 @@ mod tests {
args_array.args.clone_from(&args);
command.args = Some(command::Args::ArgsArray(args_array));
}
request.command = Some(redis_request::Command::SingleCommand(command));
request.command = Some(command_request::Command::SingleCommand(command));
request
}

Expand Down Expand Up @@ -141,14 +141,14 @@ mod tests {
}

fn assert_request(
request: &RedisRequest,
request: &CommandRequest,
expected_type: RequestType,
expected_index: u32,
expected_args: Vec<Bytes>,
args_pointer: bool,
) {
assert_eq!(request.callback_idx, expected_index);
let Some(redis_request::Command::SingleCommand(ref command)) = request.command else {
let Some(command_request::Command::SingleCommand(ref command)) = request.command else {
panic!("expected single command");
};
assert_eq!(command.request_type, expected_type.into());
Expand Down Expand Up @@ -312,7 +312,7 @@ mod tests {
let required_varint_length = u32::required_space(KEY_LENGTH as u32);
assert!(required_varint_length > 1); // so we could split the write of the varint
buffer.extend_from_slice(&request_bytes[..NUM_OF_LENGTH_BYTES]);
let requests = rotating_buffer.get_requests::<RedisRequest>().unwrap();
let requests = rotating_buffer.get_requests::<CommandRequest>().unwrap();
assert_eq!(requests.len(), 0);
let buffer = rotating_buffer.current_buffer();
buffer.extend_from_slice(&request_bytes[NUM_OF_LENGTH_BYTES..]);
Expand Down
33 changes: 16 additions & 17 deletions glide-core/src/socket_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
use super::rotating_buffer::RotatingBuffer;
use crate::client::Client;
use crate::cluster_scan_container::get_cluster_scan_cursor;
use crate::command_request::{
command, command_request, ClusterScan, Command, CommandRequest, Routes, SlotTypes, Transaction,
};
use crate::connection_request::ConnectionRequest;
use crate::errors::{error_message, error_type, RequestErrorType};
use crate::redis_request::{
command, redis_request, ClusterScan, Command, RedisRequest, Routes, SlotTypes, Transaction,
};
use crate::response;
use crate::response::Response;
use crate::retry_strategies::get_fixed_interval_backoff;
Expand Down Expand Up @@ -416,7 +416,7 @@ fn get_route(
route: Option<Box<Routes>>,
cmd: Option<&Cmd>,
) -> ClientUsageResult<Option<RoutingInfo>> {
use crate::redis_request::routes::Value;
use crate::command_request::routes::Value;
let Some(route) = route.and_then(|route| route.value) else {
return Ok(None);
};
Expand All @@ -432,17 +432,16 @@ fn get_route(
ClientUsageError::Internal(format!("Received unexpected simple route type {id}"))
})?;
match simple_route {
crate::redis_request::SimpleRoutes::AllNodes => Ok(Some(RoutingInfo::MultiNode((
MultipleNodeRoutingInfo::AllNodes,
get_response_policy(cmd),
)))),
crate::redis_request::SimpleRoutes::AllPrimaries => {
crate::command_request::SimpleRoutes::AllNodes => Ok(Some(RoutingInfo::MultiNode(
(MultipleNodeRoutingInfo::AllNodes, get_response_policy(cmd)),
))),
crate::command_request::SimpleRoutes::AllPrimaries => {
Ok(Some(RoutingInfo::MultiNode((
MultipleNodeRoutingInfo::AllMasters,
get_response_policy(cmd),
))))
}
crate::redis_request::SimpleRoutes::Random => {
crate::command_request::SimpleRoutes::Random => {
Ok(Some(RoutingInfo::SingleNode(SingleNodeRoutingInfo::Random)))
}
}
Expand Down Expand Up @@ -474,14 +473,14 @@ fn get_route(
}
}

fn handle_request(request: RedisRequest, client: Client, writer: Rc<Writer>) {
fn handle_request(request: CommandRequest, client: Client, writer: Rc<Writer>) {
task::spawn_local(async move {
let result = match request.command {
Some(action) => match action {
redis_request::Command::ClusterScan(cluster_scan_command) => {
command_request::Command::ClusterScan(cluster_scan_command) => {
cluster_scan(cluster_scan_command, client).await
}
redis_request::Command::SingleCommand(command) => {
command_request::Command::SingleCommand(command) => {
match get_redis_command(&command) {
Ok(cmd) => match get_route(request.route.0, Some(&cmd)) {
Ok(routes) => send_command(cmd, client, routes).await,
Expand All @@ -490,13 +489,13 @@ fn handle_request(request: RedisRequest, client: Client, writer: Rc<Writer>) {
Err(e) => Err(e),
}
}
redis_request::Command::Transaction(transaction) => {
command_request::Command::Transaction(transaction) => {
match get_route(request.route.0, None) {
Ok(routes) => send_transaction(transaction, client, routes).await,
Err(e) => Err(e),
}
}
redis_request::Command::ScriptInvocation(script) => {
command_request::Command::ScriptInvocation(script) => {
match get_route(request.route.0, None) {
Ok(routes) => {
invoke_script(
Expand All @@ -511,7 +510,7 @@ fn handle_request(request: RedisRequest, client: Client, writer: Rc<Writer>) {
Err(e) => Err(e),
}
}
redis_request::Command::ScriptInvocationPointers(script) => {
command_request::Command::ScriptInvocationPointers(script) => {
let keys = script
.keys_pointer
.map(|pointer| *unsafe { Box::from_raw(pointer as *mut Vec<Bytes>) });
Expand Down Expand Up @@ -543,7 +542,7 @@ fn handle_request(request: RedisRequest, client: Client, writer: Rc<Writer>) {
}

async fn handle_requests(
received_requests: Vec<RedisRequest>,
received_requests: Vec<CommandRequest>,
client: &Client,
writer: &Rc<Writer>,
) {
Expand Down
36 changes: 18 additions & 18 deletions glide-core/tests/test_socket_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ mod socket_listener {
use crate::utilities::mocks::{Mock, ServerMock};

use super::*;
use glide_core::redis_request::command::{Args, ArgsArray};
use glide_core::redis_request::{Command, Transaction};
use command_request::{CommandRequest, RequestType};
use glide_core::command_request::command::{Args, ArgsArray};
use glide_core::command_request::{Command, Transaction};
use glide_core::response::{response, ConstantResponse, Response};
use glide_core::scripts_container::add_script;
use protobuf::{EnumOrUnknown, Message};
use redis::{Cmd, ConnectionAddr, FromRedisValue, Value};
use redis_request::{RedisRequest, RequestType};
use rstest::rstest;
use std::mem::size_of;
use tokio::{net::UnixListener, runtime::Builder};
Expand Down Expand Up @@ -256,11 +256,11 @@ mod socket_listener {
args: Vec<bytes::Bytes>,
request_type: EnumOrUnknown<RequestType>,
args_pointer: bool,
) -> RedisRequest {
let mut request = RedisRequest::new();
) -> CommandRequest {
let mut request = CommandRequest::new();
request.callback_idx = callback_index;

request.command = Some(redis_request::redis_request::Command::SingleCommand(
request.command = Some(command_request::command_request::Command::SingleCommand(
get_command(CommandComponents {
args,
request_type,
Expand All @@ -270,7 +270,7 @@ mod socket_listener {
request
}

fn write_request(buffer: &mut Vec<u8>, socket: &mut UnixStream, request: RedisRequest) {
fn write_request(buffer: &mut Vec<u8>, socket: &mut UnixStream, request: CommandRequest) {
write_message(buffer, request);
socket.write_all(buffer).unwrap();
}
Expand All @@ -294,7 +294,7 @@ mod socket_listener {
callback_index: u32,
commands_components: Vec<CommandComponents>,
) {
let mut request = RedisRequest::new();
let mut request = CommandRequest::new();
request.callback_idx = callback_index;
let mut transaction = Transaction::new();
transaction.commands.reserve(commands_components.len());
Expand All @@ -303,7 +303,7 @@ mod socket_listener {
transaction.commands.push(get_command(components));
}

request.command = Some(redis_request::redis_request::Command::Transaction(
request.command = Some(command_request::command_request::Command::Transaction(
transaction,
));

Expand Down Expand Up @@ -685,8 +685,8 @@ mod socket_listener {
RequestType::CustomCommand.into(),
false,
);
let mut routes = redis_request::Routes::default();
routes.set_simple_routes(redis_request::SimpleRoutes::AllPrimaries);
let mut routes = command_request::Routes::default();
routes.set_simple_routes(command_request::SimpleRoutes::AllPrimaries);
request.route = Some(routes).into();
write_request(&mut buffer, &mut test_basics.socket, request);

Expand Down Expand Up @@ -733,8 +733,8 @@ mod socket_listener {
RequestType::CustomCommand.into(),
false,
);
let mut routes = redis_request::Routes::default();
routes.set_simple_routes(redis_request::SimpleRoutes::Random);
let mut routes = command_request::Routes::default();
routes.set_simple_routes(command_request::SimpleRoutes::Random);
request.route = Some(routes).into();
write_request(&mut buffer, &mut test_basics.socket, request.clone());

Expand All @@ -755,8 +755,8 @@ mod socket_listener {
.unwrap();

buffer.clear();
let mut routes = redis_request::Routes::default();
let by_address_route = glide_core::redis_request::ByAddressRoute {
let mut routes = command_request::Routes::default();
let by_address_route = glide_core::command_request::ByAddressRoute {
host: host.into(),
port,
..Default::default()
Expand Down Expand Up @@ -1216,10 +1216,10 @@ mod socket_listener {
let approx_message_length = hash.len() + value.len() + key.len() + APPROX_RESP_HEADER_LEN;
let mut buffer = Vec::with_capacity(approx_message_length);

let mut request = RedisRequest::new();
let mut request = CommandRequest::new();
request.callback_idx = CALLBACK_INDEX;
request.command = Some(redis_request::redis_request::Command::ScriptInvocation(
redis_request::ScriptInvocation {
request.command = Some(command_request::command_request::Command::ScriptInvocation(
command_request::ScriptInvocation {
hash: hash.into(),
keys: vec![key.into()],
args: vec![value.clone().into()],
Expand Down
2 changes: 1 addition & 1 deletion go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ generate-protobuf:
mkdir -p protobuf
protoc --proto_path=../glide-core/src/protobuf \
--go_opt=Mconnection_request.proto=github.com/aws/glide-for-redis/go/protobuf \
--go_opt=Mredis_request.proto=github.com/aws/glide-for-redis/go/protobuf \
--go_opt=Mcommand_request.proto=github.com/aws/glide-for-redis/go/protobuf \
--go_opt=Mresponse.proto=github.com/aws/glide-for-redis/go/protobuf \
--go_out=./protobuf \
--go_opt=paths=source_relative \
Expand Down
2 changes: 1 addition & 1 deletion java/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ A redis command can either have a standalone or cluster implementation which is
- A cluster command will require a note to indicate a node will follow a specific routing.
Refer to https://redis.io/docs/latest/operate/oss_and_stack/reference/cluster-spec for more details on how hash slots work for cluster commands.
When you start implementing a new command, check the [redis_request.proto](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/redis_request.proto) and [request_type.rs](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/request_type.rs) files to see whether the command has already been implemented in another language such as Python or Node.js.
When you start implementing a new command, check the [command_request.proto](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/protobuf/command_request.proto) and [request_type.rs](https://github.com/aws/glide-for-redis/blob/main/glide-core/src/request_type.rs) files to see whether the command has already been implemented in another language such as Python or Node.js.
Standalone and cluster clients both extend [BaseClient.java](https://github.com/aws/glide-for-redis/blob/main/java/client/src/main/java/glide/api/BaseClient.java) and implement methods from the interfaces listed in `java/client/src/main/java/glide/api/commands`.
The return types of these methods are in the form of a `CompletableFuture`, which fulfill the purpose of the asynchronous features of the program.
Expand Down
2 changes: 1 addition & 1 deletion java/client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tasks.register('protobuf', Exec) {
'-Iprotobuf=glide-core/src/protobuf/',
'--java_out=java/client/src/main/java/glide/models/protobuf',
'glide-core/src/protobuf/connection_request.proto',
'glide-core/src/protobuf/redis_request.proto',
'glide-core/src/protobuf/command_request.proto',
'glide-core/src/protobuf/response.proto'
workingDir Paths.get(project.rootDir.path, '..').toFile()
}
Expand Down
Loading

0 comments on commit e26f3a0

Please sign in to comment.