New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

redis-mock

Package Overview
Dependencies
Maintainers
3
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-mock

Redis client mock object for unit testing

  • 0.56.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
126K
decreased by-5.25%
Maintainers
3
Weekly downloads
 
Created

What is redis-mock?

The redis-mock npm package is a mock implementation of the Redis API, which allows developers to test their applications without needing a real Redis server. It is particularly useful for unit testing and development environments where setting up a real Redis server might be cumbersome or unnecessary.

What are redis-mock's main functionalities?

Basic Redis Commands

This feature allows you to use basic Redis commands like SET and GET. The mock client behaves like a real Redis client, making it easy to test code that interacts with Redis.

const redis = require('redis-mock');
const client = redis.createClient();

client.set('key', 'value', (err, reply) => {
  console.log(reply); // OK
});

client.get('key', (err, reply) => {
  console.log(reply); // value
});

Pub/Sub

This feature allows you to use the publish/subscribe (Pub/Sub) pattern. You can subscribe to channels and publish messages to those channels, which is useful for testing real-time messaging in your application.

const redis = require('redis-mock');
const pub = redis.createClient();
const sub = redis.createClient();

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

sub.subscribe('channel1');

pub.publish('channel1', 'message1');

Hash Operations

This feature allows you to perform hash operations like HSET and HGET. It is useful for testing code that deals with Redis hashes.

const redis = require('redis-mock');
const client = redis.createClient();

client.hset('hash', 'field1', 'value1', (err, reply) => {
  console.log(reply); // 1
});

client.hget('hash', 'field1', (err, reply) => {
  console.log(reply); // value1
});

Other packages similar to redis-mock

Keywords

FAQs

Package last updated on 23 Dec 2020

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc