Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Command to SingleCommand in proto. #1385

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 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},
redis_request::{redis_request, single_command},
redis_request::{RedisRequest, RequestType, SingleCommand},
rotating_buffer::RotatingBuffer,
};
use integer_encoding::VarInt;
Expand Down Expand Up @@ -166,16 +166,16 @@ fn split_data() -> Vec<Vec<u8>> {
fn create_request(args: Vec<String>, args_pointer: bool) -> RedisRequest {
let mut request = RedisRequest::new();
request.callback_idx = 1;
let mut command = Command::new();
let mut command = SingleCommand::new();
command.request_type = RequestType::CustomCommand.into();
if args_pointer {
command.args = Some(command::Args::ArgsVecPointer(Box::leak(Box::new(args))
as *mut Vec<String>
as u64));
command.args = Some(single_command::Args::ArgsVecPointer(
Box::leak(Box::new(args)) as *mut Vec<String> as u64,
));
} else {
let mut args_array = command::ArgsArray::new();
let mut args_array = single_command::ArgsArray::new();
args_array.args = args.into_iter().map(|str| str.into()).collect();
command.args = Some(command::Args::ArgsArray(args_array));
command.args = Some(single_command::Args::ArgsArray(args_array));
}
request.command = Some(redis_request::Command::SingleCommand(command));
request
Expand Down
6 changes: 3 additions & 3 deletions glide-core/src/protobuf/redis_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ enum RequestType {
ZUnion = 136;
}

message Command {
message SingleCommand {
message ArgsArray {
repeated string args = 1;
}
Expand All @@ -198,14 +198,14 @@ message ScriptInvocation {
}

message Transaction {
repeated Command commands = 1;
repeated SingleCommand commands = 1;
}

message RedisRequest {
uint32 callback_idx = 1;

oneof command {
Command single_command = 2;
SingleCommand single_command = 2;
Transaction transaction = 3;
ScriptInvocation script_invocation = 4;
}
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 @@ -64,8 +64,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::redis_request::{redis_request, single_command};
use crate::redis_request::{RedisRequest, RequestType, SingleCommand};
use bytes::BufMut;
use rand::{distributions::Alphanumeric, Rng};
use rstest::rstest;
Expand All @@ -85,16 +85,16 @@ mod tests {
) -> RedisRequest {
let mut request = RedisRequest::new();
request.callback_idx = callback_index;
let mut command = Command::new();
let mut command = SingleCommand::new();
command.request_type = request_type.into();
if args_pointer {
command.args = Some(command::Args::ArgsVecPointer(Box::leak(Box::new(args))
as *mut Vec<String>
as u64));
command.args = Some(single_command::Args::ArgsVecPointer(
Box::leak(Box::new(args)) as *mut Vec<String> as u64,
));
} else {
let mut args_array = command::ArgsArray::new();
let mut args_array = single_command::ArgsArray::new();
args_array.args = args.into_iter().map(|str| str.into()).collect();
command.args = Some(command::Args::ArgsArray(args_array));
command.args = Some(single_command::Args::ArgsArray(args_array));
}
request.command = Some(redis_request::Command::SingleCommand(command));
request
Expand Down
11 changes: 6 additions & 5 deletions glide-core/src/socket_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::client::Client;
use crate::connection_request::ConnectionRequest;
use crate::errors::{error_message, error_type, RequestErrorType};
use crate::redis_request::{
command, redis_request, Command, RedisRequest, Routes, ScriptInvocation, SlotTypes, Transaction,
redis_request, single_command, RedisRequest, Routes, ScriptInvocation, SingleCommand,
SlotTypes, Transaction,
};
use crate::response;
use crate::response::Response;
Expand Down Expand Up @@ -256,12 +257,12 @@ async fn write_to_writer(response: Response, writer: &Rc<Writer>) -> Result<(),
}
}

fn get_command(request: &Command) -> Option<Cmd> {
fn get_command(request: &SingleCommand) -> Option<Cmd> {
let request_type: crate::request_type::RequestType = request.request_type.into();
request_type.get_command()
}

fn get_redis_command(command: &Command) -> Result<Cmd, ClienUsageError> {
fn get_redis_command(command: &SingleCommand) -> Result<Cmd, ClienUsageError> {
let Some(mut cmd) = get_command(command) else {
return Err(ClienUsageError::Internal(format!(
"Received invalid request type: {:?}",
Expand All @@ -270,12 +271,12 @@ fn get_redis_command(command: &Command) -> Result<Cmd, ClienUsageError> {
};

match &command.args {
Some(command::Args::ArgsArray(args_vec)) => {
Some(single_command::Args::ArgsArray(args_vec)) => {
for arg in args_vec.args.iter() {
cmd.arg(arg.as_bytes());
}
}
Some(command::Args::ArgsVecPointer(pointer)) => {
Some(single_command::Args::ArgsVecPointer(pointer)) => {
let res = *unsafe { Box::from_raw(*pointer as *mut Vec<String>) };
for arg in res {
cmd.arg(arg.as_bytes());
Expand Down
8 changes: 4 additions & 4 deletions glide-core/tests/test_socket_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ 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 glide_core::redis_request::single_command::{Args, ArgsArray};
use glide_core::redis_request::{SingleCommand, Transaction};
use glide_core::response::{response, ConstantResponse, Response};
use glide_core::scripts_container::add_script;
use protobuf::{EnumOrUnknown, Message};
Expand Down Expand Up @@ -236,8 +236,8 @@ mod socket_listener {
let _res = buffer.write_all(&request.write_to_bytes().unwrap());
}

fn get_command(components: CommandComponents) -> Command {
let mut command = Command::new();
fn get_command(components: CommandComponents) -> SingleCommand {
let mut command = SingleCommand::new();
command.request_type = components.request_type;
if components.args_pointer {
command.args = Some(Args::ArgsVecPointer(Box::leak(Box::new(components.args))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@
import lombok.Getter;
import lombok.NonNull;
import org.apache.commons.lang3.ArrayUtils;
import redis_request.RedisRequestOuterClass.Command;
import redis_request.RedisRequestOuterClass.Command.ArgsArray;
import redis_request.RedisRequestOuterClass.RequestType;
import redis_request.RedisRequestOuterClass.SingleCommand;
import redis_request.RedisRequestOuterClass.SingleCommand.ArgsArray;
import redis_request.RedisRequestOuterClass.Transaction;

/**
Expand Down Expand Up @@ -2719,14 +2719,14 @@ public T geoadd(
return geoadd(key, membersToGeospatialData, new GeoAddOptions(false));
}

/** Build protobuf {@link Command} object for given command and arguments. */
protected Command buildCommand(RequestType requestType) {
/** Build protobuf {@link SingleCommand} object for given command and arguments. */
protected SingleCommand buildCommand(RequestType requestType) {
return buildCommand(requestType, buildArgs());
}

/** Build protobuf {@link Command} object for given command and arguments. */
protected Command buildCommand(RequestType requestType, ArgsArray args) {
return Command.newBuilder().setRequestType(requestType).setArgsArray(args).build();
/** Build protobuf {@link SingleCommand} object for given command and arguments. */
protected SingleCommand buildCommand(RequestType requestType, ArgsArray args) {
return SingleCommand.newBuilder().setRequestType(requestType).setArgsArray(args).build();
}

/** Build protobuf {@link ArgsArray} object for given arguments. */
Expand Down
4 changes: 2 additions & 2 deletions java/client/src/main/java/glide/api/models/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static redis_request.RedisRequestOuterClass.RequestType.Select;

import lombok.AllArgsConstructor;
import redis_request.RedisRequestOuterClass;
import redis_request.RedisRequestOuterClass.SingleCommand.ArgsArray;

/**
* Extends BaseTransaction class for Redis standalone commands. Transactions allow the execution of
Expand Down Expand Up @@ -41,7 +41,7 @@ protected Transaction getThis() {
* @return Command Response - A simple <code>OK</code> response.
*/
public Transaction select(long index) {
RedisRequestOuterClass.Command.ArgsArray commandArgs = buildArgs(Long.toString(index));
ArgsArray commandArgs = buildArgs(Long.toString(index));

protobufTransaction.addCommands(buildCommand(Select, commandArgs));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import redis_request.RedisRequestOuterClass.Command;
import redis_request.RedisRequestOuterClass.SingleCommand;

/**
* Optional arguments for {@link StringBaseCommands#set(String, String, SetOptions)} command.
Expand Down Expand Up @@ -143,7 +143,7 @@ protected enum ExpiryType {
public static final String RETURN_OLD_VALUE = "GET";

/**
* Converts SetOptions into a String[] to add to a {@link Command} arguments.
* Converts SetOptions into a String[] to add to a {@link SingleCommand} arguments.
*
* @return String[]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import java.util.concurrent.CompletableFuture;
import lombok.RequiredArgsConstructor;
import redis_request.RedisRequestOuterClass;
import redis_request.RedisRequestOuterClass.Command;
import redis_request.RedisRequestOuterClass.Command.ArgsArray;
import redis_request.RedisRequestOuterClass.RedisRequest;
import redis_request.RedisRequestOuterClass.RequestType;
import redis_request.RedisRequestOuterClass.Routes;
import redis_request.RedisRequestOuterClass.ScriptInvocation;
import redis_request.RedisRequestOuterClass.SimpleRoutes;
import redis_request.RedisRequestOuterClass.SingleCommand;
import redis_request.RedisRequestOuterClass.SingleCommand.ArgsArray;
import redis_request.RedisRequestOuterClass.SlotTypes;
import response.ResponseOuterClass.Response;

Expand Down Expand Up @@ -168,7 +168,7 @@ protected RedisRequest.Builder prepareRedisRequest(
var builder =
RedisRequest.newBuilder()
.setSingleCommand(
Command.newBuilder()
SingleCommand.newBuilder()
.setRequestType(requestType)
.setArgsArray(commandArgs.build())
.build());
Expand Down Expand Up @@ -240,7 +240,7 @@ protected RedisRequest.Builder prepareRedisRequest(RequestType requestType, Stri

return RedisRequest.newBuilder()
.setSingleCommand(
Command.newBuilder()
SingleCommand.newBuilder()
.setRequestType(requestType)
.setArgsArray(commandArgs.build())
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Test;
import redis_request.RedisRequestOuterClass;
import redis_request.RedisRequestOuterClass.Command.ArgsArray;
import redis_request.RedisRequestOuterClass.RequestType;
import redis_request.RedisRequestOuterClass.SingleCommand;
import redis_request.RedisRequestOuterClass.SingleCommand.ArgsArray;

public class StandaloneTransactionTests {
@Test
public void standalone_transaction_commands() {
List<Pair<RedisRequestOuterClass.RequestType, RedisRequestOuterClass.Command.ArgsArray>>
results = new LinkedList<>();
List<Pair<RequestType, ArgsArray>> results = new LinkedList<>();
Transaction transaction = new Transaction();

transaction.select(5L);
Expand All @@ -24,7 +24,7 @@ public void standalone_transaction_commands() {
var protobufTransaction = transaction.getProtobufTransaction().build();

for (int idx = 0; idx < protobufTransaction.getCommandsCount(); idx++) {
RedisRequestOuterClass.Command protobuf = protobufTransaction.getCommands(idx);
SingleCommand protobuf = protobufTransaction.getCommands(idx);

assertEquals(results.get(idx).getLeft(), protobuf.getRequestType());
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import redis_request.RedisRequestOuterClass.Command;
import redis_request.RedisRequestOuterClass.Command.ArgsArray;
import redis_request.RedisRequestOuterClass.RequestType;
import redis_request.RedisRequestOuterClass.SingleCommand;
import redis_request.RedisRequestOuterClass.SingleCommand.ArgsArray;

public class TransactionTests {
private static Stream<Arguments> getTransactionBuilders() {
Expand Down Expand Up @@ -657,7 +657,7 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)),
var protobufTransaction = transaction.getProtobufTransaction().build();

for (int idx = 0; idx < protobufTransaction.getCommandsCount(); idx++) {
Command protobuf = protobufTransaction.getCommands(idx);
SingleCommand protobuf = protobufTransaction.getCommands(idx);

assertEquals(results.get(idx).getLeft(), protobuf.getRequestType());
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.mockito.ArgumentCaptor;
import redis_request.RedisRequestOuterClass.RedisRequest;
import redis_request.RedisRequestOuterClass.SimpleRoutes;
import redis_request.RedisRequestOuterClass.SingleCommand;
import redis_request.RedisRequestOuterClass.SlotTypes;
import response.ResponseOuterClass.Response;

Expand Down Expand Up @@ -302,8 +303,7 @@ public void submitNewCommand_with_Transaction_sends_protobuf_request() {
resultPayloads.add("one");
resultPayloads.add("two");
resultPayloads.add("three");
for (redis_request.RedisRequestOuterClass.Command command :
requestBuilder.getTransaction().getCommandsList()) {
for (SingleCommand command : requestBuilder.getTransaction().getCommandsList()) {
assertEquals(CustomCommand, command.getRequestType());
assertEquals("GETSTRING", command.getArgsArray().getArgs(0));
assertEquals(resultPayloads.pop(), command.getArgsArray().getArgs(1));
Expand Down
10 changes: 5 additions & 5 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ export class BaseClient {
*/
protected createWritePromise<T>(
command:
| redis_request.Command
| redis_request.Command[]
| redis_request.SingleCommand
| redis_request.SingleCommand[]
| redis_request.ScriptInvocation,
route?: redis_request.Routes,
): Promise<T> {
Expand All @@ -377,8 +377,8 @@ export class BaseClient {
private writeOrBufferRedisRequest(
callbackIdx: number,
command:
| redis_request.Command
| redis_request.Command[]
| redis_request.SingleCommand
| redis_request.SingleCommand[]
| redis_request.ScriptInvocation,
route?: redis_request.Routes,
) {
Expand All @@ -389,7 +389,7 @@ export class BaseClient {
commands: command,
}),
})
: command instanceof redis_request.Command
: command instanceof redis_request.SingleCommand
? redis_request.RedisRequest.create({
callbackIdx,
singleCommand: command,
Expand Down
Loading
Loading