redis
Advanced tools
Comparing version 4.0.0-next.5 to 4.0.0-next.6
@@ -1,4 +0,6 @@ | ||
import RedisClient from './lib/client.js'; | ||
import RedisCluster from './lib/cluster.js'; | ||
import RedisClient from './lib/client'; | ||
import RedisCluster from './lib/cluster'; | ||
export declare const createClient: typeof RedisClient.create; | ||
export declare const commandOptions: typeof RedisClient.commandOptions; | ||
export declare const createCluster: typeof RedisCluster.create; | ||
export { defineScript } from './lib/lua-script'; |
@@ -6,6 +6,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createCluster = exports.createClient = void 0; | ||
const client_js_1 = __importDefault(require("./lib/client.js")); | ||
const cluster_js_1 = __importDefault(require("./lib/cluster.js")); | ||
exports.createClient = client_js_1.default.create; | ||
exports.createCluster = cluster_js_1.default.create; | ||
exports.defineScript = exports.createCluster = exports.commandOptions = exports.createClient = void 0; | ||
const client_1 = __importDefault(require("./lib/client")); | ||
const cluster_1 = __importDefault(require("./lib/cluster")); | ||
exports.createClient = client_1.default.create; | ||
exports.commandOptions = client_1.default.commandOptions; | ||
exports.createCluster = cluster_1.default.create; | ||
var lua_script_1 = require("./lib/lua-script"); | ||
Object.defineProperty(exports, "defineScript", { enumerable: true, get: function () { return lua_script_1.defineScript; } }); |
@@ -13,2 +13,3 @@ /// <reference types="node" /> | ||
import { HScanTuple } from './commands/HSCAN'; | ||
import { Options as PoolOptions } from 'generic-pool'; | ||
export interface RedisClientOptions<M = RedisModules, S = RedisLuaScripts> { | ||
@@ -21,2 +22,3 @@ socket?: RedisSocketOptions; | ||
legacyMode?: boolean; | ||
isolationPoolOptions?: PoolOptions; | ||
} | ||
@@ -38,3 +40,3 @@ export declare type RedisCommandSignature<C extends RedisCommand> = (...args: Parameters<C['transformArguments']> | [options: CommandOptions<ClientCommandOptions>, ...rest: Parameters<C['transformArguments']>]) => Promise<ReturnType<C['transformReply']>>; | ||
export interface ClientCommandOptions extends QueueCommandOptions { | ||
duplicateConnection?: boolean; | ||
isolated?: boolean; | ||
} | ||
@@ -68,2 +70,3 @@ export default class RedisClient<M extends RedisModules = RedisModules, S extends RedisLuaScripts = RedisLuaScripts> extends EventEmitter { | ||
sendEncodedCommand<T = RedisReply>(encodedCommand: string, options?: ClientCommandOptions): Promise<T>; | ||
executeIsolated<T>(fn: (client: RedisClientType<M, S>) => T | Promise<T>): Promise<T>; | ||
executeScript(script: RedisLuaScript, args: Array<string>, options?: ClientCommandOptions): Promise<ReturnType<typeof script['transformReply']>>; | ||
@@ -70,0 +73,0 @@ multi(): RedisMultiCommandType<M, S>; |
@@ -35,3 +35,3 @@ "use strict"; | ||
}; | ||
var _RedisClient_instances, _a, _RedisClient_scriptsExecutor, _RedisClient_options, _RedisClient_socket, _RedisClient_queue, _RedisClient_Multi, _RedisClient_v4, _RedisClient_selectedDB, _RedisClient_initiateSocket, _RedisClient_initiateQueue, _RedisClient_legacyMode, _RedisClient_defineLegacyCommand, _RedisClient_subscribe, _RedisClient_unsubscribe, _RedisClient_sendCommand, _RedisClient_duplicateConnection, _RedisClient_multiExecutor, _RedisClient_isTickQueued, _RedisClient_tick; | ||
var _RedisClient_instances, _a, _RedisClient_scriptsExecutor, _RedisClient_options, _RedisClient_socket, _RedisClient_queue, _RedisClient_isolationPool, _RedisClient_v4, _RedisClient_selectedDB, _RedisClient_initiateSocket, _RedisClient_initiateQueue, _RedisClient_legacyMode, _RedisClient_defineLegacyCommand, _RedisClient_subscribe, _RedisClient_unsubscribe, _RedisClient_sendCommand, _RedisClient_multiExecutor, _RedisClient_destroyIsolationPool, _RedisClient_isTickQueued, _RedisClient_tick; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -45,2 +45,3 @@ const socket_1 = __importDefault(require("./socket")); | ||
const commander_1 = require("./commander"); | ||
const generic_pool_1 = require("generic-pool"); | ||
class RedisClient extends events_1.default { | ||
@@ -53,3 +54,3 @@ constructor(options) { | ||
_RedisClient_queue.set(this, void 0); | ||
_RedisClient_Multi.set(this, void 0); | ||
_RedisClient_isolationPool.set(this, void 0); | ||
_RedisClient_v4.set(this, {}); | ||
@@ -91,3 +92,10 @@ _RedisClient_selectedDB.set(this, 0); | ||
__classPrivateFieldSet(this, _RedisClient_queue, __classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_initiateQueue).call(this), "f"); | ||
__classPrivateFieldSet(this, _RedisClient_Multi, multi_command_1.default.extend(options), "f"); | ||
__classPrivateFieldSet(this, _RedisClient_isolationPool, generic_pool_1.createPool({ | ||
create: async () => { | ||
const duplicate = this.duplicate(); | ||
await duplicate.connect(); | ||
return duplicate; | ||
}, | ||
destroy: client => client.disconnect() | ||
}, options === null || options === void 0 ? void 0 : options.isolationPoolOptions), "f"); | ||
__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_legacyMode).call(this); | ||
@@ -104,3 +112,3 @@ } | ||
static create(options) { | ||
return new (commander_1.extendWithModulesAndScripts({ | ||
const Client = commander_1.extendWithModulesAndScripts({ | ||
BaseClass: RedisClient, | ||
@@ -111,3 +119,7 @@ modules: options === null || options === void 0 ? void 0 : options.modules, | ||
scriptsExecutor: __classPrivateFieldGet(RedisClient, _a, "m", _RedisClient_scriptsExecutor) | ||
}))(options); | ||
}); | ||
if (Client !== RedisClient) { | ||
Client.prototype.Multi = multi_command_1.default.extend(options); | ||
} | ||
return new Client(options); | ||
} | ||
@@ -157,14 +169,7 @@ get options() { | ||
async sendEncodedCommand(encodedCommand, options) { | ||
if (options === null || options === void 0 ? void 0 : options.duplicateConnection) { | ||
const duplicate = this.duplicate(); | ||
await duplicate.connect(); | ||
try { | ||
return await duplicate.sendEncodedCommand(encodedCommand, { | ||
...options, | ||
duplicateConnection: false | ||
}); | ||
} | ||
finally { | ||
await duplicate.disconnect(); | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.isolated) { | ||
return this.executeIsolated(isolatedClient => isolatedClient.sendEncodedCommand(encodedCommand, { | ||
...options, | ||
isolated: false | ||
})); | ||
} | ||
@@ -175,2 +180,5 @@ const promise = __classPrivateFieldGet(this, _RedisClient_queue, "f").addEncodedCommand(encodedCommand, options); | ||
} | ||
executeIsolated(fn) { | ||
return __classPrivateFieldGet(this, _RedisClient_isolationPool, "f").use(fn); | ||
} | ||
async executeScript(script, args, options) { | ||
@@ -181,3 +189,3 @@ var _b, _c; | ||
'EVALSHA', | ||
script.SHA, | ||
script.SHA1, | ||
script.NUMBER_OF_KEYS.toString(), | ||
@@ -200,3 +208,3 @@ ...args | ||
multi() { | ||
return new (__classPrivateFieldGet(this, _RedisClient_Multi, "f"))(__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_multiExecutor).bind(this), __classPrivateFieldGet(this, _RedisClient_options, "f")); | ||
return new this.Multi(__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_multiExecutor).bind(this), __classPrivateFieldGet(this, _RedisClient_options, "f")); | ||
} | ||
@@ -243,9 +251,12 @@ async *scanIterator(options) { | ||
} | ||
disconnect() { | ||
async disconnect() { | ||
__classPrivateFieldGet(this, _RedisClient_queue, "f").flushAll(new Error('Disconnecting')); | ||
return __classPrivateFieldGet(this, _RedisClient_socket, "f").disconnect(); | ||
await Promise.all([ | ||
__classPrivateFieldGet(this, _RedisClient_socket, "f").disconnect(), | ||
__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_destroyIsolationPool).call(this) | ||
]); | ||
} | ||
} | ||
exports.default = RedisClient; | ||
_a = RedisClient, _RedisClient_options = new WeakMap(), _RedisClient_socket = new WeakMap(), _RedisClient_queue = new WeakMap(), _RedisClient_Multi = new WeakMap(), _RedisClient_v4 = new WeakMap(), _RedisClient_selectedDB = new WeakMap(), _RedisClient_isTickQueued = new WeakMap(), _RedisClient_instances = new WeakSet(), _RedisClient_scriptsExecutor = async function _RedisClient_scriptsExecutor(script, args) { | ||
_a = RedisClient, _RedisClient_options = new WeakMap(), _RedisClient_socket = new WeakMap(), _RedisClient_queue = new WeakMap(), _RedisClient_isolationPool = new WeakMap(), _RedisClient_v4 = new WeakMap(), _RedisClient_selectedDB = new WeakMap(), _RedisClient_isTickQueued = new WeakMap(), _RedisClient_instances = new WeakSet(), _RedisClient_scriptsExecutor = async function _RedisClient_scriptsExecutor(script, args) { | ||
const { args: redisArgs, options } = commander_1.transformCommandArguments(script, args); | ||
@@ -342,4 +353,3 @@ const reply = script.transformReply(await this.executeScript(script, redisArgs, options), redisArgs.preserve); | ||
return this.sendEncodedCommand(commander_1.encodeCommand(args), options); | ||
}, _RedisClient_duplicateConnection = async function _RedisClient_duplicateConnection(fn) { | ||
}, _RedisClient_multiExecutor = async function _RedisClient_multiExecutor(commands, chainId) { | ||
}, _RedisClient_multiExecutor = function _RedisClient_multiExecutor(commands, chainId) { | ||
const promise = Promise.all(commands.map(({ encodedCommand }) => { | ||
@@ -351,3 +361,6 @@ return __classPrivateFieldGet(this, _RedisClient_queue, "f").addEncodedCommand(encodedCommand, RedisClient.commandOptions({ | ||
__classPrivateFieldGet(this, _RedisClient_instances, "m", _RedisClient_tick).call(this); | ||
return await promise; | ||
return promise; | ||
}, _RedisClient_destroyIsolationPool = async function _RedisClient_destroyIsolationPool() { | ||
await __classPrivateFieldGet(this, _RedisClient_isolationPool, "f").drain(); | ||
await __classPrivateFieldGet(this, _RedisClient_isolationPool, "f").clear(); | ||
}, _RedisClient_tick = function _RedisClient_tick() { | ||
@@ -374,1 +387,2 @@ const { chunkRecommendedSize } = __classPrivateFieldGet(this, _RedisClient_socket, "f"); | ||
commander_1.extendWithDefaultCommands(RedisClient, RedisClient.commandsExecutor); | ||
RedisClient.prototype.Multi = multi_command_1.default.extend(); |
@@ -6,3 +6,2 @@ import { RedisCommand, RedisModules } from './commands'; | ||
import { RedisLuaScript, RedisLuaScripts } from './lua-script'; | ||
import { CommandOptions } from './command-options'; | ||
import { RedisMultiCommandType } from './multi-command'; | ||
@@ -21,3 +20,2 @@ export interface RedisClusterOptions<M = RedisModules, S = RedisLuaScripts> { | ||
static create<M extends RedisModules, S extends RedisLuaScripts>(options?: RedisClusterOptions<M, S>): RedisClusterType<M, S>; | ||
static commandOptions(options: ClientCommandOptions): CommandOptions<ClientCommandOptions>; | ||
constructor(options: RedisClusterOptions<M, S>); | ||
@@ -24,0 +22,0 @@ connect(): Promise<void>; |
@@ -20,3 +20,2 @@ "use strict"; | ||
const cluster_slots_1 = __importDefault(require("./cluster-slots")); | ||
const command_options_1 = require("./command-options"); | ||
const commander_1 = require("./commander"); | ||
@@ -48,5 +47,2 @@ const multi_command_1 = __importDefault(require("./multi-command")); | ||
} | ||
static commandOptions(options) { | ||
return command_options_1.commandOptions(options); | ||
} | ||
async connect() { | ||
@@ -53,0 +49,0 @@ return __classPrivateFieldGet(this, _RedisCluster_slots, "f").connect(); |
@@ -18,15 +18,26 @@ "use strict"; | ||
function extendWithModulesAndScripts(config) { | ||
let Commander, modulesBaseObject; | ||
let Commander; | ||
if (config.modules) { | ||
modulesBaseObject = Object.create(null); | ||
Commander = class extends config.BaseClass { | ||
constructor(...args) { | ||
super(...args); | ||
modulesBaseObject.self = this; | ||
for (const module of Object.keys(config.modules)) { | ||
this[module] = new this[module](this); | ||
} | ||
} | ||
}; | ||
for (const [moduleName, module] of Object.entries(config.modules)) { | ||
Commander.prototype[moduleName] = Object.create(modulesBaseObject); | ||
Commander.prototype[moduleName] = class { | ||
constructor(self) { | ||
Object.defineProperty(this, "self", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
this.self = self; | ||
} | ||
}; | ||
for (const [commandName, command] of Object.entries(module)) { | ||
Commander.prototype[moduleName][commandName] = function (...args) { | ||
Commander.prototype[moduleName].prototype[commandName] = function (...args) { | ||
return config.modulesCommandsExecutor.call(this.self, command, args); | ||
@@ -33,0 +44,0 @@ }; |
@@ -100,5 +100,2 @@ "use strict"; | ||
}; | ||
if (options.signal.aborted) { | ||
return listener(); | ||
} | ||
node.value.abort = { | ||
@@ -105,0 +102,0 @@ signal: options.signal, |
@@ -6,12 +6,5 @@ "use strict"; | ||
function transformArguments(username) { | ||
const args = ['ACL', 'DELUSER']; | ||
if (typeof username === 'string') { | ||
args.push(username); | ||
} | ||
else { | ||
args.push(...username); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['ACL', 'DELUSER'], username); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -6,12 +6,5 @@ "use strict"; | ||
function transformArguments(username, rule) { | ||
const args = ['ACL', 'SETUSER', username]; | ||
if (typeof rule === 'string') { | ||
args.push(rule); | ||
} | ||
else { | ||
args.push(...rule); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['ACL', 'SETUSER', username], rule); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyString; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(operation, destKey, key) { | ||
const args = ['BITOP', operation, destKey]; | ||
if (typeof key === 'string') { | ||
args.push(key); | ||
} | ||
else { | ||
args.push(...key); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['BITOP', operation, destKey], key); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0; | ||
const generic_transformers_1 = require("./generic-transformers"); | ||
exports.FIRST_KEY_INDEX = 1; | ||
function transformArguments(keys, timeout) { | ||
const args = ['BLPOP']; | ||
if (typeof keys === 'string') { | ||
args.push(keys); | ||
} | ||
else { | ||
args.push(...keys); | ||
} | ||
const args = generic_transformers_1.pushVerdictArguments(['BLPOP'], keys); | ||
args.push(timeout.toString()); | ||
@@ -14,0 +9,0 @@ return args; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0; | ||
const generic_transformers_1 = require("./generic-transformers"); | ||
exports.FIRST_KEY_INDEX = 1; | ||
function transformArguments(key, timeout) { | ||
const args = ['BRPOP']; | ||
if (typeof key === 'string') { | ||
args.push(key); | ||
} | ||
else { | ||
args.push(...key); | ||
} | ||
const args = generic_transformers_1.pushVerdictArguments(['BRPOP'], key); | ||
args.push(timeout.toString()); | ||
@@ -14,0 +9,0 @@ return args; |
@@ -7,9 +7,3 @@ "use strict"; | ||
function transformArguments(key, timeout) { | ||
const args = ['BZPOPMAX']; | ||
if (typeof key === 'string') { | ||
args.push(key); | ||
} | ||
else { | ||
args.push(...key); | ||
} | ||
const args = generic_transformers_1.pushVerdictArguments(['BZPOPMAX'], key); | ||
args.push(timeout.toString()); | ||
@@ -16,0 +10,0 @@ return args; |
@@ -7,9 +7,3 @@ "use strict"; | ||
function transformArguments(key, timeout) { | ||
const args = ['BZPOPMIN']; | ||
if (typeof key === 'string') { | ||
args.push(key); | ||
} | ||
else { | ||
args.push(...key); | ||
} | ||
const args = generic_transformers_1.pushVerdictArguments(['BZPOPMIN'], key); | ||
args.push(timeout.toString()); | ||
@@ -16,0 +10,0 @@ return args; |
@@ -6,12 +6,5 @@ "use strict"; | ||
function transformArguments(keys) { | ||
const args = ['DEL']; | ||
if (typeof keys === 'string') { | ||
args.push(keys); | ||
} | ||
else { | ||
args.push(...keys); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['DEL'], keys); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -8,12 +8,5 @@ "use strict"; | ||
function transformArguments(keys) { | ||
const args = ['EXISTS']; | ||
if (typeof keys === 'string') { | ||
args.push(keys); | ||
} | ||
else { | ||
args.push(...keys); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['EXISTS'], keys); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyBoolean; |
@@ -0,1 +1,2 @@ | ||
import { TransformArgumentsReply } from '.'; | ||
export declare function transformReplyNumber(reply: number): number; | ||
@@ -95,2 +96,7 @@ export declare function transformReplyNumberNull(reply: number | null): number | null; | ||
export declare function pushEvalArguments(args: Array<string>, options?: EvalOptions): Array<string>; | ||
export declare type StringTuplesArguments = Array<[string, string]> | Array<string> | Record<string, string>; | ||
export declare function pushStringTuplesArguments(args: Array<string>, tuples: StringTuplesArguments): Array<string>; | ||
export declare function pushVerdictArguments(args: TransformArgumentsReply, value: string | Array<string>): TransformArgumentsReply; | ||
export declare function pushVerdictArgument(args: TransformArgumentsReply, value: string | Array<string>): TransformArgumentsReply; | ||
export declare function pushOptionalVerdictArgument(args: TransformArgumentsReply, name: string, value: undefined | string | Array<string>): TransformArgumentsReply; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pushEvalArguments = exports.transformPXAT = exports.transformEXAT = exports.transformGeoMembersWithReply = exports.GeoReplyWith = exports.pushGeoSearchArguments = exports.pushGeoCountArgument = exports.transformReplySortedSetWithScores = exports.transformReplyStreamsMessagesNull = exports.transformReplyStreamsMessages = exports.transformReplyStreamMessages = exports.transformReplyTuples = exports.transformArgumentNumberInfinity = exports.transformReplyNumberInfinityNullArray = exports.transformReplyNumberInfinityNull = exports.transformReplyNumberInfinityArray = exports.transformReplyNumberInfinity = exports.pushScanArguments = exports.transformReplyVoid = exports.transformReplyBit = exports.transformReplyBooleanArray = exports.transformReplyBoolean = exports.transformReplyStringNullArray = exports.transformReplyStringArrayNull = exports.transformReplyStringArray = exports.transformReplyStringNull = exports.transformReplyString = exports.transformReplyNumberNullArray = exports.transformReplyNumberArray = exports.transformReplyNumberNull = exports.transformReplyNumber = void 0; | ||
exports.pushOptionalVerdictArgument = exports.pushVerdictArgument = exports.pushVerdictArguments = exports.pushStringTuplesArguments = exports.pushEvalArguments = exports.transformPXAT = exports.transformEXAT = exports.transformGeoMembersWithReply = exports.GeoReplyWith = exports.pushGeoSearchArguments = exports.pushGeoCountArgument = exports.transformReplySortedSetWithScores = exports.transformReplyStreamsMessagesNull = exports.transformReplyStreamsMessages = exports.transformReplyStreamMessages = exports.transformReplyTuples = exports.transformArgumentNumberInfinity = exports.transformReplyNumberInfinityNullArray = exports.transformReplyNumberInfinityNull = exports.transformReplyNumberInfinityArray = exports.transformReplyNumberInfinity = exports.pushScanArguments = exports.transformReplyVoid = exports.transformReplyBit = exports.transformReplyBooleanArray = exports.transformReplyBoolean = exports.transformReplyStringNullArray = exports.transformReplyStringArrayNull = exports.transformReplyStringArray = exports.transformReplyStringNull = exports.transformReplyString = exports.transformReplyNumberNullArray = exports.transformReplyNumberArray = exports.transformReplyNumberNull = exports.transformReplyNumber = void 0; | ||
function transformReplyNumber(reply) { | ||
@@ -232,1 +232,40 @@ return reply; | ||
exports.pushEvalArguments = pushEvalArguments; | ||
function pushStringTuplesArguments(args, tuples) { | ||
if (Array.isArray(tuples)) { | ||
args.push(...tuples.flat()); | ||
} | ||
else { | ||
for (const key of Object.keys(tuples)) { | ||
args.push(key, tuples[key]); | ||
} | ||
} | ||
return args; | ||
} | ||
exports.pushStringTuplesArguments = pushStringTuplesArguments; | ||
function pushVerdictArguments(args, value) { | ||
if (typeof value === 'string') { | ||
args.push(value); | ||
} | ||
else { | ||
args.push(...value); | ||
} | ||
return args; | ||
} | ||
exports.pushVerdictArguments = pushVerdictArguments; | ||
function pushVerdictArgument(args, value) { | ||
if (typeof value === 'string') { | ||
args.push('1', value); | ||
} | ||
else { | ||
args.push(value.length.toString(), ...value); | ||
} | ||
return args; | ||
} | ||
exports.pushVerdictArgument = pushVerdictArgument; | ||
function pushOptionalVerdictArgument(args, name, value) { | ||
if (value === undefined) | ||
return args; | ||
args.push(name); | ||
return pushVerdictArgument(args, value); | ||
} | ||
exports.pushOptionalVerdictArgument = pushOptionalVerdictArgument; |
@@ -8,12 +8,5 @@ "use strict"; | ||
function transformArguments(key, member) { | ||
const args = ['GEOHASH', key]; | ||
if (typeof member === 'string') { | ||
args.push(member); | ||
} | ||
else { | ||
args.push(...member); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['GEOHASH', key], member); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyStringArray; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transformReply = exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0; | ||
const generic_transformers_1 = require("./generic-transformers"); | ||
exports.FIRST_KEY_INDEX = 1; | ||
exports.IS_READ_ONLY = true; | ||
function transformArguments(key, member) { | ||
const args = ['GEOPOS', key]; | ||
if (typeof member === 'string') { | ||
args.push(member); | ||
} | ||
else { | ||
args.push(...member); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['GEOPOS', key], member); | ||
} | ||
@@ -16,0 +10,0 @@ exports.transformArguments = transformArguments; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(key, field) { | ||
const args = ['HDEL', key]; | ||
if (typeof field === 'string') { | ||
args.push(field); | ||
} | ||
else { | ||
args.push(...field); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['HDEL', key], field); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
import { AuthOptions } from './AUTH'; | ||
export declare function transformArguments(protover?: number, auth?: AuthOptions): Array<string>; | ||
interface HelloOptions { | ||
protover: number; | ||
auth?: Required<AuthOptions>; | ||
clientName?: string; | ||
} | ||
export declare function transformArguments(options?: HelloOptions): Array<string>; | ||
declare type HelloRawReply = [ | ||
_: never, | ||
server: string, | ||
_: never, | ||
version: string, | ||
_: never, | ||
proto: number, | ||
_: never, | ||
id: number, | ||
_: never, | ||
mode: string, | ||
_: never, | ||
role: string, | ||
_: never, | ||
modules: Array<string> | ||
]; | ||
interface HelloTransformedReply { | ||
server: string; | ||
version: string; | ||
proto: number; | ||
id: number; | ||
mode: string; | ||
role: string; | ||
modules: Array<string>; | ||
} | ||
export declare function transformReply(reply: HelloRawReply): HelloTransformedReply; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transformArguments = void 0; | ||
const AUTH_1 = require("./AUTH"); | ||
function transformArguments(protover, auth) { | ||
exports.transformReply = exports.transformArguments = void 0; | ||
function transformArguments(options) { | ||
const args = ['HELLO']; | ||
if (protover) { | ||
args.push(protover.toString()); | ||
if (options) { | ||
args.push(options.protover.toString()); | ||
if (options === null || options === void 0 ? void 0 : options.auth) { | ||
args.push('AUTH', options.auth.username, options.auth.password); | ||
} | ||
if (options.clientName) { | ||
args.push('SETNAME', options.clientName); | ||
} | ||
} | ||
if (auth) { | ||
args.push(...AUTH_1.transformArguments(auth)); | ||
} | ||
return args; | ||
} | ||
exports.transformArguments = transformArguments; | ||
function transformReply(reply) { | ||
return { | ||
server: reply[1], | ||
version: reply[3], | ||
proto: reply[5], | ||
id: reply[7], | ||
mode: reply[9], | ||
role: reply[11], | ||
modules: reply[13] | ||
}; | ||
} | ||
exports.transformReply = transformReply; |
@@ -8,12 +8,5 @@ "use strict"; | ||
function transformArguments(key, fields) { | ||
const args = ['HMGET', key]; | ||
if (typeof fields === 'string') { | ||
args.push(fields); | ||
} | ||
else { | ||
args.push(...fields); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['HMGET', key], fields); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyStringArray; |
import { transformReplyString } from './generic-transformers'; | ||
declare type HSETObject = Record<string | number, string | number>; | ||
declare type HSETMap = Map<string | number, string | number>; | ||
export declare function transformArguments(key: string, objectOrMap: HSETObject | HSETMap): Array<string>; | ||
declare type HSETTuples = Array<[string, string]> | Array<string>; | ||
export declare const FIRST_KEY_INDEX = 1; | ||
export declare function transformArguments(key: string, value: HSETObject | HSETMap | HSETTuples): Array<string>; | ||
export declare const transformReply: typeof transformReplyString; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transformReply = exports.transformArguments = void 0; | ||
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0; | ||
const generic_transformers_1 = require("./generic-transformers"); | ||
function transformArguments(key, objectOrMap) { | ||
var _a, _b; | ||
const flattenArgs = (_b = (_a = mapArgumentTransformer(key, objectOrMap)) !== null && _a !== void 0 ? _a : objectArgumentTransformer(key, objectOrMap)) !== null && _b !== void 0 ? _b : []; | ||
// TODO: add support for tuples | ||
flattenArgs.unshift('HSET'); | ||
return flattenArgs; | ||
exports.FIRST_KEY_INDEX = 1; | ||
function transformArguments(key, value) { | ||
const args = ['HSET', key]; | ||
if (value instanceof Map) { | ||
pushMap(args, value); | ||
} | ||
else if (Array.isArray(value)) { | ||
pushTuples(args, value); | ||
} | ||
else if (typeof value === 'object' && value !== null) { | ||
pushObject(args, value); | ||
} | ||
return args; | ||
} | ||
exports.transformArguments = transformArguments; | ||
function mapArgumentTransformer(key, map) { | ||
if (!(map instanceof Map)) | ||
return; | ||
const flat = [key]; | ||
function pushMap(args, map) { | ||
for (const [key, value] of map.entries()) { | ||
flat.push(key.toString(), value.toString()); | ||
args.push(key.toString(), value.toString()); | ||
} | ||
return flat; | ||
} | ||
function isObject(obj) { | ||
return typeof obj === 'object' && obj !== null && !Array.isArray(obj); | ||
function pushTuples(args, tuples) { | ||
args.push(...tuples.flat()); | ||
} | ||
function objectArgumentTransformer(key, obj) { | ||
if (!isObject(obj)) { | ||
return; | ||
function pushObject(args, object) { | ||
for (const key of Object.keys(object)) { | ||
args.push(key.toString(), object[key].toString()); | ||
} | ||
const flat = [key]; | ||
for (const key of Object.keys(obj)) { | ||
flat.push(key.toString(), obj[key].toString()); | ||
} | ||
return flat; | ||
} | ||
exports.transformReply = generic_transformers_1.transformReplyString; |
@@ -70,2 +70,3 @@ import * as ACL_CAT from './ACL_CAT'; | ||
import * as HDEL from './HDEL'; | ||
import * as HELLO from './HELLO'; | ||
import * as HEXISTS from './HEXISTS'; | ||
@@ -120,2 +121,3 @@ import * as HGET from './HGET'; | ||
import * as MSET from './MSET'; | ||
import * as MSETNX from './MSETNX'; | ||
import * as PERSIST from './PERSIST'; | ||
@@ -151,2 +153,7 @@ import * as PEXPIRE from './PEXPIRE'; | ||
import * as SCARD from './SCARD'; | ||
import * as SCRIPT_DEBUG from './SCRIPT_DEBUG'; | ||
import * as SCRIPT_EXISTS from './SCRIPT_EXISTS'; | ||
import * as SCRIPT_FLUSH from './SCRIPT_FLUSH'; | ||
import * as SCRIPT_KILL from './SCRIPT_KILL'; | ||
import * as SCRIPT_LOAD from './SCRIPT_LOAD'; | ||
import * as SDIFF from './SDIFF'; | ||
@@ -379,2 +386,4 @@ import * as SDIFFSTORE from './SDIFFSTORE'; | ||
hDel: typeof HDEL; | ||
HELLO: typeof HELLO; | ||
hello: typeof HELLO; | ||
HEXISTS: typeof HEXISTS; | ||
@@ -477,2 +486,4 @@ hExists: typeof HEXISTS; | ||
mSet: typeof MSET; | ||
MSETNX: typeof MSETNX; | ||
mSetNX: typeof MSETNX; | ||
PERSIST: typeof PERSIST; | ||
@@ -538,2 +549,12 @@ persist: typeof PERSIST; | ||
sCard: typeof SCARD; | ||
SCRIPT_DEBUG: typeof SCRIPT_DEBUG; | ||
scriptDebug: typeof SCRIPT_DEBUG; | ||
SCRIPT_EXISTS: typeof SCRIPT_EXISTS; | ||
scriptExists: typeof SCRIPT_EXISTS; | ||
SCRIPT_FLUSH: typeof SCRIPT_FLUSH; | ||
scriptFlush: typeof SCRIPT_FLUSH; | ||
SCRIPT_KILL: typeof SCRIPT_KILL; | ||
scriptKill: typeof SCRIPT_KILL; | ||
SCRIPT_LOAD: typeof SCRIPT_LOAD; | ||
scriptLoad: typeof SCRIPT_LOAD; | ||
SDIFF: typeof SDIFF; | ||
@@ -540,0 +561,0 @@ sDiff: typeof SDIFF; |
@@ -91,2 +91,3 @@ "use strict"; | ||
const HDEL = __importStar(require("./HDEL")); | ||
const HELLO = __importStar(require("./HELLO")); | ||
const HEXISTS = __importStar(require("./HEXISTS")); | ||
@@ -141,2 +142,3 @@ const HGET = __importStar(require("./HGET")); | ||
const MSET = __importStar(require("./MSET")); | ||
const MSETNX = __importStar(require("./MSETNX")); | ||
const PERSIST = __importStar(require("./PERSIST")); | ||
@@ -172,2 +174,7 @@ const PEXPIRE = __importStar(require("./PEXPIRE")); | ||
const SCARD = __importStar(require("./SCARD")); | ||
const SCRIPT_DEBUG = __importStar(require("./SCRIPT_DEBUG")); | ||
const SCRIPT_EXISTS = __importStar(require("./SCRIPT_EXISTS")); | ||
const SCRIPT_FLUSH = __importStar(require("./SCRIPT_FLUSH")); | ||
const SCRIPT_KILL = __importStar(require("./SCRIPT_KILL")); | ||
const SCRIPT_LOAD = __importStar(require("./SCRIPT_LOAD")); | ||
const SDIFF = __importStar(require("./SDIFF")); | ||
@@ -400,2 +407,4 @@ const SDIFFSTORE = __importStar(require("./SDIFFSTORE")); | ||
hDel: HDEL, | ||
HELLO, | ||
hello: HELLO, | ||
HEXISTS, | ||
@@ -498,2 +507,4 @@ hExists: HEXISTS, | ||
mSet: MSET, | ||
MSETNX, | ||
mSetNX: MSETNX, | ||
PERSIST, | ||
@@ -559,2 +570,12 @@ persist: PERSIST, | ||
sCard: SCARD, | ||
SCRIPT_DEBUG, | ||
scriptDebug: SCRIPT_DEBUG, | ||
SCRIPT_EXISTS, | ||
scriptExists: SCRIPT_EXISTS, | ||
SCRIPT_FLUSH, | ||
scriptFlush: SCRIPT_FLUSH, | ||
SCRIPT_KILL, | ||
scriptKill: SCRIPT_KILL, | ||
SCRIPT_LOAD, | ||
scriptLoad: SCRIPT_LOAD, | ||
SDIFF, | ||
@@ -561,0 +582,0 @@ sDiff: SDIFF, |
@@ -7,15 +7,5 @@ "use strict"; | ||
function transformArguments(key, elements) { | ||
const args = [ | ||
'LPUSH', | ||
key | ||
]; | ||
if (typeof elements === 'string') { | ||
args.push(elements); | ||
} | ||
else { | ||
args.push(...elements); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['LPUSH', key], elements); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -7,15 +7,5 @@ "use strict"; | ||
function transformArguments(key, element) { | ||
const args = [ | ||
'LPUSHX', | ||
key | ||
]; | ||
if (typeof element === 'string') { | ||
args.push(element); | ||
} | ||
else { | ||
args.push(...element); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['LPUSHX', key], element); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -1,3 +0,4 @@ | ||
import { transformReplyBoolean } from './generic-transformers'; | ||
export declare function transformArguments(key: string, db: number): Array<string>; | ||
export declare const transformReply: typeof transformReplyBoolean; | ||
import { transformReplyString } from './generic-transformers'; | ||
export declare const FIRST_KEY_INDEX = 1; | ||
export declare function transformArguments(toSet: Array<[string, string]> | Array<string> | Record<string, string>): Array<string>; | ||
export declare const transformReply: typeof transformReplyString; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transformReply = exports.transformArguments = void 0; | ||
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0; | ||
const generic_transformers_1 = require("./generic-transformers"); | ||
function transformArguments(key, db) { | ||
return ['MSET', key, db.toString()]; | ||
exports.FIRST_KEY_INDEX = 1; | ||
function transformArguments(toSet) { | ||
const args = ['MSET']; | ||
if (Array.isArray(toSet)) { | ||
args.push(...toSet.flat()); | ||
} | ||
else { | ||
for (const key of Object.keys(toSet)) { | ||
args.push(key, toSet[key]); | ||
} | ||
} | ||
return args; | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyBoolean; | ||
exports.transformReply = generic_transformers_1.transformReplyString; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(key, element) { | ||
const args = ['PFADD', key]; | ||
if (typeof element === 'string') { | ||
args.push(element); | ||
} | ||
else { | ||
args.push(...element); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['PFADD', key], element); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyBoolean; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(key) { | ||
const args = ['PFCOUNT']; | ||
if (typeof key === 'string') { | ||
args.push(key); | ||
} | ||
else { | ||
args.push(...key); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['PFCOUNT'], key); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(destination, source) { | ||
const args = ['PFMERGE', destination]; | ||
if (typeof source === 'string') { | ||
args.push(source); | ||
} | ||
else { | ||
args.push(...source); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['PFMERGE', destination], source); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyString; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transformReply = exports.transformArguments = exports.IS_READ_ONLY = void 0; | ||
const generic_transformers_1 = require("./generic-transformers"); | ||
exports.IS_READ_ONLY = true; | ||
function transformArguments(channels) { | ||
const args = ['PUBSUB', 'NUMSUB']; | ||
if (Array.isArray(channels)) { | ||
args.push(...channels); | ||
if (channels) { | ||
generic_transformers_1.pushVerdictArguments(args, channels); | ||
} | ||
else if (typeof channels === 'string') { | ||
args.push(channels); | ||
} | ||
return args; | ||
@@ -14,0 +12,0 @@ } |
@@ -7,15 +7,5 @@ "use strict"; | ||
function transformArguments(key, element) { | ||
const args = [ | ||
'RPUSH', | ||
key | ||
]; | ||
if (typeof element === 'string') { | ||
args.push(element); | ||
} | ||
else { | ||
args.push(...element); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['RPUSH', key], element); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -7,15 +7,5 @@ "use strict"; | ||
function transformArguments(key, element) { | ||
const args = [ | ||
'RPUSHX', | ||
key | ||
]; | ||
if (typeof element === 'string') { | ||
args.push(element); | ||
} | ||
else { | ||
args.push(...element); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['RPUSHX', key], element); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(key, members) { | ||
const args = ['SADD', key]; | ||
if (typeof members === 'string') { | ||
args.push(members); | ||
} | ||
else { | ||
args.push(...members); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['SADD', key], members); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(keys) { | ||
const args = ['SDIFF']; | ||
if (typeof keys === 'string') { | ||
args.push(keys); | ||
} | ||
else { | ||
args.push(...keys); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['SDIFF'], keys); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyStringArray; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(destination, keys) { | ||
const args = ['SDIFFSTORE', destination]; | ||
if (typeof keys === 'string') { | ||
args.push(keys); | ||
} | ||
else { | ||
args.push(...keys); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['SDIFFSTORE', destination], keys); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(keys) { | ||
const args = ['SINTER']; | ||
if (typeof keys === 'string') { | ||
args.push(keys); | ||
} | ||
else { | ||
args.push(...keys); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['SINTER'], keys); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyStringArray; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(destination, keys) { | ||
const args = ['SINTERSTORE', destination]; | ||
if (typeof keys === 'string') { | ||
args.push(keys); | ||
} | ||
else { | ||
args.push(...keys); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['SINTERSTORE', destination], keys); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyStringArray; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(key, members) { | ||
const args = ['SREM', key]; | ||
if (typeof members === 'string') { | ||
args.push(members); | ||
} | ||
else { | ||
args.push(...members); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['SREM', key], members); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -8,12 +8,5 @@ "use strict"; | ||
function transformArguments(keys) { | ||
const args = ['SUNION']; | ||
if (typeof keys === 'string') { | ||
args.push(keys); | ||
} | ||
else { | ||
args.push(...keys); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['SUNION'], keys); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyStringArray; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(destination, keys) { | ||
const args = ['SUNIONSTORE', destination]; | ||
if (typeof keys === 'string') { | ||
args.push(keys); | ||
} | ||
else { | ||
args.push(...keys); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['SUNIONSTORE', destination], keys); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(key) { | ||
const args = ['TOUCH']; | ||
if (typeof key === 'string') { | ||
args.push(key); | ||
} | ||
else { | ||
args.push(...key); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['TOUCH'], key); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(key) { | ||
const args = ['UNLINK']; | ||
if (typeof key === 'string') { | ||
args.push(key); | ||
} | ||
else { | ||
args.push(...key); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['UNLINK'], key); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -6,12 +6,5 @@ "use strict"; | ||
function transformArguments(key) { | ||
const args = ['WATCH']; | ||
if (typeof key === 'string') { | ||
args.push(key); | ||
} | ||
else { | ||
args.push(...key); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['WATCH'], key); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyString; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(key, group, id) { | ||
const args = ['XACK', key, group]; | ||
if (typeof id === 'string') { | ||
args.push(id); | ||
} | ||
else { | ||
args.push(...id); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['XACK', key, group], id); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -8,8 +8,3 @@ "use strict"; | ||
const args = ['XCLAIM', key, group, consumer, minIdleTime.toString()]; | ||
if (typeof id === 'string') { | ||
args.push(id); | ||
} | ||
else { | ||
args.push(...id); | ||
} | ||
generic_transformers_1.pushVerdictArguments(args, id); | ||
if (options === null || options === void 0 ? void 0 : options.IDLE) { | ||
@@ -16,0 +11,0 @@ args.push('IDLE', options.IDLE.toString()); |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(key, id) { | ||
const args = ['XDEL', key]; | ||
if (typeof id === 'string') { | ||
args.push(id); | ||
} | ||
else { | ||
args.push(...id); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['XDEL', key], id); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -8,12 +8,5 @@ "use strict"; | ||
function transformArguments(keys) { | ||
const args = ['ZDIFF']; | ||
if (typeof keys === 'string') { | ||
args.push('1', keys); | ||
} | ||
else { | ||
args.push(keys.length.toString(), ...keys); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArgument(['ZDIFF'], keys); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyStringArray; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(destination, keys) { | ||
const args = ['ZDIFFSTORE', destination]; | ||
if (typeof keys === 'string') { | ||
args.push('1', keys); | ||
} | ||
else { | ||
args.push(keys.length.toString(), ...keys); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArgument(['ZDIFFSTORE', destination], keys); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -8,9 +8,3 @@ "use strict"; | ||
function transformArguments(keys, options) { | ||
const args = ['ZINTER']; | ||
if (typeof keys === 'string') { | ||
args.push('1', keys); | ||
} | ||
else { | ||
args.push(keys.length.toString(), ...keys); | ||
} | ||
const args = generic_transformers_1.pushVerdictArgument(['ZINTER'], keys); | ||
if (options === null || options === void 0 ? void 0 : options.WEIGHTS) { | ||
@@ -17,0 +11,0 @@ args.push('WEIGHTS', ...options.WEIGHTS.map(weight => weight.toString())); |
@@ -7,9 +7,3 @@ "use strict"; | ||
function transformArguments(destination, keys, options) { | ||
const args = ['ZINTERSTORE', destination]; | ||
if (typeof keys === 'string') { | ||
args.push('1', keys); | ||
} | ||
else { | ||
args.push(keys.length.toString(), ...keys); | ||
} | ||
const args = generic_transformers_1.pushVerdictArgument(['ZINTERSTORE', destination], keys); | ||
if (options === null || options === void 0 ? void 0 : options.WEIGHTS) { | ||
@@ -16,0 +10,0 @@ args.push('WEIGHTS', ...options.WEIGHTS.map(weight => weight.toString())); |
@@ -8,12 +8,5 @@ "use strict"; | ||
function transformArguments(key, member) { | ||
const args = ['ZMSCORE', key]; | ||
if (typeof member === 'string') { | ||
args.push(member); | ||
} | ||
else { | ||
args.push(...member); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['ZMSCORE', key], member); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumberInfinityNullArray; |
@@ -7,12 +7,5 @@ "use strict"; | ||
function transformArguments(key, member) { | ||
const args = ['ZREM', key]; | ||
if (typeof member === 'string') { | ||
args.push(member); | ||
} | ||
else { | ||
args.push(...member); | ||
} | ||
return args; | ||
return generic_transformers_1.pushVerdictArguments(['ZREM', key], member); | ||
} | ||
exports.transformArguments = transformArguments; | ||
exports.transformReply = generic_transformers_1.transformReplyNumber; |
@@ -8,9 +8,3 @@ "use strict"; | ||
function transformArguments(keys, options) { | ||
const args = ['ZUNION']; | ||
if (typeof keys === 'string') { | ||
args.push('1', keys); | ||
} | ||
else { | ||
args.push(keys.length.toString(), ...keys); | ||
} | ||
const args = generic_transformers_1.pushVerdictArgument(['ZUNION'], keys); | ||
if (options === null || options === void 0 ? void 0 : options.WEIGHTS) { | ||
@@ -17,0 +11,0 @@ args.push('WEIGHTS', ...options.WEIGHTS.map(weight => weight.toString())); |
@@ -7,9 +7,3 @@ "use strict"; | ||
function transformArguments(destination, keys, options) { | ||
const args = ['ZUNIONSTORE', destination]; | ||
if (typeof keys === 'string') { | ||
args.push('1', keys); | ||
} | ||
else { | ||
args.push(keys.length.toString(), ...keys); | ||
} | ||
const args = generic_transformers_1.pushVerdictArgument(['ZUNIONSTORE', destination], keys); | ||
if (options === null || options === void 0 ? void 0 : options.WEIGHTS) { | ||
@@ -16,0 +10,0 @@ args.push('WEIGHTS', ...options.WEIGHTS.map(weight => weight.toString())); |
export declare class AbortError extends Error { | ||
constructor(); | ||
} | ||
export declare class WatchError extends Error { | ||
constructor(); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AbortError = void 0; | ||
exports.WatchError = exports.AbortError = void 0; | ||
class AbortError extends Error { | ||
@@ -10,1 +10,7 @@ constructor() { | ||
exports.AbortError = AbortError; | ||
class WatchError extends Error { | ||
constructor() { | ||
super('One (or more) of the watched keys has been changed'); | ||
} | ||
} | ||
exports.WatchError = WatchError; |
@@ -6,10 +6,10 @@ import { RedisCommand } from './commands'; | ||
} | ||
interface SHA { | ||
SHA: string; | ||
export interface SHA1 { | ||
SHA1: string; | ||
} | ||
export declare type RedisLuaScript = RedisLuaScriptConfig & SHA; | ||
export declare type RedisLuaScript = RedisLuaScriptConfig & SHA1; | ||
export interface RedisLuaScripts { | ||
[key: string]: RedisLuaScript; | ||
} | ||
export declare function defineScript<S extends RedisLuaScriptConfig>(script: S): S & SHA; | ||
export {}; | ||
export declare function defineScript<S extends RedisLuaScriptConfig>(script: S): S & SHA1; | ||
export declare function scriptSha1(script: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defineScript = void 0; | ||
exports.scriptSha1 = exports.defineScript = void 0; | ||
const crypto_1 = require("crypto"); | ||
@@ -8,5 +8,9 @@ function defineScript(script) { | ||
...script, | ||
SHA: crypto_1.createHash('sha1').update(script.SCRIPT).digest('hex') | ||
SHA1: scriptSha1(script.SCRIPT) | ||
}; | ||
} | ||
exports.defineScript = defineScript; | ||
function scriptSha1(script) { | ||
return crypto_1.createHash('sha1').update(script).digest('hex'); | ||
} | ||
exports.scriptSha1 = scriptSha1; |
@@ -23,3 +23,3 @@ import COMMANDS, { TransformArgumentsReply } from './commands'; | ||
} | ||
export declare type RedisMultiExecutor = (queue: Array<MultiQueuedCommand>, chainId?: symbol) => Promise<Array<RedisReply>>; | ||
export declare type RedisMultiExecutor = (queue: Array<MultiQueuedCommand>, chainId?: symbol) => Promise<null | Array<RedisReply>>; | ||
export default class RedisMultiCommand<M extends RedisModules = RedisModules, S extends RedisLuaScripts = RedisLuaScripts> { | ||
@@ -33,5 +33,5 @@ #private; | ||
addCommand(args: TransformArgumentsReply, transformReply?: RedisCommand['transformReply']): this; | ||
exec(execAsPipeline?: boolean): Promise<Array<unknown>>; | ||
execAsPipeline(): Promise<Array<unknown>>; | ||
exec(execAsPipeline?: boolean): Promise<Array<RedisReply>>; | ||
execAsPipeline(): Promise<Array<RedisReply>>; | ||
} | ||
export {}; |
@@ -16,6 +16,7 @@ "use strict"; | ||
}; | ||
var _RedisMultiCommand_instances, _a, _RedisMultiCommand_scriptsExecutor, _RedisMultiCommand_executor, _RedisMultiCommand_clientOptions, _RedisMultiCommand_queue, _RedisMultiCommand_scriptsInUse, _RedisMultiCommand_v4, _RedisMultiCommand_legacyMode, _RedisMultiCommand_defineLegacyCommand; | ||
var _RedisMultiCommand_instances, _a, _RedisMultiCommand_scriptsExecutor, _RedisMultiCommand_executor, _RedisMultiCommand_clientOptions, _RedisMultiCommand_queue, _RedisMultiCommand_scriptsInUse, _RedisMultiCommand_v4, _RedisMultiCommand_legacyMode, _RedisMultiCommand_defineLegacyCommand, _RedisMultiCommand_handleNullReply, _RedisMultiCommand_transformReplies; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const commands_1 = __importDefault(require("./commands")); | ||
const commander_1 = require("./commander"); | ||
const errors_1 = require("./errors"); | ||
class RedisMultiCommand { | ||
@@ -70,14 +71,12 @@ constructor(executor, clientOptions) { | ||
} | ||
const queue = __classPrivateFieldGet(this, _RedisMultiCommand_queue, "f").splice(0); | ||
queue.unshift({ | ||
encodedCommand: commander_1.encodeCommand(['MULTI']) | ||
}); | ||
queue.push({ | ||
encodedCommand: commander_1.encodeCommand(['EXEC']) | ||
}); | ||
const rawReplies = await __classPrivateFieldGet(this, _RedisMultiCommand_executor, "f").call(this, queue, Symbol('[RedisMultiCommand] Chain ID')); | ||
return rawReplies[rawReplies.length - 1].map((reply, i) => { | ||
const { transformReply, preservedArguments } = queue[i + 1]; | ||
return transformReply ? transformReply(reply, preservedArguments) : reply; | ||
}); | ||
const queue = __classPrivateFieldGet(this, _RedisMultiCommand_queue, "f").splice(0), rawReplies = __classPrivateFieldGet(this, _RedisMultiCommand_instances, "m", _RedisMultiCommand_handleNullReply).call(this, await __classPrivateFieldGet(this, _RedisMultiCommand_executor, "f").call(this, [ | ||
{ | ||
encodedCommand: commander_1.encodeCommand(['MULTI']) | ||
}, | ||
...queue, | ||
{ | ||
encodedCommand: commander_1.encodeCommand(['EXEC']) | ||
} | ||
], Symbol('[RedisMultiCommand] Chain ID'))); | ||
return __classPrivateFieldGet(this, _RedisMultiCommand_instances, "m", _RedisMultiCommand_transformReplies).call(this, rawReplies[rawReplies.length - 1], queue); | ||
} | ||
@@ -88,3 +87,4 @@ async execAsPipeline() { | ||
} | ||
return await __classPrivateFieldGet(this, _RedisMultiCommand_executor, "f").call(this, __classPrivateFieldGet(this, _RedisMultiCommand_queue, "f").splice(0)); | ||
const queue = __classPrivateFieldGet(this, _RedisMultiCommand_queue, "f").splice(0); | ||
return __classPrivateFieldGet(this, _RedisMultiCommand_instances, "m", _RedisMultiCommand_transformReplies).call(this, __classPrivateFieldGet(this, _RedisMultiCommand_instances, "m", _RedisMultiCommand_handleNullReply).call(this, await __classPrivateFieldGet(this, _RedisMultiCommand_executor, "f").call(this, queue)), queue); | ||
} | ||
@@ -95,7 +95,7 @@ } | ||
const transformedArguments = []; | ||
if (__classPrivateFieldGet(this, _RedisMultiCommand_scriptsInUse, "f").has(script.SHA)) { | ||
transformedArguments.push('EVALSHA', script.SHA); | ||
if (__classPrivateFieldGet(this, _RedisMultiCommand_scriptsInUse, "f").has(script.SHA1)) { | ||
transformedArguments.push('EVALSHA', script.SHA1); | ||
} | ||
else { | ||
__classPrivateFieldGet(this, _RedisMultiCommand_scriptsInUse, "f").add(script.SHA); | ||
__classPrivateFieldGet(this, _RedisMultiCommand_scriptsInUse, "f").add(script.SHA1); | ||
transformedArguments.push('EVAL', script.SCRIPT); | ||
@@ -141,3 +141,13 @@ } | ||
this[name] = (...args) => this.addCommand(name, args); | ||
}, _RedisMultiCommand_handleNullReply = function _RedisMultiCommand_handleNullReply(reply) { | ||
if (reply === null) { | ||
throw new errors_1.WatchError(); | ||
} | ||
return reply; | ||
}, _RedisMultiCommand_transformReplies = function _RedisMultiCommand_transformReplies(rawReplies, queue) { | ||
return rawReplies.map((reply, i) => { | ||
const { transformReply, preservedArguments } = queue[i]; | ||
return transformReply ? transformReply(reply, preservedArguments) : reply; | ||
}); | ||
}; | ||
commander_1.extendWithDefaultCommands(RedisMultiCommand, RedisMultiCommand.commandsExecutor); |
/// <reference types="node" /> | ||
import EventEmitter from 'events'; | ||
import tls from 'tls'; | ||
interface RedisSocketCommonOptions { | ||
export interface RedisSocketCommonOptions { | ||
username?: string; | ||
@@ -9,13 +9,13 @@ password?: string; | ||
} | ||
interface RedisNetSocketOptions extends RedisSocketCommonOptions { | ||
export interface RedisNetSocketOptions extends RedisSocketCommonOptions { | ||
port?: number; | ||
host?: string; | ||
} | ||
interface RedisUrlSocketOptions extends RedisSocketCommonOptions { | ||
export interface RedisUrlSocketOptions extends RedisSocketCommonOptions { | ||
url: string; | ||
} | ||
interface RedisUnixSocketOptions extends RedisSocketCommonOptions { | ||
export interface RedisUnixSocketOptions extends RedisSocketCommonOptions { | ||
path: string; | ||
} | ||
interface RedisTlsSocketOptions extends RedisNetSocketOptions { | ||
export interface RedisTlsSocketOptions extends RedisNetSocketOptions { | ||
tls: tls.SecureContextOptions; | ||
@@ -34,2 +34,1 @@ } | ||
} | ||
export {}; |
{ | ||
"name": "redis", | ||
"version": "4.0.0-next.5", | ||
"version": "4.0.0-next.6", | ||
"description": "A high performance Redis client.", | ||
@@ -31,2 +31,3 @@ "keywords": [ | ||
"cluster-key-slot": "1.1.0", | ||
"generic-pool": "3.8.2", | ||
"redis-parser": "3.0.0", | ||
@@ -38,3 +39,3 @@ "yallist": "4.0.0" | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^16.4.5", | ||
"@types/node": "^16.6.2", | ||
"@types/sinon": "^10.0.2", | ||
@@ -45,7 +46,7 @@ "@types/which": "^2.0.1", | ||
"nyc": "^15.1.0", | ||
"release-it": "^14.10.1", | ||
"release-it": "^14.11.5", | ||
"sinon": "^11.1.2", | ||
"source-map-support": "^0.5.19", | ||
"ts-node": "^10.1.0", | ||
"typedoc": "^0.21.4", | ||
"ts-node": "^10.2.1", | ||
"typedoc": "^0.21.5", | ||
"typedoc-github-wiki-theme": "^0.5.1", | ||
@@ -52,0 +53,0 @@ "typedoc-plugin-markdown": "^3.10.4", |
@@ -49,12 +49,24 @@ > :warning: Version 4 is still under development and isn't ready for production use. Use at your own risk. | ||
The new interface is clean and cool, but if you have an existing code base, you might want to enable [legacy mode](#legacy-mode). | ||
The above code only connects to localhost on port 6379. You probably want to connect to somewhere else. To do so, use a connection string in the format `[redis[s]:]//[[username][:password@]][host][:port]`: | ||
```typescript | ||
createClient({ | ||
socket: { | ||
url: 'redis://alice:foobared@awesome.redis.server:6380' | ||
} | ||
}); | ||
``` | ||
You can also use discrete parameters, UNIX sockets, and even TLS to connect. Details can be found in in the [Wiki](https://github.com/NodeRedis/node-redis/wiki/lib.socket#RedisSocketOptions). | ||
> The new interface is clean and cool, but if you have an existing code base, you might want to enable [legacy mode](#legacy-mode). | ||
### Redis Commands | ||
There is built-in support for all of the [out-of-the-box Redis commands](https://redis.io/commands). They are exposed using the raw Redis command names (`HGET`, `HSET`, etc.) and a friendlier camel-cased version (`hGet`, `hSet`, etc.): | ||
There is built-in support for all of the [out-of-the-box Redis commands](https://redis.io/commands). They are exposed using the raw Redis command names (`HSET`, `HGETALL`, etc.) and a friendlier camel-cased version (`hSet`, `hGetAll`, etc.): | ||
```typescript | ||
// raw Redis commands | ||
await client.SET('key', 'value'); | ||
await client.GET('key'); | ||
await client.HSET('key', 'field', 'value'); | ||
await client.HGETALL('key'); | ||
@@ -75,7 +87,7 @@ // friendly JavaScript commands | ||
Replies will be transformed to useful data structures: | ||
Replies will be transformed into useful data structures: | ||
```typescript | ||
await client.hGetAll('key'); // { key1: 'value1', key2: 'value2' } | ||
await client.hKeys('key'); // ['key1', 'key2'] | ||
await client.hGetAll('key'); // { field1: 'value1', field2: 'value2' } | ||
await client.hVals('key'); // ['value1', 'value2'] | ||
``` | ||
@@ -85,3 +97,3 @@ | ||
If you want to run commands and arguments that Node Redis doesn't know about (yet!) you can use `.sendCommand`: | ||
If you want to run commands and/or use arguments that Node Redis doesn't know about (yet!) you can use `.sendCommand()`: | ||
@@ -96,30 +108,21 @@ ```typescript | ||
Start [transactions](https://redis.io/topics/transactions) with a call to `.multi()` and then chain your commands. At the end call `.exec()` and you'll get an array back with the results of your commands: | ||
Start a [transaction](https://redis.io/topics/transactions) by calling `.multi()`, then chaining your commands. When you're done, call `.exec()` and you'll get an array back with your results: | ||
```typescript | ||
await client.set('another-key', 'another-value'); | ||
const [ setKeyReply, otherKeyValue ] = await client.multi() | ||
.set('key', 'value') | ||
.get('other-key') | ||
.get('another-key') | ||
.exec() | ||
]); // ['OK', null] | ||
]); // ['OK', 'another-value'] | ||
``` | ||
You can also watch keys by calling `.watch()`. If someone else changes them out from underneath you, your transaction will abort: | ||
You can also [watch](https://redis.io/topics/transactions#optimistic-locking-using-check-and-set) keys by calling `.watch()`. Your transaction will abort if any of the watched keys change. | ||
```typescript | ||
await client.watch('other-key'); | ||
try { | ||
await client.multi() | ||
.set('key', 'value') | ||
.get('other-key') | ||
.exec() | ||
]); | ||
} catch (err) { | ||
// ... | ||
} | ||
``` | ||
To dig deeper into transactions, check out the [Isolated Execution Guide](./docs/isolated-execution.md). | ||
### Blocking Commands | ||
Any command can be run on a new connection by specifying the `duplicateConnection` option. The newly created connection is closed when the command's `Promise` is fulfilled. | ||
Any command can be run on a new connection by specifying the `isolated` option. The newly created connection is closed when the command's `Promise` is fulfilled. | ||
@@ -129,4 +132,6 @@ This pattern works especially well for blocking commands—such as `BLPOP` and `BLMOVE`: | ||
```typescript | ||
import { commandOptions } from 'redis'; | ||
const blPopPromise = client.blPop( | ||
client.commandOptions({ duplicateConnection: true }), | ||
commandOptions({ isolated: true }), | ||
'key' | ||
@@ -140,7 +145,17 @@ ); | ||
To learn more about isolated execution, check out the [guide](./docs/isolated-execution.md). | ||
### Pub/Sub | ||
Subscribing to a channel requires a dedicated Redis connection and is easily handled using events: | ||
Subscribing to a channel requires a dedicated stand-alone connection. You can easily get one by `.duplicate()`ing an existing Redis connection. | ||
```typescript | ||
const subscriber = client.duplicate(); | ||
await subscriber.connect(); | ||
``` | ||
Once you have one, simply subscribe and unsubscribe as needed: | ||
```typescript | ||
await subscriber.subscribe('channel', message => { | ||
@@ -154,2 +169,10 @@ console.log(message); // 'message' | ||
await subscriber.unsubscribe('channel'); | ||
await subscriber.pUnsubscribe('channe*'); | ||
``` | ||
Publish a message on a channel: | ||
```typescript | ||
await publisher.publish('channel', 'message'); | ||
@@ -169,3 +192,3 @@ ``` | ||
This works with HSCAN, SSCAN, and ZSCAN too: | ||
This works with `HSCAN`, `SSCAN`, and `ZSCAN` too: | ||
@@ -190,7 +213,6 @@ ```typescript | ||
You can define Lua scripts to create efficient custom commands: | ||
You can define [Lua scripts](https://redis.io/commands/eval) to create efficient custom commands: | ||
```typescript | ||
import { createClient } from 'redis'; | ||
import { defineScript } from 'redis/dist/lib/lua-script'; | ||
import { createClient, defineScript } from 'redis'; | ||
@@ -224,3 +246,3 @@ (async () => { | ||
Connecting to a cluster is a bit different. Create the client by specifying the root nodes in your cluster and then use it like a non-clustered client: | ||
Connecting to a cluster is a bit different. Create the client by specifying some (or all) of the nodes in your cluster and then use it like a non-clustered client: | ||
@@ -233,6 +255,6 @@ ```typescript | ||
rootNodes: [{ | ||
host: '192.168.1.1', | ||
host: '10.0.0.1', | ||
port: 30001 | ||
}, { | ||
host: '192.168.1.2', | ||
host: '10.0.0.2', | ||
port: 30002 | ||
@@ -239,0 +261,0 @@ }] |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
523
289
0
2
441159
4
8659
+ Addedgeneric-pool@3.8.2
+ Addedgeneric-pool@3.8.2(transitive)