1.0.2 • Published 2 years ago

@o1s/redis-testbench v1.0.2

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
2 years ago

Redis Test Bench

Provide means to spin up & connect to:

  • a redis instance,
  • a redis cluster, composed of 3 shards, with 1 replica each,
  • a set of monitors, that logs:
    • (almost all) redis commands,
    • expiring entries.

Note that the npm package only adds a simple function to create an IORedis client, for either standalone Redis instance or for the Redis Cluster.

Installation

To be able to connect to the redis instance or cluster: npm install @o1s/redis-testbench

You can use the exported function buildClient, which will return an IORedis client (for standalone Redis instance or for a Redis Cluster).

To boot the services, clone this repo and read the title Redis and Redis Cluster services below.

Connectivity

Connecting to Redis services

  • The single redis service is available:
    • outside docker-compose: as localhost:6379
    • inside docker-compose: as redis:6379
  • The redis-cluster services are available:
    • outside docker-compose: localhost:6380 to localhost:6385 (requires nat support if ioredis is used).
    • inside docker-compose: as redis-node-0:6379 to redis-node-5:6379.

API Provided

  • buildClient returns the required redis client (either for a single Redis instance or for the Redis Cluster).
  • buildOptionsFromEnv builds the required options from env vars.

Redis and Redis Cluster services

Docker and Docker Compose services should be started from a git clone of this repo, not from the npm installed.

To start all redis and redis cluster services:

. .setup.sh
docker-compose up --build

To start the redis instance alone:

docker-compose up --build redis redis-monitor redis-watch-expirations

To start only the redis cluster (6 nodes: 3 primaries + 1 replica each):

. .setup.sh
docker-compose up --build \
  redis-node-0 \
  redis-node-1 \
  redis-node-2 \
  redis-node-3 \
  redis-node-4 \
  redis-node-5 \
  redis-monitor-0 \
  redis-monitor-1 \
  redis-monitor-2 \
  redis-monitor-3 \
  redis-monitor-4 \
  redis-monitor-5 \
  redis-watch-expirations-0 \
  redis-watch-expirations-1 \
  redis-watch-expirations-2 \
  redis-watch-expirations-3 \
  redis-watch-expirations-4 \
  redis-watch-expirations-5
  • redis-node-*: these are the actual redis services
  • redis-monitor-*: these will list (almost all) redis commands
  • redis-watch-expirations-*: these will list entry expirations.

To do a clean start state:

. .setup.sh
docker-compose down;
docker-compose rm -f \
  redis-node-0 \
  redis-node-1 \
  redis-node-2 \
  redis-node-3 \
  redis-node-4 \
  redis-node-5;
docker-compose up --build;

The commands above can be run with:

bash -i start.sh