Serverless Offline Redis Server
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
-
Redis server failed to start: Error: spawn redis-server ENOENT
cause The native Redis server executable is not installed on the system or is not in the system's PATH.fixInstall Redis server for your operating system (e.g., `brew install redis` on macOS, `apt-get install redis-server` on Debian/Ubuntu, or download from redis.io). -
Error: Port 6379 already in use.
cause Another process is already using the specified Redis port (default 6379).fixChange the `port` in your `custom.redis` configuration in `serverless.yml` to an available port, or stop the process currently using the port.
Warnings
- gotcha This plugin requires a native Redis server executable to be installed on the host machine. It does not bundle or automatically install Redis itself. Failure to install Redis will result in runtime errors when `serverless offline` attempts to start the Redis server.
- breaking The plugin is currently at version 0.0.2, indicating an early development stage. APIs and configuration options may be subject to frequent changes without strict adherence to SemVer between minor versions.
- gotcha This plugin is strictly for local development with `serverless-offline`. It is not intended for deployment to production environments or for managing Redis instances in the cloud. Using it outside of `serverless offline start` will have no effect.
Install
-
npm install serverless-offline-redis-server -
yarn add serverless-offline-redis-server -
pnpm add serverless-offline-redis-server
Imports
- Plugin integration
import { ServerlessOfflineRedisServer } from 'serverless-offline-redis-server'plugins: - serverless-offline-redis-server - Configuration
plugins: serverless-offline-redis-server: port: 8888custom: redis: port: 8888 # ... other redis-server options
Quickstart
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