1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00
This commit is contained in:
Leibale
2023-04-23 07:56:15 -04:00
parent 35d32e5b64
commit 9faa3e77c4
326 changed files with 14620 additions and 10931 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,637 +0,0 @@
import * as APPEND from '../commands/APPEND';
import * as BITCOUNT from '../commands/BITCOUNT';
import * as BITFIELD_RO from '../commands/BITFIELD_RO';
import * as BITFIELD from '../commands/BITFIELD';
import * as BITOP from '../commands/BITOP';
import * as BITPOS from '../commands/BITPOS';
import * as BLMOVE from '../commands/BLMOVE';
import * as BLMPOP from '../commands/BLMPOP';
import * as BLPOP from '../commands/BLPOP';
import * as BRPOP from '../commands/BRPOP';
import * as BRPOPLPUSH from '../commands/BRPOPLPUSH';
import * as BZMPOP from '../commands/BZMPOP';
import * as BZPOPMAX from '../commands/BZPOPMAX';
import * as BZPOPMIN from '../commands/BZPOPMIN';
import * as COPY from '../commands/COPY';
import * as DECR from '../commands/DECR';
import * as DECRBY from '../commands/DECRBY';
import * as DEL from '../commands/DEL';
import * as DUMP from '../commands/DUMP';
import * as EVAL_RO from '../commands/EVAL_RO';
import * as EVAL from '../commands/EVAL';
import * as EVALSHA_RO from '../commands/EVALSHA_RO';
import * as EVALSHA from '../commands/EVALSHA';
import * as EXISTS from '../commands/EXISTS';
import * as EXPIRE from '../commands/EXPIRE';
import * as EXPIREAT from '../commands/EXPIREAT';
import * as EXPIRETIME from '../commands/EXPIRETIME';
import * as FCALL_RO from '../commands/FCALL_RO';
import * as FCALL from '../commands/FCALL';
import * as GEOADD from '../commands/GEOADD';
import * as GEODIST from '../commands/GEODIST';
import * as GEOHASH from '../commands/GEOHASH';
import * as GEOPOS from '../commands/GEOPOS';
import * as GEORADIUS_RO_WITH from '../commands/GEORADIUS_RO_WITH';
import * as GEORADIUS_RO from '../commands/GEORADIUS_RO';
import * as GEORADIUS_WITH from '../commands/GEORADIUS_WITH';
import * as GEORADIUS from '../commands/GEORADIUS';
import * as GEORADIUSBYMEMBER_RO_WITH from '../commands/GEORADIUSBYMEMBER_RO_WITH';
import * as GEORADIUSBYMEMBER_RO from '../commands/GEORADIUSBYMEMBER_RO';
import * as GEORADIUSBYMEMBER_WITH from '../commands/GEORADIUSBYMEMBER_WITH';
import * as GEORADIUSBYMEMBER from '../commands/GEORADIUSBYMEMBER';
import * as GEORADIUSBYMEMBERSTORE from '../commands/GEORADIUSBYMEMBERSTORE';
import * as GEORADIUSSTORE from '../commands/GEORADIUSSTORE';
import * as GEOSEARCH_WITH from '../commands/GEOSEARCH_WITH';
import * as GEOSEARCH from '../commands/GEOSEARCH';
import * as GEOSEARCHSTORE from '../commands/GEOSEARCHSTORE';
import * as GET from '../commands/GET';
import * as GETBIT from '../commands/GETBIT';
import * as GETDEL from '../commands/GETDEL';
import * as GETEX from '../commands/GETEX';
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 from '../commands/HGET';
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 from '../commands/HRANDFIELD_COUNT_WITHVALUES';
import * as HRANDFIELD_COUNT from '../commands/HRANDFIELD_COUNT';
import * as HRANDFIELD from '../commands/HRANDFIELD';
import * as HSCAN from '../commands/HSCAN';
import * as HSET from '../commands/HSET';
import * as HSETNX from '../commands/HSETNX';
import * as HSTRLEN from '../commands/HSTRLEN';
import * as HVALS from '../commands/HVALS';
import * as INCR from '../commands/INCR';
import * as INCRBY from '../commands/INCRBY';
import * as INCRBYFLOAT from '../commands/INCRBYFLOAT';
import * as LCS_IDX_WITHMATCHLEN from '../commands/LCS_IDX_WITHMATCHLEN';
import * as LCS_IDX from '../commands/LCS_IDX';
import * as LCS_LEN from '../commands/LCS_LEN';
import * as LCS from '../commands/LCS';
import * as LINDEX from '../commands/LINDEX';
import * as LINSERT from '../commands/LINSERT';
import * as LLEN from '../commands/LLEN';
import * as LMOVE from '../commands/LMOVE';
import * as LMPOP from '../commands/LMPOP';
import * as LPOP_COUNT from '../commands/LPOP_COUNT';
import * as LPOP from '../commands/LPOP';
import * as LPOS_COUNT from '../commands/LPOS_COUNT';
import * as LPOS from '../commands/LPOS';
import * as LPUSH from '../commands/LPUSH';
import * as LPUSHX from '../commands/LPUSHX';
import * as LRANGE from '../commands/LRANGE';
import * as LREM from '../commands/LREM';
import * as LSET from '../commands/LSET';
import * as LTRIM from '../commands/LTRIM';
import * as MGET from '../commands/MGET';
import * as MIGRATE from '../commands/MIGRATE';
import * as MSET from '../commands/MSET';
import * as MSETNX from '../commands/MSETNX';
import * as OBJECT_ENCODING from '../commands/OBJECT_ENCODING';
import * as OBJECT_FREQ from '../commands/OBJECT_FREQ';
import * as OBJECT_IDLETIME from '../commands/OBJECT_IDLETIME';
import * as OBJECT_REFCOUNT from '../commands/OBJECT_REFCOUNT';
import * as PERSIST from '../commands/PERSIST';
import * as PEXPIRE from '../commands/PEXPIRE';
import * as PEXPIREAT from '../commands/PEXPIREAT';
import * as PEXPIRETIME from '../commands/PEXPIRETIME';
import * as PFADD from '../commands/PFADD';
import * as PFCOUNT from '../commands/PFCOUNT';
import * as PFMERGE from '../commands/PFMERGE';
import * as PSETEX from '../commands/PSETEX';
import * as PTTL from '../commands/PTTL';
import * as PUBLISH from '../commands/PUBLISH';
import * as RENAME from '../commands/RENAME';
import * as RENAMENX from '../commands/RENAMENX';
import * as RPOP_COUNT from '../commands/RPOP_COUNT';
import * as RPOP from '../commands/RPOP';
import * as RPOPLPUSH from '../commands/RPOPLPUSH';
import * as RPUSH from '../commands/RPUSH';
import * as RPUSHX from '../commands/RPUSHX';
import * as SADD from '../commands/SADD';
import * as SCARD from '../commands/SCARD';
import * as SDIFF from '../commands/SDIFF';
import * as SDIFFSTORE from '../commands/SDIFFSTORE';
import * as SET from '../commands/SET';
import * as SETBIT from '../commands/SETBIT';
import * as SETEX from '../commands/SETEX';
import * as SETNX from '../commands/SETNX';
import * as SETRANGE from '../commands/SETRANGE';
import * as SINTER from '../commands/SINTER';
import * as SINTERCARD from '../commands/SINTERCARD';
import * as SINTERSTORE from '../commands/SINTERSTORE';
import * as SISMEMBER from '../commands/SISMEMBER';
import * as SMEMBERS from '../commands/SMEMBERS';
import * as SMISMEMBER from '../commands/SMISMEMBER';
import * as SMOVE from '../commands/SMOVE';
import * as SORT_RO from '../commands/SORT_RO';
import * as SORT_STORE from '../commands/SORT_STORE';
import * as SORT from '../commands/SORT';
import * as SPOP from '../commands/SPOP';
import * as SPUBLISH from '../commands/SPUBLISH';
import * as SRANDMEMBER_COUNT from '../commands/SRANDMEMBER_COUNT';
import * as SRANDMEMBER from '../commands/SRANDMEMBER';
import * as SREM from '../commands/SREM';
import * as SSCAN from '../commands/SSCAN';
import * as STRLEN from '../commands/STRLEN';
import * as SUNION from '../commands/SUNION';
import * as SUNIONSTORE from '../commands/SUNIONSTORE';
import * as TOUCH from '../commands/TOUCH';
import * as TTL from '../commands/TTL';
import * as TYPE from '../commands/TYPE';
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 from '../commands/XAUTOCLAIM_JUSTID';
import * as XAUTOCLAIM from '../commands/XAUTOCLAIM';
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';
import * as XGROUP_DELCONSUMER from '../commands/XGROUP_DELCONSUMER';
import * as XGROUP_DESTROY from '../commands/XGROUP_DESTROY';
import * as XGROUP_SETID from '../commands/XGROUP_SETID';
import * as XINFO_CONSUMERS from '../commands/XINFO_CONSUMERS';
import * as XINFO_GROUPS from '../commands/XINFO_GROUPS';
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 from '../commands/XRANGE';
import * as XREAD from '../commands/XREAD';
import * as XREADGROUP from '../commands/XREADGROUP';
import * as XREVRANGE from '../commands/XREVRANGE';
import * as XSETID from '../commands/XSETID';
import * as XTRIM from '../commands/XTRIM';
import * as ZADD from '../commands/ZADD';
import * as ZCARD from '../commands/ZCARD';
import * as ZCOUNT from '../commands/ZCOUNT';
import * as ZDIFF_WITHSCORES from '../commands/ZDIFF_WITHSCORES';
import * as ZDIFF from '../commands/ZDIFF';
import * as ZDIFFSTORE from '../commands/ZDIFFSTORE';
import * as ZINCRBY from '../commands/ZINCRBY';
import * as ZINTER_WITHSCORES from '../commands/ZINTER_WITHSCORES';
import * as ZINTER from '../commands/ZINTER';
import * as ZINTERCARD from '../commands/ZINTERCARD';
import * as ZINTERSTORE from '../commands/ZINTERSTORE';
import * as ZLEXCOUNT from '../commands/ZLEXCOUNT';
import * as ZMPOP from '../commands/ZMPOP';
import * as ZMSCORE from '../commands/ZMSCORE';
import * as ZPOPMAX_COUNT from '../commands/ZPOPMAX_COUNT';
import * as ZPOPMAX from '../commands/ZPOPMAX';
import * as ZPOPMIN_COUNT from '../commands/ZPOPMIN_COUNT';
import * as ZPOPMIN from '../commands/ZPOPMIN';
import * as ZRANDMEMBER_COUNT_WITHSCORES from '../commands/ZRANDMEMBER_COUNT_WITHSCORES';
import * as ZRANDMEMBER_COUNT from '../commands/ZRANDMEMBER_COUNT';
import * as ZRANDMEMBER from '../commands/ZRANDMEMBER';
import * as ZRANGE_WITHSCORES from '../commands/ZRANGE_WITHSCORES';
import * as ZRANGE from '../commands/ZRANGE';
import * as ZRANGEBYLEX from '../commands/ZRANGEBYLEX';
import * as ZRANGEBYSCORE_WITHSCORES from '../commands/ZRANGEBYSCORE_WITHSCORES';
import * as ZRANGEBYSCORE from '../commands/ZRANGEBYSCORE';
import * as ZRANGESTORE from '../commands/ZRANGESTORE';
import * as ZRANK from '../commands/ZRANK';
import * as ZREM from '../commands/ZREM';
import * as ZREMRANGEBYLEX from '../commands/ZREMRANGEBYLEX';
import * as ZREMRANGEBYRANK from '../commands/ZREMRANGEBYRANK';
import * as ZREMRANGEBYSCORE from '../commands/ZREMRANGEBYSCORE';
import * as ZREVRANK from '../commands/ZREVRANK';
import * as ZSCAN from '../commands/ZSCAN';
import * as ZSCORE from '../commands/ZSCORE';
import * as ZUNION_WITHSCORES from '../commands/ZUNION_WITHSCORES';
import * as ZUNION from '../commands/ZUNION';
import * as ZUNIONSTORE from '../commands/ZUNIONSTORE';
export default {
APPEND,
append: APPEND,
BITCOUNT,
bitCount: BITCOUNT,
BITFIELD_RO,
bitFieldRo: BITFIELD_RO,
BITFIELD,
bitField: BITFIELD,
BITOP,
bitOp: BITOP,
BITPOS,
bitPos: BITPOS,
BLMOVE,
blMove: BLMOVE,
BLMPOP,
blmPop: BLMPOP,
BLPOP,
blPop: BLPOP,
BRPOP,
brPop: BRPOP,
BRPOPLPUSH,
brPopLPush: BRPOPLPUSH,
BZMPOP,
bzmPop: BZMPOP,
BZPOPMAX,
bzPopMax: BZPOPMAX,
BZPOPMIN,
bzPopMin: BZPOPMIN,
COPY,
copy: COPY,
DECR,
decr: DECR,
DECRBY,
decrBy: DECRBY,
DEL,
del: DEL,
DUMP,
dump: DUMP,
EVAL_RO,
evalRo: EVAL_RO,
EVAL,
eval: EVAL,
EVALSHA,
evalSha: EVALSHA,
EVALSHA_RO,
evalShaRo: EVALSHA_RO,
EXISTS,
exists: EXISTS,
EXPIRE,
expire: EXPIRE,
EXPIREAT,
expireAt: EXPIREAT,
EXPIRETIME,
expireTime: EXPIRETIME,
FCALL_RO,
fCallRo: FCALL_RO,
FCALL,
fCall: FCALL,
GEOADD,
geoAdd: GEOADD,
GEODIST,
geoDist: GEODIST,
GEOHASH,
geoHash: GEOHASH,
GEOPOS,
geoPos: GEOPOS,
GEORADIUS_RO_WITH,
geoRadiusRoWith: GEORADIUS_RO_WITH,
GEORADIUS_RO,
geoRadiusRo: GEORADIUS_RO,
GEORADIUS_WITH,
geoRadiusWith: GEORADIUS_WITH,
GEORADIUS,
geoRadius: GEORADIUS,
GEORADIUSBYMEMBER_RO_WITH,
geoRadiusByMemberRoWith: GEORADIUSBYMEMBER_RO_WITH,
GEORADIUSBYMEMBER_RO,
geoRadiusByMemberRo: GEORADIUSBYMEMBER_RO,
GEORADIUSBYMEMBER_WITH,
geoRadiusByMemberWith: GEORADIUSBYMEMBER_WITH,
GEORADIUSBYMEMBER,
geoRadiusByMember: GEORADIUSBYMEMBER,
GEORADIUSBYMEMBERSTORE,
geoRadiusByMemberStore: GEORADIUSBYMEMBERSTORE,
GEORADIUSSTORE,
geoRadiusStore: GEORADIUSSTORE,
GEOSEARCH_WITH,
geoSearchWith: GEOSEARCH_WITH,
GEOSEARCH,
geoSearch: GEOSEARCH,
GEOSEARCHSTORE,
geoSearchStore: GEOSEARCHSTORE,
GET,
get: GET,
GETBIT,
getBit: GETBIT,
GETDEL,
getDel: GETDEL,
GETEX,
getEx: GETEX,
GETRANGE,
getRange: GETRANGE,
GETSET,
getSet: GETSET,
HDEL,
hDel: HDEL,
HEXISTS,
hExists: HEXISTS,
HGET,
hGet: HGET,
HGETALL,
hGetAll: HGETALL,
HINCRBY,
hIncrBy: HINCRBY,
HINCRBYFLOAT,
hIncrByFloat: HINCRBYFLOAT,
HKEYS,
hKeys: HKEYS,
HLEN,
hLen: HLEN,
HMGET,
hmGet: HMGET,
HRANDFIELD_COUNT_WITHVALUES,
hRandFieldCountWithValues: HRANDFIELD_COUNT_WITHVALUES,
HRANDFIELD_COUNT,
hRandFieldCount: HRANDFIELD_COUNT,
HRANDFIELD,
hRandField: HRANDFIELD,
HSCAN,
hScan: HSCAN,
HSET,
hSet: HSET,
HSETNX,
hSetNX: HSETNX,
HSTRLEN,
hStrLen: HSTRLEN,
HVALS,
hVals: HVALS,
INCR,
incr: INCR,
INCRBY,
incrBy: INCRBY,
INCRBYFLOAT,
incrByFloat: INCRBYFLOAT,
LCS_IDX_WITHMATCHLEN,
lcsIdxWithMatchLen: LCS_IDX_WITHMATCHLEN,
LCS_IDX,
lcsIdx: LCS_IDX,
LCS_LEN,
lcsLen: LCS_LEN,
LCS,
lcs: LCS,
LINDEX,
lIndex: LINDEX,
LINSERT,
lInsert: LINSERT,
LLEN,
lLen: LLEN,
LMOVE,
lMove: LMOVE,
LMPOP,
lmPop: LMPOP,
LPOP_COUNT,
lPopCount: LPOP_COUNT,
LPOP,
lPop: LPOP,
LPOS_COUNT,
lPosCount: LPOS_COUNT,
LPOS,
lPos: LPOS,
LPUSH,
lPush: LPUSH,
LPUSHX,
lPushX: LPUSHX,
LRANGE,
lRange: LRANGE,
LREM,
lRem: LREM,
LSET,
lSet: LSET,
LTRIM,
lTrim: LTRIM,
MGET,
mGet: MGET,
MIGRATE,
migrate: MIGRATE,
MSET,
mSet: MSET,
MSETNX,
mSetNX: MSETNX,
OBJECT_ENCODING,
objectEncoding: OBJECT_ENCODING,
OBJECT_FREQ,
objectFreq: OBJECT_FREQ,
OBJECT_IDLETIME,
objectIdleTime: OBJECT_IDLETIME,
OBJECT_REFCOUNT,
objectRefCount: OBJECT_REFCOUNT,
PERSIST,
persist: PERSIST,
PEXPIRE,
pExpire: PEXPIRE,
PEXPIREAT,
pExpireAt: PEXPIREAT,
PEXPIRETIME,
pExpireTime: PEXPIRETIME,
PFADD,
pfAdd: PFADD,
PFCOUNT,
pfCount: PFCOUNT,
PFMERGE,
pfMerge: PFMERGE,
PSETEX,
pSetEx: PSETEX,
PTTL,
pTTL: PTTL,
PUBLISH,
publish: PUBLISH,
RENAME,
rename: RENAME,
RENAMENX,
renameNX: RENAMENX,
RPOP_COUNT,
rPopCount: RPOP_COUNT,
RPOP,
rPop: RPOP,
RPOPLPUSH,
rPopLPush: RPOPLPUSH,
RPUSH,
rPush: RPUSH,
RPUSHX,
rPushX: RPUSHX,
SADD,
sAdd: SADD,
SCARD,
sCard: SCARD,
SDIFF,
sDiff: SDIFF,
SDIFFSTORE,
sDiffStore: SDIFFSTORE,
SINTER,
sInter: SINTER,
SINTERCARD,
sInterCard: SINTERCARD,
SINTERSTORE,
sInterStore: SINTERSTORE,
SET,
set: SET,
SETBIT,
setBit: SETBIT,
SETEX,
setEx: SETEX,
SETNX,
setNX: SETNX,
SETRANGE,
setRange: SETRANGE,
SISMEMBER,
sIsMember: SISMEMBER,
SMEMBERS,
sMembers: SMEMBERS,
SMISMEMBER,
smIsMember: SMISMEMBER,
SMOVE,
sMove: SMOVE,
SORT_RO,
sortRo: SORT_RO,
SORT_STORE,
sortStore: SORT_STORE,
SORT,
sort: SORT,
SPOP,
sPop: SPOP,
SPUBLISH,
sPublish: SPUBLISH,
SRANDMEMBER_COUNT,
sRandMemberCount: SRANDMEMBER_COUNT,
SRANDMEMBER,
sRandMember: SRANDMEMBER,
SREM,
sRem: SREM,
SSCAN,
sScan: SSCAN,
STRLEN,
strLen: STRLEN,
SUNION,
sUnion: SUNION,
SUNIONSTORE,
sUnionStore: SUNIONSTORE,
TOUCH,
touch: TOUCH,
TTL,
ttl: TTL,
TYPE,
type: TYPE,
UNLINK,
unlink: UNLINK,
WATCH,
watch: WATCH,
XACK,
xAck: XACK,
XADD,
xAdd: XADD,
XAUTOCLAIM_JUSTID,
xAutoClaimJustId: XAUTOCLAIM_JUSTID,
XAUTOCLAIM,
xAutoClaim: XAUTOCLAIM,
XCLAIM,
xClaim: XCLAIM,
XCLAIM_JUSTID,
xClaimJustId: XCLAIM_JUSTID,
XDEL,
xDel: XDEL,
XGROUP_CREATE,
xGroupCreate: XGROUP_CREATE,
XGROUP_CREATECONSUMER,
xGroupCreateConsumer: XGROUP_CREATECONSUMER,
XGROUP_DELCONSUMER,
xGroupDelConsumer: XGROUP_DELCONSUMER,
XGROUP_DESTROY,
xGroupDestroy: XGROUP_DESTROY,
XGROUP_SETID,
xGroupSetId: XGROUP_SETID,
XINFO_CONSUMERS,
xInfoConsumers: XINFO_CONSUMERS,
XINFO_GROUPS,
xInfoGroups: XINFO_GROUPS,
XINFO_STREAM,
xInfoStream: XINFO_STREAM,
XLEN,
xLen: XLEN,
XPENDING_RANGE,
xPendingRange: XPENDING_RANGE,
XPENDING,
xPending: XPENDING,
XRANGE,
xRange: XRANGE,
XREAD,
xRead: XREAD,
XREADGROUP,
xReadGroup: XREADGROUP,
XREVRANGE,
xRevRange: XREVRANGE,
XSETID,
xSetId: XSETID,
XTRIM,
xTrim: XTRIM,
ZADD,
zAdd: ZADD,
ZCARD,
zCard: ZCARD,
ZCOUNT,
zCount: ZCOUNT,
ZDIFF_WITHSCORES,
zDiffWithScores: ZDIFF_WITHSCORES,
ZDIFF,
zDiff: ZDIFF,
ZDIFFSTORE,
zDiffStore: ZDIFFSTORE,
ZINCRBY,
zIncrBy: ZINCRBY,
ZINTER_WITHSCORES,
zInterWithScores: ZINTER_WITHSCORES,
ZINTER,
zInter: ZINTER,
ZINTERCARD,
zInterCard: ZINTERCARD,
ZINTERSTORE,
zInterStore: ZINTERSTORE,
ZLEXCOUNT,
zLexCount: ZLEXCOUNT,
ZMPOP,
zmPop: ZMPOP,
ZMSCORE,
zmScore: ZMSCORE,
ZPOPMAX_COUNT,
zPopMaxCount: ZPOPMAX_COUNT,
ZPOPMAX,
zPopMax: ZPOPMAX,
ZPOPMIN_COUNT,
zPopMinCount: ZPOPMIN_COUNT,
ZPOPMIN,
zPopMin: ZPOPMIN,
ZRANDMEMBER_COUNT_WITHSCORES,
zRandMemberCountWithScores: ZRANDMEMBER_COUNT_WITHSCORES,
ZRANDMEMBER_COUNT,
zRandMemberCount: ZRANDMEMBER_COUNT,
ZRANDMEMBER,
zRandMember: ZRANDMEMBER,
ZRANGE_WITHSCORES,
zRangeWithScores: ZRANGE_WITHSCORES,
ZRANGE,
zRange: ZRANGE,
ZRANGEBYLEX,
zRangeByLex: ZRANGEBYLEX,
ZRANGEBYSCORE_WITHSCORES,
zRangeByScoreWithScores: ZRANGEBYSCORE_WITHSCORES,
ZRANGEBYSCORE,
zRangeByScore: ZRANGEBYSCORE,
ZRANGESTORE,
zRangeStore: ZRANGESTORE,
ZRANK,
zRank: ZRANK,
ZREM,
zRem: ZREM,
ZREMRANGEBYLEX,
zRemRangeByLex: ZREMRANGEBYLEX,
ZREMRANGEBYRANK,
zRemRangeByRank: ZREMRANGEBYRANK,
ZREMRANGEBYSCORE,
zRemRangeByScore: ZREMRANGEBYSCORE,
ZREVRANK,
zRevRank: ZREVRANK,
ZSCAN,
zScan: ZSCAN,
ZSCORE,
zScore: ZSCORE,
ZUNION_WITHSCORES,
zUnionWithScores: ZUNION_WITHSCORES,
ZUNION,
zUnion: ZUNION,
ZUNIONSTORE,
zUnionStore: ZUNIONSTORE
};

