@silverwind/ioredis-mock
Version:
This library emulates ioredis by performing all operations in-memory.
36 lines (30 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.evalsha = evalsha;
var _command = _interopRequireDefault(require("../command"));
var _defineCommand = require("./defineCommand");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* EVALSHA redis command
* https://redis.io/commands/evalsha
*
* Before using it, you need to:
* 1) call your LUA script using EVAL first, to load it into memory
* 2) calculate sha1 hash of your script, e.g. using the function in src/commands-utils/sha1.js
*
* The rest is exactly like calling EVAL
*
* @param sha1
* @param numberOfKeys
* @param args
* @returns {*|Promise<unknown>}
*/
function evalsha(sha1, numberOfKeys, ...args) {
if (!(sha1 in this.shaScripts) || !this.shaScripts[sha1]) {
throw new Error(`NOSCRIPT for sha1 ${sha1}`);
}
const script = this.shaScripts[sha1];
return (0, _command.default)((0, _defineCommand.customCommand)(numberOfKeys, script).bind(this), '', this)(...args);
}