1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

add buffer support to a bunch of commands

This commit is contained in:
leibale
2021-12-15 17:08:50 -05:00
parent 72072f6b1c
commit a1bed9a10f
88 changed files with 821 additions and 381 deletions

View File

@@ -1,7 +1,7 @@
import RedisClient, { InstantiableRedisClient, RedisClientType } from '../client';
import { RedisClusterMasterNode, RedisClusterReplicaNode } from '../commands/CLUSTER_NODES';
import { RedisClusterClientOptions, RedisClusterOptions } from '.';
import { RedisModules, RedisScripts } from '../commands';
import { RedisCommandArgument, RedisModules, RedisScripts } from '../commands';
// We need to use 'require', because it's not possible with Typescript to import
// function that are exported as 'module.exports = function`, without esModuleInterop
@@ -202,7 +202,7 @@ export default class RedisClusterSlots<M extends RedisModules, S extends RedisSc
return value.client;
}
getClient(firstKey?: string | Buffer, isReadonly?: boolean): RedisClientType<M, S> {
getClient(firstKey?: RedisCommandArgument, isReadonly?: boolean): RedisClientType<M, S> {
if (!firstKey) {
return this.#getRandomClient();
}

View File

@@ -4,9 +4,13 @@ import * as BITCOUNT from '../commands/BITCOUNT';
import * as BITFIELD from '../commands/BITFIELD';
import * as BITOP from '../commands/BITOP';
import * as BITPOS from '../commands/BITPOS';
import * as BLMOVE_BUFFER from '../commands/BLMOVE_BUFFER';
import * as BLMOVE from '../commands/BLMOVE';
import * as BLPOP_BUFFER from '../commands/BLPOP_BUFFER';
import * as BLPOP from '../commands/BLPOP';
import * as BRPOP_BUFFER from '../commands/BRPOP_BUFFER';
import * as BRPOP from '../commands/BRPOP';
import * as BRPOPLPUSH_BUFFER from '../commands/BRPOPLPUSH_BUFFER';
import * as BRPOPLPUSH from '../commands/BRPOPLPUSH';
import * as BZPOPMAX from '../commands/BZPOPMAX';
import * as BZPOPMIN from '../commands/BZPOPMIN';
@@ -36,13 +40,16 @@ import * as GETRANGE from '../commands/GETRANGE';
import * as GETSET from '../commands/GETSET';
import * as HDEL from '../commands/HDEL';
import * as HEXISTS from '../commands/HEXISTS';
import * as HGET_BUFFER from '../commands/HGET_BUFFER';
import * as HGET from '../commands/HGET';
import * as HGETALL_BUFFER from '../commands/HGETALL_BUFFER';
import * as HGETALL from '../commands/HGETALL';
import * as HINCRBY from '../commands/HINCRBY';
import * as HINCRBYFLOAT from '../commands/HINCRBYFLOAT';
import * as HKEYS from '../commands/HKEYS';
import * as HLEN from '../commands/HLEN';
import * as HMGET from '../commands/HMGET';
import * as HRANDFIELD_COUNT_WITHVALUES_BUFFER from '../commands/HRANDFIELD_COUNT_WITHVALUES_BUFFER';
import * as HRANDFIELD_COUNT_WITHVALUES from '../commands/HRANDFIELD_COUNT_WITHVALUES';
import * as HRANDFIELD_COUNT from '../commands/HRANDFIELD_COUNT';
import * as HRANDFIELD from '../commands/HRANDFIELD';
@@ -119,10 +126,14 @@ import * as UNLINK from '../commands/UNLINK';
import * as WATCH from '../commands/WATCH';
import * as XACK from '../commands/XACK';
import * as XADD from '../commands/XADD';
import * as XAUTOCLAIM_JUSTID_BUFFER from '../commands/XAUTOCLAIM_JUSTID_BUFFER';
import * as XAUTOCLAIM_BUFFER from '../commands/XAUTOCLAIM_BUFFER';
import * as XAUTOCLAIM_JUSTID from '../commands/XAUTOCLAIM_JUSTID';
import * as XAUTOCLAIM from '../commands/XAUTOCLAIM';
import * as XCLAIM from '../commands/XCLAIM';
import * as XCLAIM_JUSTID_BUFFER from '../commands/XCLAIM_JUSTID_BUFFER';
import * as XCLAIM_BUFFER from '../commands/XCLAIM_BUFFER';
import * as XCLAIM_JUSTID from '../commands/XCLAIM_JUSTID';
import * as XCLAIM from '../commands/XCLAIM';
import * as XDEL from '../commands/XDEL';
import * as XGROUP_CREATE from '../commands/XGROUP_CREATE';
import * as XGROUP_CREATECONSUMER from '../commands/XGROUP_CREATECONSUMER';
@@ -135,9 +146,13 @@ import * as XINFO_STREAM from '../commands/XINFO_STREAM';
import * as XLEN from '../commands/XLEN';
import * as XPENDING_RANGE from '../commands/XPENDING_RANGE';
import * as XPENDING from '../commands/XPENDING';
import * as XRANGE_BUFFER from '../commands/XRANGE_BUFFER';
import * as XRANGE from '../commands/XRANGE';
import * as XREAD_BUFFER from '../commands/XREAD_BUFFER';
import * as XREAD from '../commands/XREAD';
import * as XREADGROUP_BUFFER from '../commands/XREADGROUP_BUFFER';
import * as XREADGROUP from '../commands/XREADGROUP';
import * as XREVRANGE_BUFFER from '../commands/XREVRANGE_BUFFER';
import * as XREVRANGE from '../commands/XREVRANGE';
import * as XTRIM from '../commands/XTRIM';
import * as ZADD from '../commands/ZADD';
@@ -188,12 +203,20 @@ export default {
bitOp: BITOP,
BITPOS,
bitPos: BITPOS,
BLMOVE_BUFFER,
blMoveBuffer: BLMOVE_BUFFER,
BLMOVE,
blMove: BLMOVE,
BLPOP_BUFFER,
blPopBuffer: BLPOP_BUFFER,
BLPOP,
blPop: BLPOP,
BRPOP_BUFFER,
brPopBuffer: BRPOP_BUFFER,
BRPOP,
brPop: BRPOP,
BRPOPLPUSH_BUFFER,
brPopLPushBuffer: BRPOPLPUSH_BUFFER,
BRPOPLPUSH,
brPopLPush: BRPOPLPUSH,
BZPOPMAX,
@@ -252,8 +275,12 @@ export default {
hDel: HDEL,
HEXISTS,
hExists: HEXISTS,
HGET_BUFFER,
hGetBuffer: HGET_BUFFER,
HGET,
hGet: HGET,
HGETALL_BUFFER,
hGetAllBuffer: HGETALL_BUFFER,
HGETALL,
hGetAll: HGETALL,
HINCRBY,
@@ -266,6 +293,8 @@ export default {
hLen: HLEN,
HMGET,
hmGet: HMGET,
HRANDFIELD_COUNT_WITHVALUES_BUFFER,
hRandFieldCountWithValuesBuffer: HRANDFIELD_COUNT_WITHVALUES_BUFFER,
HRANDFIELD_COUNT_WITHVALUES,
hRandFieldCountWithValues: HRANDFIELD_COUNT_WITHVALUES,
HRANDFIELD_COUNT,
@@ -418,12 +447,20 @@ export default {
xAck: XACK,
XADD,
xAdd: XADD,
XAUTOCLAIM_JUSTID_BUFFER,
xAutoClaimJustIdBuffer: XAUTOCLAIM_JUSTID_BUFFER,
XAUTOCLAIM_BUFFER,
xAutoClaimBuffer: XAUTOCLAIM_BUFFER,
XAUTOCLAIM_JUSTID,
xAutoClaimJustId: XAUTOCLAIM_JUSTID,
XAUTOCLAIM,
xAutoClaim: XAUTOCLAIM,
XCLAIM,
xClaim: XCLAIM,
XCLAIM_JUSTID_BUFFER,
xClaimJustIdBuffer: XCLAIM_JUSTID_BUFFER,
XCLAIM_BUFFER,
xClaimBuffer: XCLAIM_BUFFER,
XCLAIM_JUSTID,
xClaimJustId: XCLAIM_JUSTID,
XDEL,
@@ -450,12 +487,20 @@ export default {
xPendingRange: XPENDING_RANGE,
XPENDING,
xPending: XPENDING,
XRANGE_BUFFER,
xRangeBuffer: XRANGE_BUFFER,
XRANGE,
xRange: XRANGE,
XREAD_BUFFER,
xReadBuffer: XREAD_BUFFER,
XREAD,
xRead: XREAD,
XREADGROUP_BUFFER,
xReadGroupBuffer: XREADGROUP_BUFFER,
XREADGROUP,
xReadGroup: XREADGROUP,
XREVRANGE_BUFFER,
xRevRangeBuffer: XREVRANGE_BUFFER,
XREVRANGE,
xRevRange: XREVRANGE,
XTRIM,

View File

@@ -1,5 +1,5 @@
import COMMANDS from './commands';
import { RedisCommand, RedisCommandArguments, RedisCommandReply, RedisModules, RedisPlugins, RedisScript, RedisScripts } from '../commands';
import { RedisCommand, RedisCommandArgument, RedisCommandArguments, RedisCommandReply, RedisModules, RedisPlugins, RedisScript, RedisScripts } from '../commands';
import { ClientCommandOptions, RedisClientCommandSignature, RedisClientOptions, RedisClientType, WithModules, WithScripts } from '../client';
import RedisClusterSlots, { ClusterNode } from './cluster-slots';
import { extendWithModulesAndScripts, transformCommandArguments, transformCommandReply, extendWithCommands } from '../commander';
@@ -24,7 +24,7 @@ export type RedisClusterType<M extends RedisModules = Record<string, never>, S e
RedisCluster<M, S> & WithCommands & WithModules<M> & WithScripts<S>;
export default class RedisCluster<M extends RedisModules = Record<string, never>, S extends RedisScripts = Record<string, never>> extends EventEmitter {
static extractFirstKey(command: RedisCommand, originalArgs: Array<unknown>, redisArgs: RedisCommandArguments): string | Buffer | undefined {
static extractFirstKey(command: RedisCommand, originalArgs: Array<unknown>, redisArgs: RedisCommandArguments): RedisCommandArgument | undefined {
if (command.FIRST_KEY_INDEX === undefined) {
return undefined;
} else if (typeof command.FIRST_KEY_INDEX === 'number') {
@@ -84,7 +84,7 @@ export default class RedisCluster<M extends RedisModules = Record<string, never>
}
async sendCommand<C extends RedisCommand>(
firstKey: string | Buffer | undefined,
firstKey: RedisCommandArgument | undefined,
isReadonly: boolean | undefined,
args: RedisCommandArguments,
options?: ClientCommandOptions,
@@ -175,9 +175,9 @@ export default class RedisCluster<M extends RedisModules = Record<string, never>
throw err;
}
multi(routing?: string | Buffer): RedisClusterMultiCommandType<M, S> {
multi(routing?: RedisCommandArgument): RedisClusterMultiCommandType<M, S> {
return new this.#Multi(
async (commands: Array<RedisMultiQueuedCommand>, firstKey?: string | Buffer, chainId?: symbol) => {
async (commands: Array<RedisMultiQueuedCommand>, firstKey?: RedisCommandArgument, chainId?: symbol) => {
return this.#slots
.getClient(firstKey)
.multiExecutor(commands, chainId);

View File

@@ -1,5 +1,5 @@
import COMMANDS from './commands';
import { RedisCommand, RedisCommandArguments, RedisCommandRawReply, RedisModules, RedisPlugins, RedisScript, RedisScripts } from '../commands';
import { RedisCommand, RedisCommandArgument, RedisCommandArguments, RedisCommandRawReply, RedisModules, RedisPlugins, RedisScript, RedisScripts } from '../commands';
import RedisMultiCommand, { RedisMultiQueuedCommand } from '../multi-command';
import { extendWithCommands, extendWithModulesAndScripts } from '../commander';
import RedisCluster from '.';
@@ -24,12 +24,12 @@ type WithScripts<M extends RedisModules, S extends RedisScripts> = {
export type RedisClusterMultiCommandType<M extends RedisModules = Record<string, never>, S extends RedisScripts = Record<string, never>> =
RedisClusterMultiCommand & WithCommands<M, S> & WithModules<M, S> & WithScripts<M, S>;
export type RedisClusterMultiExecutor = (queue: Array<RedisMultiQueuedCommand>, firstKey?: string | Buffer, chainId?: symbol) => Promise<Array<RedisCommandRawReply>>;
export type RedisClusterMultiExecutor = (queue: Array<RedisMultiQueuedCommand>, firstKey?: RedisCommandArgument, chainId?: symbol) => Promise<Array<RedisCommandRawReply>>;
export default class RedisClusterMultiCommand {
readonly #multi = new RedisMultiCommand();
readonly #executor: RedisClusterMultiExecutor;
#firstKey: string | Buffer | undefined;
#firstKey: RedisCommandArgument | undefined;
static extend<M extends RedisModules, S extends RedisScripts>(
plugins?: RedisPlugins<M, S>
@@ -43,7 +43,7 @@ export default class RedisClusterMultiCommand {
});
}
constructor(executor: RedisClusterMultiExecutor, firstKey?: string | Buffer) {
constructor(executor: RedisClusterMultiExecutor, firstKey?: RedisCommandArgument) {
this.#executor = executor;
this.#firstKey = firstKey;
}
@@ -62,7 +62,7 @@ export default class RedisClusterMultiCommand {
}
addCommand(
firstKey: string | Buffer | undefined,
firstKey: RedisCommandArgument | undefined,
args: RedisCommandArguments,
transformReply?: RedisCommand['transformReply']
): this {