View File

@@ -1,424 +1,549 @@
import COMMANDS from './commands';
import { RedisCommand, RedisCommandArgument, RedisCommandArguments, RedisCommandRawReply, RedisCommandReply, RedisFunctions, RedisModules, RedisExtensions, RedisScript, RedisScripts, RedisCommandSignature, RedisFunction } from '../commands';
import { ClientCommandOptions, RedisClientOptions, RedisClientType, WithFunctions, WithModules, WithScripts } from '../client';
import RedisClusterSlots, { NodeAddressMap, ShardNode } from './cluster-slots';
import { attachExtensions, transformCommandReply, attachCommands, transformCommandArguments } from '../commander';
import { ClientCommandOptions, RedisClientOptions, RedisClientType } from '../client';
import { Command, CommandArguments, CommanderConfig, CommandPolicies, CommandSignature, CommandWithPoliciesSignature, Flags, RedisArgument, RedisFunction, RedisFunctions, RedisModules, RedisScript, RedisScripts, ReplyUnion, RespVersions, TransformReply } from '../RESP/types';
import COMMANDS from '../commands';
import { EventEmitter } from 'events';
import RedisClusterMultiCommand, { InstantiableRedisClusterMultiCommandType, RedisClusterMultiCommandType } from './multi-command';
import { RedisMultiQueuedCommand } from '../multi-command';
import { attachConfig, functionArgumentsPrefix, getTransformReply, scriptArgumentsPrefix } from '../commander';
import RedisClusterSlots, { NodeAddressMap, ShardNode } from './cluster-slots';
// import RedisClusterMultiCommand, { InstantiableRedisClusterMultiCommandType, RedisClusterMultiCommandType } from './multi-command';
// import { RedisMultiQueuedCommand } from '../multi-command';
import { PubSubListener } from '../client/pub-sub';
import { ErrorReply } from '../errors';
export type RedisClusterClientOptions = Omit<
RedisClientOptions,
'modules' | 'functions' | 'scripts' | 'database'
RedisClientOptions,
'modules' | 'functions' | 'scripts' | 'database' | 'RESP'
>;
export interface RedisClusterOptions<
M extends RedisModules = Record<string, never>,
F extends RedisFunctions = Record<string, never>,
S extends RedisScripts = Record<string, never>
> extends RedisExtensions<M, F, S> {
/**
* Should contain details for some of the cluster nodes that the client will use to discover
* the "cluster topology". We recommend including details for at least 3 nodes here.
*/
rootNodes: Array<RedisClusterClientOptions>;
/**
* Default values used for every client in the cluster. Use this to specify global values,
* for example: ACL credentials, timeouts, TLS configuration etc.
*/
defaults?: Partial<RedisClusterClientOptions>;
/**
* When `true`, `.connect()` will only discover the cluster topology, without actually connecting to all the nodes.
* Useful for short-term or PubSub-only connections.
*/
minimizeConnections?: boolean;
/**
* When `true`, distribute load by executing readonly commands (such as `GET`, `GEOSEARCH`, etc.) across all cluster nodes. When `false`, only use master nodes.
*/
useReplicas?: boolean;
/**
* The maximum number of times a command will be redirected due to `MOVED` or `ASK` errors.
*/
maxCommandRedirections?: number;
/**
* Mapping between the addresses in the cluster (see `CLUSTER SHARDS`) and the addresses the client should connect to
* Useful when the cluster is running on another network
*
*/
nodeAddressMap?: NodeAddressMap;
M extends RedisModules = RedisModules,
F extends RedisFunctions = RedisFunctions,
S extends RedisScripts = RedisScripts,
RESP extends RespVersions = RespVersions
> extends CommanderConfig<M, F, S, RESP> {
/**
* Should contain details for some of the cluster nodes that the client will use to discover
* the "cluster topology". We recommend including details for at least 3 nodes here.
*/
rootNodes: Array<RedisClusterClientOptions>;
/**
* Default values used for every client in the cluster. Use this to specify global values,
* for example: ACL credentials, timeouts, TLS configuration etc.
*/
defaults?: Partial<RedisClusterClientOptions>;
/**
* When `true`, `.connect()` will only discover the cluster topology, without actually connecting to all the nodes.
* Useful for short-term or PubSub-only connections.
*/
minimizeConnections?: boolean;
/**
* When `true`, distribute load by executing readonly commands (such as `GET`, `GEOSEARCH`, etc.) across all cluster nodes. When `false`, only use master nodes.
*/
// TODO: replicas only mode?
useReplicas?: boolean;
/**
* The maximum number of times a command will be redirected due to `MOVED` or `ASK` errors.
*/
maxCommandRedirections?: number;
/**
* Mapping between the addresses in the cluster (see `CLUSTER SHARDS`) and the addresses the client should connect to
* Useful when the cluster is running on another network
*/
nodeAddressMap?: NodeAddressMap;
}
type WithCommands = {
[P in keyof typeof COMMANDS]: RedisCommandSignature<(typeof COMMANDS)[P]>;
type WithCommands<
RESP extends RespVersions,
FLAGS extends Flags,
POLICIES extends CommandPolicies
> = {
[P in keyof typeof COMMANDS]: CommandWithPoliciesSignature<(typeof COMMANDS)[P], RESP, FLAGS, POLICIES>;
};
export type RedisClusterType<
M extends RedisModules = Record<string, never>,
F extends RedisFunctions = Record<string, never>,
S extends RedisScripts = Record<string, never>
> = RedisCluster<M, F, S> & WithCommands & WithModules<M> & WithFunctions<F> & WithScripts<S>;
M extends RedisModules = {},
F extends RedisFunctions = {},
S extends RedisScripts = {},
RESP extends RespVersions = 2,
FLAGS extends Flags = {},
POLICIES extends CommandPolicies = {}
> = RedisCluster<M, F, S, RESP, FLAGS, POLICIES> & WithCommands<RESP, FLAGS, POLICIES>;
// & WithModules<M> & WithFunctions<F> & WithScripts<S>
export default class RedisCluster<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts
> extends EventEmitter {
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') {
return redisArgs[command.FIRST_KEY_INDEX];
}
return command.FIRST_KEY_INDEX(...originalArgs);
}
static create<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts
>(options?: RedisClusterOptions<M, F, S>): RedisClusterType<M, F, S> {
return new (attachExtensions({
BaseClass: RedisCluster,
modulesExecutor: RedisCluster.prototype.commandsExecutor,
modules: options?.modules,
functionsExecutor: RedisCluster.prototype.functionsExecutor,
functions: options?.functions,
scriptsExecutor: RedisCluster.prototype.scriptsExecutor,
scripts: options?.scripts
}))(options);
}
readonly #options: RedisClusterOptions<M, F, S>;
readonly #slots: RedisClusterSlots<M, F, S>;
get slots() {
return this.#slots.slots;
}
get shards() {
return this.#slots.shards;
}
get masters() {
return this.#slots.masters;
}
get replicas() {
return this.#slots.replicas;
}
get nodeByAddress() {
return this.#slots.nodeByAddress;
}
get pubSubNode() {
return this.#slots.pubSubNode;
}
readonly #Multi: InstantiableRedisClusterMultiCommandType<M, F, S>;
get isOpen() {
return this.#slots.isOpen;
}
constructor(options: RedisClusterOptions<M, F, S>) {
super();
this.#options = options;
this.#slots = new RedisClusterSlots(options, this.emit.bind(this));
this.#Multi = RedisClusterMultiCommand.extend(options);
}
duplicate(overrides?: Partial<RedisClusterOptions<M, F, S>>): RedisClusterType<M, F, S> {
return new (Object.getPrototypeOf(this).constructor)({
...this.#options,
...overrides
});
}
connect() {
return this.#slots.connect();
}
async commandsExecutor<C extends RedisCommand>(
command: C,
args: Array<unknown>
): Promise<RedisCommandReply<C>> {
const { args: redisArgs, options } = transformCommandArguments(command, args);
return transformCommandReply(
command,
await this.sendCommand(
RedisCluster.extractFirstKey(command, args, redisArgs),
command.IS_READ_ONLY,
redisArgs,
options
),
redisArgs.preserve
);
}
async sendCommand<T = RedisCommandRawReply>(
firstKey: RedisCommandArgument | undefined,
isReadonly: boolean | undefined,
args: RedisCommandArguments,
options?: ClientCommandOptions
): Promise<T> {
return this.#execute(
firstKey,
isReadonly,
client => client.sendCommand<T>(args, options)
);
}
async functionsExecutor<F extends RedisFunction>(
fn: F,
args: Array<unknown>,
name: string,
): Promise<RedisCommandReply<F>> {
const { args: redisArgs, options } = transformCommandArguments(fn, args);
return transformCommandReply(
fn,
await this.executeFunction(
name,
fn,
args,
redisArgs,
options
),
redisArgs.preserve
);
}
async executeFunction(
name: string,
fn: RedisFunction,
originalArgs: Array<unknown>,
redisArgs: RedisCommandArguments,
options?: ClientCommandOptions
): Promise<RedisCommandRawReply> {
return this.#execute(
RedisCluster.extractFirstKey(fn, originalArgs, redisArgs),
fn.IS_READ_ONLY,
client => client.executeFunction(name, fn, redisArgs, options)
);
}
async scriptsExecutor<S extends RedisScript>(script: S, args: Array<unknown>): Promise<RedisCommandReply<S>> {
const { args: redisArgs, options } = transformCommandArguments(script, args);
return transformCommandReply(
script,
await this.executeScript(
script,
args,
redisArgs,
options
),
redisArgs.preserve
);
}
async executeScript(
script: RedisScript,
originalArgs: Array<unknown>,
redisArgs: RedisCommandArguments,
options?: ClientCommandOptions
): Promise<RedisCommandRawReply> {
return this.#execute(
RedisCluster.extractFirstKey(script, originalArgs, redisArgs),
script.IS_READ_ONLY,
client => client.executeScript(script, redisArgs, options)
);
}
async #execute<Reply>(
firstKey: RedisCommandArgument | undefined,
isReadonly: boolean | undefined,
executor: (client: RedisClientType<M, F, S>) => Promise<Reply>
): Promise<Reply> {
const maxCommandRedirections = this.#options.maxCommandRedirections ?? 16;
let client = await this.#slots.getClient(firstKey, isReadonly);
for (let i = 0;; i++) {
try {
return await executor(client);
} catch (err) {
if (++i > maxCommandRedirections || !(err instanceof ErrorReply)) {
throw err;
}
if (err.message.startsWith('ASK')) {
const address = err.message.substring(err.message.lastIndexOf(' ') + 1);
let redirectTo = await this.#slots.getMasterByAddress(address);
if (!redirectTo) {
await this.#slots.rediscover(client);
redirectTo = await this.#slots.getMasterByAddress(address);
}
if (!redirectTo) {
throw new Error(`Cannot find node ${address}`);
}
await redirectTo.asking();
client = redirectTo;
continue;
} else if (err.message.startsWith('MOVED')) {
await this.#slots.rediscover(client);
client = await this.#slots.getClient(firstKey, isReadonly);
continue;
}
throw err;
}
}
}
MULTI(routing?: RedisCommandArgument): RedisClusterMultiCommandType<M, F, S> {
return new this.#Multi(
(commands: Array<RedisMultiQueuedCommand>, firstKey?: RedisCommandArgument, chainId?: symbol) => {
return this.#execute(
firstKey,
false,
client => client.multiExecutor(commands, undefined, chainId)
);
},
routing
);
}
multi = this.MULTI;
async SUBSCRIBE<T extends boolean = false>(
channels: string | Array<string>,
listener: PubSubListener<T>,
bufferMode?: T
) {
return (await this.#slots.getPubSubClient())
.SUBSCRIBE(channels, listener, bufferMode);
}
subscribe = this.SUBSCRIBE;
async UNSUBSCRIBE<T extends boolean = false>(
channels?: string | Array<string>,
listener?: PubSubListener<boolean>,
bufferMode?: T
) {
return this.#slots.executeUnsubscribeCommand(client =>
client.UNSUBSCRIBE(channels, listener, bufferMode)
);
}
unsubscribe = this.UNSUBSCRIBE;
async PSUBSCRIBE<T extends boolean = false>(
patterns: string | Array<string>,
listener: PubSubListener<T>,
bufferMode?: T
) {
return (await this.#slots.getPubSubClient())
.PSUBSCRIBE(patterns, listener, bufferMode);
}
pSubscribe = this.PSUBSCRIBE;
async PUNSUBSCRIBE<T extends boolean = false>(
patterns?: string | Array<string>,
listener?: PubSubListener<T>,
bufferMode?: T
) {
return this.#slots.executeUnsubscribeCommand(client =>
client.PUNSUBSCRIBE(patterns, listener, bufferMode)
);
}
pUnsubscribe = this.PUNSUBSCRIBE;
async SSUBSCRIBE<T extends boolean = false>(
channels: string | Array<string>,
listener: PubSubListener<T>,
bufferMode?: T
) {
const maxCommandRedirections = this.#options.maxCommandRedirections ?? 16,
firstChannel = Array.isArray(channels) ? channels[0] : channels;
let client = await this.#slots.getShardedPubSubClient(firstChannel);
for (let i = 0;; i++) {
try {
return await client.SSUBSCRIBE(channels, listener, bufferMode);
} catch (err) {
if (++i > maxCommandRedirections || !(err instanceof ErrorReply)) {
throw err;
}
if (err.message.startsWith('MOVED')) {
await this.#slots.rediscover(client);
client = await this.#slots.getShardedPubSubClient(firstChannel);
continue;
}
throw err;
}
}
}
sSubscribe = this.SSUBSCRIBE;
SUNSUBSCRIBE<T extends boolean = false>(
channels: string | Array<string>,
listener: PubSubListener<T>,
bufferMode?: T
) {
return this.#slots.executeShardedUnsubscribeCommand(
Array.isArray(channels) ? channels[0] : channels,
client => client.SUNSUBSCRIBE(channels, listener, bufferMode)
);
}
sUnsubscribe = this.SUNSUBSCRIBE;
quit(): Promise<void> {
return this.#slots.quit();
}
disconnect(): Promise<void> {
return this.#slots.disconnect();
}
nodeClient(node: ShardNode<M, F, S>) {
return this.#slots.nodeClient(node);
}
getRandomNode() {
return this.#slots.getRandomNode();
}
getSlotRandomNode(slot: number) {
return this.#slots.getSlotRandomNode(slot);
}
/**
* @deprecated use `.masters` instead
*/
getMasters() {
return this.masters;
}
/**
* @deprecated use `.slots[<SLOT>]` instead
*/
getSlotMaster(slot: number) {
return this.slots[slot].master;
}
export interface ClusterCommandOptions extends ClientCommandOptions {
policies?: CommandPolicies;
}
attachCommands({
BaseClass: RedisCluster,
commands: COMMANDS,
executor: RedisCluster.prototype.commandsExecutor
});
type ProxyCluster = RedisCluster<RedisModules, RedisFunctions, RedisScripts, RespVersions, Flags, CommandPolicies> & { commandOptions?: ClusterCommandOptions };
type NamespaceProxyCluster = { self: ProxyCluster };
export default class RedisCluster<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts,
RESP extends RespVersions,
FLAGS extends Flags,
POLICIES extends CommandPolicies
> extends EventEmitter {
private static _extractFirstKey<C extends Command>(
command: C,
args: Parameters<C['transformArguments']>,
redisArgs: Array<RedisArgument>
): RedisArgument | undefined {
if (command.FIRST_KEY_INDEX === undefined) {
return undefined;
} else if (typeof command.FIRST_KEY_INDEX === 'number') {
return redisArgs[command.FIRST_KEY_INDEX];
}
return command.FIRST_KEY_INDEX(...args);
}
private static _createCommand(command: Command, resp: RespVersions) {
const transformReply = getTransformReply(command, resp);
return async function (this: ProxyCluster) {
const args = command.transformArguments.apply(undefined, arguments as any),
firstKey = RedisCluster._extractFirstKey(
command,
arguments as any,
args
),
reply = await this.sendCommand(
firstKey,
command.IS_READ_ONLY,
args,
this.commandOptions,
command.POLICIES
);
return transformReply ?
transformReply(reply, args.preserve) :
reply;
};
}
private static _createModuleCommand(command: Command, resp: RespVersions) {
const transformReply = getTransformReply(command, resp);
return async function (this: NamespaceProxyCluster) {
const args = command.transformArguments.apply(undefined, arguments as any),
firstKey = RedisCluster._extractFirstKey(
command,
arguments as any,
args
),
reply = await this.self.sendCommand(
firstKey,
command.IS_READ_ONLY,
args,
this.self.commandOptions,
command.POLICIES
);
return transformReply ?
transformReply(reply, args.preserve) :
reply;
};
}
private static _createFunctionCommand(name: string, fn: RedisFunction, resp: RespVersions) {
const prefix = functionArgumentsPrefix(name, fn),
transformReply = getTransformReply(fn, resp);
return async function (this: NamespaceProxyCluster) {
const fnArgs = fn.transformArguments.apply(undefined, arguments as any),
args = prefix.concat(fnArgs),
firstKey = RedisCluster._extractFirstKey(
fn,
arguments as any,
args
),
reply = await this.self.sendCommand(
firstKey,
fn.IS_READ_ONLY,
args,
this.self.commandOptions,
fn.POLICIES
);
return transformReply ?
transformReply(reply, fnArgs.preserve) :
reply;
};
}
private static _createScriptCommand(script: RedisScript, resp: RespVersions) {
const prefix = scriptArgumentsPrefix(script),
transformReply = getTransformReply(script, resp);
return async function (this: ProxyCluster) {
const scriptArgs = script.transformArguments.apply(undefined, arguments as any),
args = prefix.concat(scriptArgs),
firstKey = RedisCluster._extractFirstKey(
script,
arguments as any,
args
),
reply = await this.sendCommand(
firstKey,
script.IS_READ_ONLY,
args,
this.commandOptions,
script.POLICIES
);
return transformReply ?
transformReply(reply, scriptArgs.preserve) :
reply;
};
}
static factory<
M extends RedisModules = {},
F extends RedisFunctions = {},
S extends RedisScripts = {},
RESP extends RespVersions = 2
>(config?: CommanderConfig<M, F, S, RESP>) {
const Cluster = attachConfig({
BaseClass: RedisCluster,
commands: COMMANDS,
createCommand: RedisCluster._createCommand,
createFunctionCommand: RedisCluster._createFunctionCommand,
createModuleCommand: RedisCluster._createModuleCommand,
createScriptCommand: RedisCluster._createScriptCommand,
config
});
// Client.prototype.Multi = RedisClientMultiCommand.extend(config);
return (options?: Omit<RedisClusterOptions, keyof Exclude<typeof config, undefined>>) => {
// returning a proxy of the client to prevent the namespaces.self to leak between proxies
// namespaces will be bootstraped on first access per proxy
return Object.create(new Cluster(options)) as RedisClusterType<M, F, S, RESP>;
};
}
static create<
M extends RedisModules = {},
F extends RedisFunctions = {},
S extends RedisScripts = {},
RESP extends RespVersions = 2
>(options?: RedisClusterOptions<M, F, S, RESP>) {
return RedisCluster.factory(options)(options);
}
private readonly _options: RedisClusterOptions<M, F, S, RESP>;
private readonly _slots: RedisClusterSlots<M, F, S, RESP>;
/**
* An array of the cluster slots, each slot contain its `master` and `replicas`.
* Use with {@link RedisCluster.prototype.nodeClient} to get the client for a specific node (master or replica).
*/
get slots() {
return this._slots.slots;
}
/**
* An array of cluster shards, each shard contain its `master` and `replicas`.
* Use with {@link RedisCluster.prototype.nodeClient} to get the client for a specific node (master or replica).
*/
get shards() {
return this._slots.shards;
}
/**
* An array of the cluster masters.
* Use with {@link RedisCluster.prototype.nodeClient} to get the client for a specific master node.
*/
get masters() {
return this._slots.masters;
}
/**
* An array of the cluster replicas.
* Use with {@link RedisCluster.prototype.nodeClient} to get the client for a specific replica node.
*/
get replicas() {
return this._slots.replicas;
}
/**
* A map form a node address (`<host>:<port>`) to its shard, each shard contain its `master` and `replicas`.
* Use with {@link RedisCluster.prototype.nodeClient} to get the client for a specific node (master or replica).
*/
get nodeByAddress() {
return this._slots.nodeByAddress;
}
/**
* The current pub/sub node.
*/
get pubSubNode() {
return this._slots.pubSubNode;
}
// readonly #Multi: InstantiableRedisClusterMultiCommandType<M, F, S>;
get isOpen() {
return this._slots.isOpen;
}
constructor(options: RedisClusterOptions<M, F, S, RESP>) {
super();
this._options = options;
this._slots = new RedisClusterSlots(options, this.emit.bind(this));
// this.#Multi = RedisClusterMultiCommand.extend(options);
}
duplicate(overrides?: Partial<RedisClusterOptions<M, F, S>>): RedisClusterType<M, F, S> {
return new (Object.getPrototypeOf(this).constructor)({
...this._options,
...overrides
});
}
connect() {
return this._slots.connect();
}
withCommandOptions<T extends ClusterCommandOptions>(options: T) {
const proxy = Object.create(this);
proxy.commandOptions = options;
return proxy as RedisClusterType<
M,
F,
S,
RESP,
T['flags'] extends Flags ? T['flags'] : {},
T['policies'] extends CommandPolicies ? T['policies'] : {}
>;
}
private _commandOptionsProxy<
K extends keyof ClusterCommandOptions,
V extends ClusterCommandOptions[K]
>(
key: K,
value: V
) {
const proxy = Object.create(this);
proxy.commandOptions = Object.create((this as ProxyCluster).commandOptions ?? null);
proxy.commandOptions[key] = value;
return proxy as RedisClusterType<
M,
F,
S,
RESP,
K extends 'flags' ? V extends Flags ? V : {} : FLAGS,
K extends 'policies' ? V extends CommandPolicies ? V : {} : POLICIES
>;
}
/**
* Override the `flags` command option
*/
withFlags<FLAGS extends Flags>(flags: FLAGS) {
return this._commandOptionsProxy('flags', flags);
}
/**
* Override the `policies` command option
* TODO
*/
withPolicies<POLICIES extends CommandPolicies> (policies: POLICIES) {
return this._commandOptionsProxy('policies', policies);
}
async sendCommand<T = ReplyUnion>(
firstKey: RedisArgument | undefined,
isReadonly: boolean | undefined,
args: CommandArguments,
options?: ClusterCommandOptions,
deafultPolicies?: CommandPolicies
): Promise<T> {
// const requestPolicy = options?.policies?.request ?? deafultPolicies?.request,
// responsePolicy = options?.policies?.response ?? deafultPolicies?.response;
const maxCommandRedirections = this._options.maxCommandRedirections ?? 16;
let client = await this._slots.getClient(firstKey, isReadonly);
for (let i = 0; ; i++) {
try {
return await client.sendCommand<T>(args, options);
} catch (err) {
// TODO: error class
if (++i > maxCommandRedirections || !(err instanceof Error)) {
throw err;
}
if (err.message.startsWith('ASK')) {
const address = err.message.substring(err.message.lastIndexOf(' ') + 1);
let redirectTo = await this._slots.getMasterByAddress(address);
if (!redirectTo) {
await this._slots.rediscover(client);
redirectTo = await this._slots.getMasterByAddress(address);
}
if (!redirectTo) {
throw new Error(`Cannot find node ${address}`);
}
await redirectTo.asking();
client = redirectTo;
continue;
} else if (err.message.startsWith('MOVED')) {
await this._slots.rediscover(client);
client = await this._slots.getClient(firstKey, isReadonly);
continue;
}
throw err;
}
}
}
// MULTI(routing?: RedisCommandArgument): RedisClusterMultiCommandType<M, F, S> {
// return new this.#Multi(
// (commands: Array<RedisMultiQueuedCommand>, firstKey?: RedisCommandArgument, chainId?: symbol) => {
// return this.#execute(
// firstKey,
// false,
// client => client.multiExecutor(commands, undefined, chainId)
// );
// },
// routing
// );
// }
// multi = this.MULTI;
async SUBSCRIBE<T extends boolean = false>(
channels: string | Array<string>,
listener: PubSubListener<T>,
bufferMode?: T
) {
return (await this._slots.getPubSubClient())
.SUBSCRIBE(channels, listener, bufferMode);
}
subscribe = this.SUBSCRIBE;
async UNSUBSCRIBE<T extends boolean = false>(
channels?: string | Array<string>,
listener?: PubSubListener<boolean>,
bufferMode?: T
) {
return this._slots.executeUnsubscribeCommand(client =>
client.UNSUBSCRIBE(channels, listener, bufferMode)
);
}
unsubscribe = this.UNSUBSCRIBE;
async PSUBSCRIBE<T extends boolean = false>(
patterns: string | Array<string>,
listener: PubSubListener<T>,
bufferMode?: T
) {
return (await this._slots.getPubSubClient())
.PSUBSCRIBE(patterns, listener, bufferMode);
}
pSubscribe = this.PSUBSCRIBE;
async PUNSUBSCRIBE<T extends boolean = false>(
patterns?: string | Array<string>,
listener?: PubSubListener<T>,
bufferMode?: T
) {
return this._slots.executeUnsubscribeCommand(client =>
client.PUNSUBSCRIBE(patterns, listener, bufferMode)
);
}
pUnsubscribe = this.PUNSUBSCRIBE;
async SSUBSCRIBE<T extends boolean = false>(
channels: string | Array<string>,
listener: PubSubListener<T>,
bufferMode?: T
) {
const maxCommandRedirections = this._options.maxCommandRedirections ?? 16,
firstChannel = Array.isArray(channels) ? channels[0] : channels;
let client = await this._slots.getShardedPubSubClient(firstChannel);
for (let i = 0; ; i++) {
try {
return await client.SSUBSCRIBE(channels, listener, bufferMode);
} catch (err) {
if (++i > maxCommandRedirections || !(err instanceof ErrorReply)) {
throw err;
}
if (err.message.startsWith('MOVED')) {
await this._slots.rediscover(client);
client = await this._slots.getShardedPubSubClient(firstChannel);
continue;
}
throw err;
}
}
}
sSubscribe = this.SSUBSCRIBE;
SUNSUBSCRIBE<T extends boolean = false>(
channels: string | Array<string>,
listener: PubSubListener<T>,
bufferMode?: T
) {
return this._slots.executeShardedUnsubscribeCommand(
Array.isArray(channels) ? channels[0] : channels,
client => client.SUNSUBSCRIBE(channels, listener, bufferMode)
);
}
sUnsubscribe = this.SUNSUBSCRIBE;
// quit(): Promise<void> {
// return this.#slots.quit();
// }
disconnect(): Promise<void> {
return this._slots.disconnect();
}
nodeClient(node: ShardNode<M, F, S, RESP>) {
return this._slots.nodeClient(node);
}
/**
* Returns a random node from the cluster.
* Userful for running "forward" commands (like PUBLISH) on a random node.
*/
getRandomNode() {
return this._slots.getRandomNode();
}
/**
* Get a random node from a slot.
* Useful for running readonly commands on a slot.
*/
getSlotRandomNode(slot: number) {
return this._slots.getSlotRandomNode(slot);
}
/**
* @deprecated use `.masters` instead
* TODO
*/
getMasters() {
return this.masters;
}
/**
* @deprecated use `.slots[<SLOT>]` instead
* TODO
*/
getSlotMaster(slot: number) {
return this.slots[slot].master;
}
}

