Serverless Offline Redis Server

0.0.2 · active · verified Sun Apr 19

serverless-offline-redis-server is a Serverless Framework plugin designed to launch a local Redis server specifically for local development workflows using `serverless-offline`. The package, currently at version 0.0.2, integrates with the `serverless offline start` command to automatically manage a Redis instance alongside your serverless functions. Its primary differentiation lies in simplifying the setup of a local Redis instance within the Serverless Offline ecosystem, eliminating the need for manual Redis server management during development. It acts as a wrapper for the `redis-server` npm package, allowing users to configure Redis properties like port directly in their `serverless.yml`. The release cadence appears to be infrequent given its early version.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install the plugin, configure it in `serverless.yml` to launch a local Redis server, and connect to it from a Serverless function during local development.

npm install --save-dev serverless-offline-redis-server

# Ensure Redis server is installed locally via your OS package manager (e.g., 'brew install redis' on macOS).

# serverless.yml
service: my-redis-service

plugins:
  - serverless-offline
  - serverless-offline-redis-server

custom:
  redis:
    port: 6379 # Default Redis port
    bind: 127.0.0.1 # Bind to localhost
    # Additional redis-server options can be added here

provider:
  name: aws
  runtime: nodejs18.x

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: get

# handler.js (example usage)
const Redis = require('ioredis');
const redis = new Redis({ port: 6379, host: '127.0.0.1' });

module.exports.hello = async (event) => {
  await redis.set('mykey', 'myvalue');
  const value = await redis.get('mykey');
  return {
    statusCode: 200,
    body: JSON.stringify({ message: `Redis value: ${value}` }),
  };
};

# To run:
npx serverless offline start

view raw JSON →