Giter VIP home page Giter VIP logo

node-redis-server's Introduction

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.

node-redis-server's People

Contributors

brandonzacharie avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.