Socket
Book a DemoInstallSign in
Socket

ioredis-mock

Package Overview
Dependencies
Maintainers
1
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ioredis-mock

This library emulates ioredis by performing all operations in-memory.

8.9.0
latest
Source
npmnpm
Version published
Weekly downloads
697K
-7.93%
Maintainers
1
Weekly downloads
 
Created

What is ioredis-mock?

ioredis-mock is a mock implementation of the ioredis library, which is used for interacting with Redis databases. This package is particularly useful for testing purposes, as it allows developers to simulate Redis operations without needing a real Redis server.

What are ioredis-mock's main functionalities?

Basic Redis Commands

This feature allows you to perform basic Redis commands such as SET and GET. The code sample demonstrates setting a key-value pair and then retrieving the value.

const Redis = require('ioredis-mock');
const redis = new Redis();

redis.set('key', 'value').then(() => {
  return redis.get('key');
}).then(value => {
  console.log(value); // 'value'
});

Pub/Sub

This feature allows you to use the publish/subscribe pattern. The code sample demonstrates subscribing to a channel and publishing a message to that channel.

const Redis = require('ioredis-mock');
const pub = new Redis();
const sub = new Redis();

sub.subscribe('channel', (err, count) => {
  pub.publish('channel', 'message');
});

sub.on('message', (channel, message) => {
  console.log(channel, message); // 'channel', 'message'
});

Transactions

This feature allows you to perform transactions using the MULTI command. The code sample demonstrates setting a key-value pair and then retrieving the value within a transaction.

const Redis = require('ioredis-mock');
const redis = new Redis();

redis.multi()
  .set('key', 'value')
  .get('key')
  .exec((err, results) => {
    console.log(results); // [[null, 'OK'], [null, 'value']]
  });

Other packages similar to ioredis-mock

Keywords

fakeredis

FAQs

Package last updated on 29 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.