Registry / testing / redis-eval-mock

redis-eval-mock

JSON →
library1.0.1jsnpmunverified

A mock of Redis EVAL functionality for testing Lua scripts in Node.js. Version 1.0.1, last updated in 2019, with no active development. It integrates with existing redis mocks like redis-mock and provides mock implementations of cjson and cmsgpack libraries. It allows testing Lua scripts without a real Redis server, but note that evalsha always throws NOSCRIPT as there is no script cache. The package ships TypeScript types and has a peer dependency on @types/redis. It is a niche testing utility, not updated recently.

npm install redis-eval-mock
INSTALL
IMPORT
SIG · REDIS-EVAL-MOCK
R
redis-eval-mock
testingjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import mockEval from 'redis-eval-mock'
✗ const mockEval = require('redis-eval-mock')
The package is ESM-only with a default export. Using require may cause issues if the package does not export a CommonJS module.
mockEval
✓ import mockEval from 'redis-eval-mock'
✗ import { mockEval } from 'redis-eval-mock'
The default export is a function; there is no named export 'mockEval'.
Function
✓ import type { Function } from ''; // Not exported
✗ No type imports available from this package
The package does not export any types; you can use the types from @types/redis for the return value.

Creates a mocked Redis client with eval support for testing Lua scripts in Node.js.

import * as redis from 'redis'; import * as mock from 'redis-mock'; import mockEval from 'redis-eval-mock'; // Set up mock Redis client with eval mocking const client = mockEval(mock.createClient()); // Now you can use eval as if it were real Redis client.eval('return 1', 0, (err, result) => { if (err) throw err; console.log(result); // 1 }); // evalsha will always throw NOSCRIPT client.evalsha('some-sha', 0, (err, result) => { console.log(err.message); // NOSCRIPT No matching script });
Debug
Known issues
gotchaevalsha always throws NOSCRIPT error because the mock does not implement a script cache.
fix
If you need to test evalsha, you will need to extend the mock or use a different library.
affects: >=1.0.0
deprecatedPackage has not been updated since 2019 and may not work with newer versions of Node.js or TypeScript.
fix
Consider testing with a real Redis instance or using alternatives like ioredis-mock.
affects: >=1.0.0
gotchaThe package relies on @types/redis as a peer dependency; without it, TypeScript compilation may fail.
fix
Install @types/redis as a dev dependency.
affects: >=1.0.0
breakingIn version 1.0.0, the package switched from CommonJS to ESM-only exports, breaking require() usage.
fix
Use import syntax instead of require().
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: mockEval is not a function
Using named import { mockEval } instead of default import.
fix
Use `import mockEval from 'redis-eval-mock'` (without curly braces).
Cannot find module '@types/redis'
Missing peer dependency @types/redis.
fix
Run `npm install --save-dev @types/redis`.
Error: NOSCRIPT No matching script
The mock does not implement script caching, so evalsha always fails.
fix
If you need to test evalsha, consider using a different mocking strategy or a real Redis server.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
@types/redisrequiredpeer dependency for TypeScript type definitions
Agent activity
8 hits · last 30 days
node
8
Resources
redis-eval-mock — npm install redis-eval-mock · libregistry