npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fakeredis

v2.0.0

Published

Fake redis for testing, works as a drop-in replacement for node_redis

Downloads

52,876

Readme

fakeredis

npm version Build Status Coverage Status Code Climate Dependency Status

a fake redis for node.js

This module provides easy-to-use simulated instances of Redis to which you appear to be connected via the redis client by Matt Ranney. It helps with writing tests in two ways: your tests won't require an actual redis instance and you'll be able to safely run as many tests in parallel as you want.

NPM Version

Usage

Install:

npm install fakeredis

You can use fakeredis as you would use node_redis, just changing the module name from redis to fakeredis:

var client = require("fakeredis").createClient(port, host);

Both parameters are optional, and only serve to determine if you want to reuse a an existing fakeredis instance or not. You can also just name your backends arbitrarily:


// Create a connection to a fresh fakeredis instance:
var client = fakeredis.createClient("social stuff");

// Connect to the same backend via another simulated connection:
var concurrentClient = fakeredis.createClient("social stuff");

By omitting both parameters, you simply create a new blank slate fakeredis instance:

var client = require("fakeredis").createClient();

In other words, every time you create a client specifying the same port and/or name you reuse the same simulated backend. This makes most sense when you need a concurrent client setup for some test, say because you need to publish / subscribe, or because you want to test something that's based on MULTI/EXEC and uses optimistic locking with WATCH/UNWATCH.

In any case, fakeredis is great for testing because you can run as many tests in parallel as you wish, and that's also why you'll generally be naming your clients in a way that ensures tests don't collide.

By default fakeredis simulates network latency to help you discover race-conditions when testing multi-client setups. Network latency can be disabled using the .fast option:

var client = require("fakeredis").createClient(port, host, {
    fast : true
});

Intended differences from a true Redis

One key difference is that the output of some commands, such as SMEMBERS, HKEYS, HVALS, comes out sorted lexicographically to provide for simpler testing. This means that some tests that make use of undocumented Redis behaviours such as the chronological order of retrieval for members in a set may fail when attempted with fakeredis. To solve this, whenever there is no documented sort order for a given Redis command's multi-bulk reply, sort the output before asserting equality to ensure your tests run everywhere.

Another major difference is that commands that accept modifier parameters, such as SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination] currently only accept these parameters in the order that is stated in the documentation. For example, in Redis it appears to be perfectly legitimate to have SORT myset ALPHA LIMIT 0 5, but in fakeredis this will currently return a syntax error.

I'm totally open to discussion on both points.

Implemented subset:

Fakeredis is still mostly stuck in the Redis 2.4 era.

All Redis 2.4 string, list, hash, set and sorted set commands, most keyspace commands, and some connection and server commands. Pubsub, transactions with optimistic locking are also fully implemented.

List of available commands:

Keyspace:

DBSIZE
EXISTS
EXPIRE
EXPIREAT
FLUSHDB
KEYS
PERSIST
DEL
RANDOMKEY
RENAME
RENAMENX
SORT
TTL
TYPE

Strings:

APPEND
BITCOUNT
DECR
DECRBY
GET
GETBIT
GETRANGE
GETSET
INCR
INCRBY
MGET
MSET
MSETNX
SET
SETBIT
SETEX
SETNX
SETRANGE

Hashes:

HDEL
HEXISTS
HGET
HGETALL
HINCRBY
HKEYS
HLEN
HMGET
HMSET
HSET
HSETNX
HVALS

Lists:

BLPOP
BRPOP
BRPOPLPUSH
LINDEX
LINSERT
LLEN
LPOP
LPUSH
LPUSHX
LRANGE
LREM
LSET
LTRIM
RPOP
RPOPLPUSH
RPUSH
RPUSHX

Sets:

SADD
SCARD
SDIFF
SDIFFSTORE
SINTER
SINTERSTORE
SISMEMBER
SMEMBERS
SMOVE
SPOP
SRANDMEMBER
SREM
STRLEN
SUNION
SUNIONSTORE

Sorted Sets:

ZADD
ZCARD
ZCOUNT
ZINCRBY
ZINTERSTORE
ZRANGE
ZRANGEBYSCORE
ZRANK
ZREM
ZREMRANGEBYRANK
ZREMRANGEBYSCORE
ZREVRANGE
ZREVRANGEBYSCORE
ZREVRANK
ZSCORE
ZUNIONSTORE

Pub/Sub:

PSUBSCRIBE
PUBLISH
PUNSUBSCRIBE
SUBSCRIBE
UNSUBSCRIBE

Transactions:

DISCARD
EXEC
MULTI
UNWATCH
WATCH

Connection and Server:

ECHO
PING
QUIT
SELECT

These do nothing but return OK:

AUTH
BGREWRITEAOF
BGSAVE
SAVE

What's missing:

Most notably, there's no support for Lua scripting and MONITOR is still missing.

None of the ready, connect, error, end, drain and idle client events are currently implemented.

List of missing commands (will throw upon attempt to use):

Connection and Server:

CONFIG GET
CONFIG SET
CONFIG RESETSTAT
DEBUG OBJECT
DEBUG SEGFAULT
FLUSHALL
INFO
LASTSAVE
MONITOR
MOVE
OBJECT
SHUTDOWN
SLAVEOF
SYNC

License

MIT.