Skip to content

Commit d96aacd

Browse files
committed
move some usage of RedisArgument arrays to ReadonlyArray
motivated by wanting to return a read only array from the parser object
1 parent df228c9 commit d96aacd

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

packages/client/lib/RESP/encoder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RedisArgument } from './types';
22

33
const CRLF = '\r\n';
44

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

88
let strings = '*' + args.length + CRLF;

packages/client/lib/client/commands-queue.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SinglyLinkedList, DoublyLinkedNode, DoublyLinkedList } from './linked-list';
22
import encodeCommand from '../RESP/encoder';
33
import { Decoder, PUSH_TYPE_MAPPING, RESP_TYPES } from '../RESP/decoder';
4-
import { CommandArguments, TypeMapping, ReplyUnion, RespVersions } from '../RESP/types';
4+
import { TypeMapping, ReplyUnion, RespVersions, RedisArgument } from '../RESP/types';
55
import { ChannelListeners, PubSub, PubSubCommand, PubSubListener, PubSubType, PubSubTypeListeners } from './pub-sub';
66
import { AbortError, ErrorReply } from '../errors';
77
import { MonitorCallback } from '.';
@@ -17,7 +17,7 @@ export interface CommandOptions<T = TypeMapping> {
1717
}
1818

1919
export interface CommandToWrite extends CommandWaitingForReply {
20-
args: CommandArguments;
20+
args: ReadonlyArray<RedisArgument>;
2121
chainId: symbol | undefined;
2222
abort: {
2323
signal: AbortSignal;
@@ -117,7 +117,7 @@ export default class RedisCommandsQueue {
117117
}
118118

119119
addCommand<T>(
120-
args: CommandArguments,
120+
args: ReadonlyArray<RedisArgument>,
121121
options?: CommandOptions
122122
): Promise<T> {
123123
if (this.#maxLength && this.#toWrite.length + this.#waitingForReply.length >= this.#maxLength) {
@@ -346,7 +346,7 @@ export default class RedisCommandsQueue {
346346
*commandsToWrite() {
347347
let toSend = this.#toWrite.shift();
348348
while (toSend) {
349-
let encoded: CommandArguments;
349+
let encoded: ReadonlyArray<RedisArgument>
350350
try {
351351
encoded = encodeCommand(toSend.args);
352352
} catch (err) {

packages/client/lib/client/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ export default class RedisClient<
627627
}
628628

629629
sendCommand<T = ReplyUnion>(
630-
args: Array<RedisArgument>,
630+
args: ReadonlyArray<RedisArgument>,
631631
options?: CommandOptions
632632
): Promise<T> {
633633
if (!this._self.#socket.isOpen) {

packages/client/lib/client/socket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export default class RedisSocket extends EventEmitter {
271271
});
272272
}
273273

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

277277
this.#socket.cork();

0 commit comments

Comments
 (0)