Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

redis-server

BrandonZacharie39kMIT1.2.2TypeScript support: definitely-typed

Start and stop a Redis server.

Redis, server, manager

readme

redis-server

NPM version Build Status Coverage Status License

Start and stop a local Redis server in Node.js like a boss.

Installation


npm install redis-server

Usage

The constructor exported by this module optionally accepts a single argument; a number or string that is a port or an object for configuration.

Basic Example


const RedisServer = require('redis-server');

// Simply pass the port that you want a Redis server to listen on.
const server = new RedisServer(6379);

server.open((err) => {
  if (err === null) {
    // You may now connect a client to the Redis
    // server bound to port 6379.
  }
});

Configuration

Property Type Default Description
bin String redis-server A Redis server binary path.
conf String | A Redis server configuration file path.
port Number 6379 A port to bind a Redis server to.
slaveof String | An address of a Redis server to sync with.

A Redis server binary must be available. If you do not have one in $PATH, provide a path in configuration.


const server = new RedisServer({
  port: 6379,
  bin: '/opt/local/bin/redis-server'
});

You may use a Redis configuration file instead of configuration object properties that are flags (i.e. port and slaveof). If conf is provided, no flags will be passed to the binary.


const server = new RedisServer({
  conf: '/path/to/redis.conf'
});

Methods

For methods that accept callback, callback will receive an Error as the first argument if a problem is detected; null, if not.

RedisServer#open()

Attempt to open a Redis server. Returns a Promise.

Promise style open()

server.open().then(() => {
  // You may now connect a client to the Redis server bound to `server.port`.
});
Callback style open()

server.open((err) => {
  if (err === null) {
    // You may now connect a client to the Redis server bound to `server.port`.
  }
});

RedisServer#close()

Close the associated Redis server. Returns a Promise. NOTE: Disconnect clients prior to calling this method to avoid receiving connection errors from clients.

Promise style close()

server.close().then(() => {
  // The associated Redis server is now closed.
});
Callback style close()

server.close((err) => {
  // The associated Redis server is now closed.
});

Properties

RedisServer#isOpening

Determine if the instance is starting a Redis server; true while a process is spawning, and/or about to be spawned, until the contained Redis server either starts or errs.

RedisServer#isRunning

Determine if the instance is running a Redis server; true once a process has spawned and the contained Redis server is ready to service requests.

RedisServer#isClosing

Determine if the instance is closing a Redis server; true while a process is being, or about to be, killed until the contained Redis server either closes or errs.

Events

stdout

Emitted when a Redis server prints to stdout.

opening

Emitted when attempting to start a Redis server.

open

Emitted when a Redis server becomes ready to service requests.

closing

Emitted when attempting to stop a Redis server.

close

Emitted once a Redis server has stopped.

changelog

redis-server

This project adheres to Semantic Versioning. Notable changes to this project will be documented in this file for which the format is based on Keep a Changelog.


Unreleased

1.2.2 — 2018-06-12

  • #open() returning a rejected promise due to a "Server can't set maximum open files" error

1.2.1 — 2018-06-07

Changed

  • Update dev dependencies
    • coveralls 3.0.1
    • eslint 4.19.1
    • mocha 5.2.0
    • nyc 12.0.2
    • remark-lint 6.0.2
    • remark-preset-lint-recommended 3.0.2

Deprecated

  • Support for Node.js versions not designated as LTS

Fixed

  • npm audit found 15 vulnerabilities (4 low, 9 moderate, 2 high)
  • #open() returning a rejected promise due to a "Server can't set maximum open files" error

1.2.0 — 2018-02-07

Added

  • Change log entries for releases prior to 1.0.0
  • Add support for Redis 4.0

Changed

  • Change log format based on http://keepachangelog.com/en/0.3.0/
  • Update dependencies
    • promise-queue 2.2.5
  • Update dev dependencies
    • chai 4.1.2
    • coveralls 3.0.0
    • eslint 4.17.0
    • mocha 5.0.0
    • remark-cli 5.0.0
    • remark-preset-lint-recommended 3.0.1
  • Change test framework from istanbul to nyc
  • Update test matrix; remove Node.js v5 and v7; add Node.js v9

Fixed

  • UnhandledPromiseRejectionWarning errors appear when some tests fail
  • #open() returning an unresolved promise due to "Can't chdir to '...': No such file or directory" errors

1.1.0 — 2017-01-07

Added

  • Change log
  • “opening” and “closing” events

Changed

  • Update dev dependencies
    • eslint 3.13.0

Fixed

  • #isClosing not set to true when a server is closing due to a start-up error

1.0.0 — 2017-01-05

Added

  • Code coverage: 100% ✨

Changed

  • Lint JavaScript with eslint

Fixed

  • RedisServer~Config#bin not working with RedisServer~Config#conf
  • #open() and #close() race conditions
  • Callbacks not receiving arguments
  • UnhandledPromiseRejectionWarning when an error is thrown in a callback

0.4.0 — 2016-12-05

Added

  • Support for --slaveof (RedisServer~Config#slaveof)
  • Lint markdown with remark

0.3.0 — 2016-12-02

Added

  • #open() and #close() return a Promise

Changed

  • Accept port as a string or number

Fixed

  • Process EventEmitter memory leak
  • Errors when calling #open() or #close() repetitiously

0.2.0 — 2016-11-26

Added

  • MIT License
  • Code coverage report
  • Support for a Redis server binary path (RedisServer~Config#bin)
  • Support for a Redis configuration file path (RedisServer~Config#conf)
  • Lint JavaScript with jshint
  • “open”, “close”, and “stdout” events

0.1.0 — 2016-11-26

Added

  • CI build testing and status report

Changed

  • Refactor ES5 to ES6

Deprecated

  • Support for Node.js versions below 4.0.0

0.0.3 — 2016-04-30

Added

  • Use port number 6379 when the constructor argument configOrPort is undefined

0.0.2 — 2016-04-25

Added

  • Support for Node.js >= 0.10.0

0.0.1 — 2014-05-06

Added

  • Initial release