Skip to content

Commit

Permalink
rev 1 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
avifenesh committed Jul 11, 2023
1 parent 59f3385 commit 86aaa7f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
4 changes: 3 additions & 1 deletion babushka-core/src/protobuf/redis_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ enum RequestType {
GetString = 2;
/// Type of a set string request.
SetString = 3;
/// Type of a ping request.
Ping = 4;
}

message Command {
Expand All @@ -30,7 +32,7 @@ message Transaction {

message RedisRequest {
uint32 callback_idx = 1;

oneof command {
Command single_command = 2;
Transaction transaction = 3;
Expand Down
15 changes: 12 additions & 3 deletions node/src/ClusterSocketConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import * as net from "net";
import { connection_request } from "./ProtobufMessage";
import { ConnectionOptions, SocketConnection } from "./SocketConnection";

type Routes = "all_shards";
export type Routes =
| "all_primaries"
| "all_nodes"
| "multi_shard"
| "random"
| "master_slot"
| "replica_slot";
export class ClusterSocketConnection extends SocketConnection {
protected createConnectionRequest(
options: ConnectionOptions
Expand All @@ -22,10 +28,13 @@ export class ClusterSocketConnection extends SocketConnection {
);
}

/// Returns PONG if no argument is provided, otherwise return a copy of the argument as a bulk
/// Returns PONG if no argument is provided, otherwise return a copy of the argument
/// See https://redis.io/commands/ping/ for details.
// TODO: implement routing
public ping(str?: string, route: Routes = "all_shards"): Promise<string> {
public ping(
str?: string,
route: Routes = "all_primaries"
): Promise<string> {
return super.ping(str);
}
}
4 changes: 2 additions & 2 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export function createGet(key: string): redis_request.Command {
}

export function createPing(str?: string): redis_request.Command {
if (str) return createCommand(RequestType.GetString, [str]);
return createCommand(RequestType.GetString, []);
if (str !== undefined) return createCommand(RequestType.Ping, [str]);
return createCommand(RequestType.Ping, []);
}

export type SetOptions = {
Expand Down
2 changes: 1 addition & 1 deletion node/src/SocketConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class SocketConnection {
return this.createWritePromise(createSet(key, value, options));
}

/// Returns PONG if no argument is provided, otherwise return a copy of the argument as a bulk
/// Returns PONG if no argument is provided, otherwise return a copy of the argument
/// See https://redis.io/commands/ping/ for details.
public ping(str?: string): Promise<string> {
return this.createWritePromise(createPing(str));
Expand Down
2 changes: 1 addition & 1 deletion node/src/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class Transaction {
this.commands.push(createSet(key, value, options));
}

/// Returns PONG if no argument is provided, otherwise return a copy of the argument as a bulk
/// Returns PONG if no argument is provided, otherwise return a copy of the argument
/// See https://redis.io/commands/ping/ for details.
public ping(str?: string) {
this.commands.push(createPing(str));
Expand Down
8 changes: 4 additions & 4 deletions node/tests/SocketConnectionInternals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ describe("SocketConnectionInternals", () => {
});
});

it("should pass return PONG from socket", async () => {
it("should return PONG", async () => {
await testWithResources(async (connection, socket) => {
const expected = "PONG";
socket.once("data", (data) => {
const reader = Reader.create(data);
const request = RedisRequest.decodeDelimited(reader);
expect(request.singleCommand?.requestType).toEqual(
RequestType.GetString
RequestType.Ping
);
expect(request.singleCommand?.argsArray?.args?.length).toEqual(
0
Expand All @@ -248,14 +248,14 @@ describe("SocketConnectionInternals", () => {
});
});

it("should pass return HELLO from socket", async () => {
it("should return HELLO", async () => {
await testWithResources(async (connection, socket) => {
const expected = "HELLO";
socket.once("data", (data) => {
const reader = Reader.create(data);
const request = RedisRequest.decodeDelimited(reader);
expect(request.singleCommand?.requestType).toEqual(
RequestType.GetString
RequestType.Ping
);
expect(request.singleCommand?.argsArray?.args?.length).toEqual(
1
Expand Down

0 comments on commit 86aaa7f

Please sign in to comment.