View File

@@ -1,141 +1,141 @@
import COMMANDS from './commands';
import { RedisCommand, RedisCommandArgument, RedisCommandArguments, RedisCommandRawReply, RedisFunctions, RedisModules, RedisExtensions, RedisScript, RedisScripts, ExcludeMappedString, RedisFunction } from '../commands';
import RedisMultiCommand, { RedisMultiQueuedCommand } from '../multi-command';
import { attachCommands, attachExtensions } from '../commander';
import RedisCluster from '.';
// import COMMANDS from './commands';
// import { RedisCommand, RedisCommandArgument, RedisCommandArguments, RedisCommandRawReply, RedisFunctions, RedisModules, RedisExtensions, RedisScript, RedisScripts, ExcludeMappedString, RedisFunction } from '../commands';
// import RedisMultiCommand, { RedisMultiQueuedCommand } from '../multi-command';
// import { attachCommands, attachExtensions } from '../commander';
// import RedisCluster from '.';
type RedisClusterMultiCommandSignature<
C extends RedisCommand,
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts
> = (...args: Parameters<C['transformArguments']>) => RedisClusterMultiCommandType<M, F, S>;
// type RedisClusterMultiCommandSignature<
// C extends RedisCommand,
// M extends RedisModules,
// F extends RedisFunctions,
// S extends RedisScripts
// > = (...args: Parameters<C['transformArguments']>) => RedisClusterMultiCommandType<M, F, S>;
type WithCommands<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts
> = {
[P in keyof typeof COMMANDS]: RedisClusterMultiCommandSignature<(typeof COMMANDS)[P], M, F, S>;
};
// type WithCommands<
// M extends RedisModules,
// F extends RedisFunctions,
// S extends RedisScripts
// > = {
// [P in keyof typeof COMMANDS]: RedisClusterMultiCommandSignature<(typeof COMMANDS)[P], M, F, S>;
// };
type WithModules<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts
> = {
[P in keyof M as ExcludeMappedString<P>]: {
[C in keyof M[P] as ExcludeMappedString<C>]: RedisClusterMultiCommandSignature<M[P][C], M, F, S>;
};
};
// type WithModules<
// M extends RedisModules,
// F extends RedisFunctions,
// S extends RedisScripts
// > = {
// [P in keyof M as ExcludeMappedString<P>]: {
// [C in keyof M[P] as ExcludeMappedString<C>]: RedisClusterMultiCommandSignature<M[P][C], M, F, S>;
// };
// };
type WithFunctions<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts
> = {
[P in keyof F as ExcludeMappedString<P>]: {
[FF in keyof F[P] as ExcludeMappedString<FF>]: RedisClusterMultiCommandSignature<F[P][FF], M, F, S>;
};
};
// type WithFunctions<
// M extends RedisModules,
// F extends RedisFunctions,
// S extends RedisScripts
// > = {
// [P in keyof F as ExcludeMappedString<P>]: {
// [FF in keyof F[P] as ExcludeMappedString<FF>]: RedisClusterMultiCommandSignature<F[P][FF], M, F, S>;
// };
// };
type WithScripts<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts
> = {
[P in keyof S as ExcludeMappedString<P>]: RedisClusterMultiCommandSignature<S[P], M, F, S>;
};
// type WithScripts<
// M extends RedisModules,
// F extends RedisFunctions,
// S extends RedisScripts
// > = {
// [P in keyof S as ExcludeMappedString<P>]: RedisClusterMultiCommandSignature<S[P], M, F, S>;
// };
export type RedisClusterMultiCommandType<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts
> = RedisClusterMultiCommand & WithCommands<M, F, S> & WithModules<M, F, S> & WithFunctions<M, F, S> & WithScripts<M, F, S>;
// export type RedisClusterMultiCommandType<
// M extends RedisModules,
// F extends RedisFunctions,
// S extends RedisScripts
// > = RedisClusterMultiCommand & WithCommands<M, F, S> & WithModules<M, F, S> & WithFunctions<M, F, S> & WithScripts<M, F, S>;
export type InstantiableRedisClusterMultiCommandType<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts
> = new (...args: ConstructorParameters<typeof RedisClusterMultiCommand>) => RedisClusterMultiCommandType<M, F, S>;
// export type InstantiableRedisClusterMultiCommandType<
// M extends RedisModules,
// F extends RedisFunctions,
// S extends RedisScripts
// > = new (...args: ConstructorParameters<typeof RedisClusterMultiCommand>) => RedisClusterMultiCommandType<M, F, S>;
export type RedisClusterMultiExecutor = (queue: Array<RedisMultiQueuedCommand>, firstKey?: RedisCommandArgument, 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: RedisCommandArgument | undefined;
// export default class RedisClusterMultiCommand {
// readonly #multi = new RedisMultiCommand();
// readonly #executor: RedisClusterMultiExecutor;
// #firstKey: RedisCommandArgument | undefined;
static extend<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts
>(extensions?: RedisExtensions<M, F, S>): InstantiableRedisClusterMultiCommandType<M, F, S> {
return attachExtensions({
BaseClass: RedisClusterMultiCommand,
modulesExecutor: RedisClusterMultiCommand.prototype.commandsExecutor,
modules: extensions?.modules,
functionsExecutor: RedisClusterMultiCommand.prototype.functionsExecutor,
functions: extensions?.functions,
scriptsExecutor: RedisClusterMultiCommand.prototype.scriptsExecutor,
scripts: extensions?.scripts
});
}
// static extend<
// M extends RedisModules,
// F extends RedisFunctions,
// S extends RedisScripts
// >(extensions?: RedisExtensions<M, F, S>): InstantiableRedisClusterMultiCommandType<M, F, S> {
// return attachExtensions({
// BaseClass: RedisClusterMultiCommand,
// modulesExecutor: RedisClusterMultiCommand.prototype.commandsExecutor,
// modules: extensions?.modules,
// functionsExecutor: RedisClusterMultiCommand.prototype.functionsExecutor,
// functions: extensions?.functions,
// scriptsExecutor: RedisClusterMultiCommand.prototype.scriptsExecutor,
// scripts: extensions?.scripts
// });
// }
constructor(executor: RedisClusterMultiExecutor, firstKey?: RedisCommandArgument) {
this.#executor = executor;
this.#firstKey = firstKey;
}
// constructor(executor: RedisClusterMultiExecutor, firstKey?: RedisCommandArgument) {
// this.#executor = executor;
// this.#firstKey = firstKey;
// }
commandsExecutor(command: RedisCommand, args: Array<unknown>): this {
const transformedArguments = command.transformArguments(...args);
this.#firstKey ??= RedisCluster.extractFirstKey(command, args, transformedArguments);
return this.addCommand(undefined, transformedArguments, command.transformReply);
}
// commandsExecutor(command: RedisCommand, args: Array<unknown>): this {
// const transformedArguments = command.transformArguments(...args);
// this.#firstKey ??= RedisCluster.extractFirstKey(command, args, transformedArguments);
// return this.addCommand(undefined, transformedArguments, command.transformReply);
// }
addCommand(
firstKey: RedisCommandArgument | undefined,
args: RedisCommandArguments,
transformReply?: RedisCommand['transformReply']
): this {
this.#firstKey ??= firstKey;
this.#multi.addCommand(args, transformReply);
return this;
}
// addCommand(
// firstKey: RedisCommandArgument | undefined,
// args: RedisCommandArguments,
// transformReply?: RedisCommand['transformReply']
// ): this {
// this.#firstKey ??= firstKey;
// this.#multi.addCommand(args, transformReply);
// return this;
// }
functionsExecutor(fn: RedisFunction, args: Array<unknown>, name: string): this {
const transformedArguments = this.#multi.addFunction(name, fn, args);
this.#firstKey ??= RedisCluster.extractFirstKey(fn, args, transformedArguments);
return this;
}
// functionsExecutor(fn: RedisFunction, args: Array<unknown>, name: string): this {
// const transformedArguments = this.#multi.addFunction(name, fn, args);
// this.#firstKey ??= RedisCluster.extractFirstKey(fn, args, transformedArguments);
// return this;
// }
scriptsExecutor(script: RedisScript, args: Array<unknown>): this {
const transformedArguments = this.#multi.addScript(script, args);
this.#firstKey ??= RedisCluster.extractFirstKey(script, args, transformedArguments);
return this;
}
// scriptsExecutor(script: RedisScript, args: Array<unknown>): this {
// const transformedArguments = this.#multi.addScript(script, args);
// this.#firstKey ??= RedisCluster.extractFirstKey(script, args, transformedArguments);
// return this;
// }
async exec(execAsPipeline = false): Promise<Array<RedisCommandRawReply>> {
if (execAsPipeline) {
return this.execAsPipeline();
}
// async exec(execAsPipeline = false): Promise<Array<RedisCommandRawReply>> {
// if (execAsPipeline) {
// return this.execAsPipeline();
// }
return this.#multi.handleExecReplies(
await this.#executor(this.#multi.queue, this.#firstKey, RedisMultiCommand.generateChainId())
);
}
// return this.#multi.handleExecReplies(
// await this.#executor(this.#multi.queue, this.#firstKey, RedisMultiCommand.generateChainId())
// );
// }
EXEC = this.exec;
// EXEC = this.exec;
async execAsPipeline(): Promise<Array<RedisCommandRawReply>> {
return this.#multi.transformReplies(
await this.#executor(this.#multi.queue, this.#firstKey)
);
}
}
// async execAsPipeline(): Promise<Array<RedisCommandRawReply>> {
// return this.#multi.transformReplies(
// await this.#executor(this.#multi.queue, this.#firstKey)
// );
// }
// }
attachCommands({
BaseClass: RedisClusterMultiCommand,
commands: COMMANDS,
executor: RedisClusterMultiCommand.prototype.commandsExecutor
});
// attachCommands({
// BaseClass: RedisClusterMultiCommand,
// commands: COMMANDS,
// executor: RedisClusterMultiCommand.prototype.commandsExecutor
// });