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

redis-memory-server

v0.11.0

Published

Redis Server for testing. The server will allow you to connect your favorite client library to the Redis Server and run parallel integration tests isolated from each other.

Downloads

139,119

Readme

Redis In-Memory Server

This package spins up a real Redis server programmatically from Node.js, for testing or mocking during development. It holds the data in memory. Each redis-server process takes about 4Mb of memory. The server will allow you to connect your favorite client library to the Redis server and run integration tests isolated from each other.

It is inspired heavily by mongodb-memory-server.

On install, it downloads the Redis source, compiles the redis-server binary, and saves it to a cache folder.

On starting a new instance of the in-memory server, if the binary cannot be found, it will be downloaded and compiled; thus, the first run may take some time. All further runs will be fast because they will use the downloaded binaries.

This package automatically downloads source code from https://download.redis.io/.

Every RedisMemoryServer instance starts a fresh Redis server on a free port. You may start up several redis-server processes simultaneously. When you terminate your script or call stop(), the Redis server(s) will be automatically shut down.

It works in Travis CI without additional services or addons in .travis.yml.

Installation

yarn add redis-memory-server --dev
# OR
npm install redis-memory-server --save-dev

On install, this package auto-downloads and compiles version stable of the redis-server binary to node_modules/.cache/redis-binaries.

Requirements

  • NodeJS: 10.15+
  • Typescript: 3.8+ (if used)
  • make

Windows:

Although Windows is not officially supported by Redis, but there is a downloadable version of redis: 3.0.503 (June 28, 2016) for win64 by microsoft. This is an older version. It will work for most of the simple tasks like basic storage and pubsub. Probably what is missing or old is lua scripting.

Please note it will download the redis binary from github from URL: https://raw.githubusercontent.com/ServiceStack/redis-windows/master/downloads/redis-latest.zip.

Optionally, you could provide your own URL before running npm install: npx cross-env REDISMS_DOWNLOAD_URL='https://raw.githubusercontent.com/ServiceStack/redis-windows/master/downloads/redis-latest.zip' npm install

Configuring which redis-server binary to use

The default behavior is that version stable will be downloaded. You can set configurations via environment variables or via package.json.

Usage

Simple server start

import { RedisMemoryServer } from 'redis-memory-server';

const redisServer = new RedisMemoryServer();

const host = await redisServer.getHost();
const port = await redisServer.getPort();

// `redis-server` has been started
// you may use `host` and `port` as connection parameters for `ioredis` (or similar)

// you may check instance status
redisServer.getInstanceInfo(); // returns an object with instance data

// you may stop `redis-server` manually
await redisServer.stop();

// when `redis-server` is killed, its running status should be `false`
redisServer.getInstanceInfo();

// even if you forget to stop `redis-server`,
// when your script exits, a special process killer will shut it down for you

Start server via npx

npx redis-memory-server
# OR
REDISMS_PORT=6379 npx redis-memory-server

Available options for RedisMemoryServer

All settings are optional.

const redisServer = new RedisMemoryServer({
  instance: {
    port: number, // by default, choose any free port
    ip: string, // by default, '127.0.0.1'; for binding to all IP addresses set it to `::,0.0.0.0`,
    args: [], // by default, no additional arguments; any additional command line arguments for `redis-server`
  },
  binary: {
    version: string, // by default, 'stable'
    downloadDir: string, // by default, 'node_modules/.cache/redis-memory-server/redis-binaries'
    systemBinary: string, // by default, undefined
  },
  autoStart: boolean, // by default, true
});

Options which can be set via environment variables

REDISMS_DOWNLOAD_DIR=/path/to/redis/binaries # default target download directory
REDISMS_VERSION=6.0.10 # default version to download
REDISMS_DEBUG=1 # debug mode, also available case-insensitive values: "on" "yes" "true"
REDISMS_DOWNLOAD_MIRROR=host # your mirror host to download the redis binary
REDISMS_DOWNLOAD_URL=url # full URL to download the redis binary
REDISMS_DISABLE_POSTINSTALL=1 # if you want to skip download binaries on install
REDISMS_SYSTEM_BINARY=/usr/local/bin/redis-server # if you want to use an existing binary already on your system.

Options which can be set via package.json

You can also use package.json to configure the installation process. It will search up the hierarchy looking for package.json files and combine all configurations, where closer package.json files take precedence. Environment variables have higher priority than contents of package.json files.

{
  "redisMemoryServer": {
    "downloadDir": "/path/to/redis/binaries",
    "version": "6.0.10",
    "debug": "1",
    "downloadMirror": "url",
    "disablePostinstall": "1",
    "systemBinary": "/usr/local/bin/redis-server"
  }
}

By default, it starts looking for package.json files at process.cwd(). To change this:

import { findPackageJson } from 'redis-memory-server/lib/util/resolve-config';

findPackageJson('/custom/path');

Simple test with ioredis

Take a look at this test file.

Debug mode

Debug mode can be enabled with an environment variable or in package.json:

REDISMS_DEBUG=1 # also available case-insensitive values: "on", "yes", "true"

or

{
  "redisMemoryServer": {
    "debug": "1"
  }
}

Credits

This package is inspired heavily by mongodb-memory-server.

License

MIT