Skip to content

Commit

Permalink
move some usage of RedisArgument arrays to ReadonlyArray
Browse files Browse the repository at this point in the history
motivated by wanting to return a read only array from the parser object
  • Loading branch information
sjpotter committed Apr 2, 2024
1 parent df228c9 commit d96aacd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/client/lib/RESP/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RedisArgument } from './types';

const CRLF = '\r\n';

export default function encodeCommand(args: Array<RedisArgument>): Array<RedisArgument> {
export default function encodeCommand(args: ReadonlyArray<RedisArgument>): ReadonlyArray<RedisArgument> {
const toWrite: Array<RedisArgument> = [];

let strings = '*' + args.length + CRLF;
Expand Down
8 changes: 4 additions & 4 deletions packages/client/lib/client/commands-queue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SinglyLinkedList, DoublyLinkedNode, DoublyLinkedList } from './linked-list';
import encodeCommand from '../RESP/encoder';
import { Decoder, PUSH_TYPE_MAPPING, RESP_TYPES } from '../RESP/decoder';
import { CommandArguments, TypeMapping, ReplyUnion, RespVersions } from '../RESP/types';
import { TypeMapping, ReplyUnion, RespVersions, RedisArgument } from '../RESP/types';
import { ChannelListeners, PubSub, PubSubCommand, PubSubListener, PubSubType, PubSubTypeListeners } from './pub-sub';
import { AbortError, ErrorReply } from '../errors';
import { MonitorCallback } from '.';
Expand All @@ -17,7 +17,7 @@ export interface CommandOptions<T = TypeMapping> {
}

export interface CommandToWrite extends CommandWaitingForReply {
args: CommandArguments;
args: ReadonlyArray<RedisArgument>;
chainId: symbol | undefined;
abort: {
signal: AbortSignal;
Expand Down Expand Up @@ -117,7 +117,7 @@ export default class RedisCommandsQueue {
}

addCommand<T>(
args: CommandArguments,
args: ReadonlyArray<RedisArgument>,
options?: CommandOptions
): Promise<T> {
if (this.#maxLength && this.#toWrite.length + this.#waitingForReply.length >= this.#maxLength) {
Expand Down Expand Up @@ -346,7 +346,7 @@ export default class RedisCommandsQueue {
*commandsToWrite() {
let toSend = this.#toWrite.shift();
while (toSend) {
let encoded: CommandArguments;
let encoded: ReadonlyArray<RedisArgument>
try {
encoded = encodeCommand(toSend.args);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export default class RedisClient<
}

sendCommand<T = ReplyUnion>(
args: Array<RedisArgument>,
args: ReadonlyArray<RedisArgument>,
options?: CommandOptions
): Promise<T> {
if (!this._self.#socket.isOpen) {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/client/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export default class RedisSocket extends EventEmitter {
});
}

write(iterable: Iterable<Array<RedisArgument>>) {
write(iterable: Iterable<ReadonlyArray<RedisArgument>>) {
if (!this.#socket) return;

this.#socket.cork();
Expand Down

0 comments on commit d96aacd

Please sign in to comment.