Registry / database / redis-ssh2

redis-ssh2

JSON →
library1.0.3jsnpmunverified

redis-ssh2 is a Node.js package (v1.0.3) that enables executing Redis commands over an SSH tunnel using ioredis and ssh2. It creates a local SSH tunnel to a remote server and then connects to Redis through that tunnel, bypassing restrictions on localhost-only connections. The package wraps ioredis for Redis operations and ssh2 for SSH connections. It is particularly useful when Redis is only accessible from a webserver and not directly from the client. The API consists of a single connect() function that accepts SSH and Redis configurations and returns a promise that resolves to an ioredis client. Users must close the tunnel with Redis.close() when done.

npm install redis-ssh2
INSTALL
IMPORT
SIG · REDIS-SSH2
R
redis-ssh2
databasejavascriptv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (connect)
import Redis from 'redis-ssh2'
const { connect } = require('redis-ssh2')
Use default import for the connect function. CommonJS require returns the same object.
connect
const Redis = require('redis-ssh2')
const { Redis } = require('redis-ssh2')
CommonJS require returns the default export (the connect function). Named destructuring is incorrect.
close
Redis.close()
client.close()
close is a static method on the Redis object, not on the client instance.

Connects to a remote Redis server through an SSH tunnel using a private key, sets a key, and closes the tunnel.

const Redis = require('redis-ssh2'); const fs = require('fs'); Redis.connect( { host: 'ssh-server.example.com', user: 'ssh-user', privateKey: fs.readFileSync(process.env.HOME + '/.ssh/id_rsa') }, { host: 'redis.internal.example.com', port: 6379, password: process.env.REDIS_PASSWORD ?? '', db: 0 } ).then(client => { client.set('key', 'value', (err, reply) => { if (err) throw err; console.log(reply); Redis.close(); }); }).catch(err => { console.error(err); });
Debug
Known issues
gotchaRedis.close() must be called on the Redis object, not on the client instance.
fix
Always call Redis.close() after finishing Redis operations.
affects: >=0.0.0
gotchaThe close method is static; do not attempt to close the tunnel via client.quit() or client.disconnect().
fix
Use Redis.close() to properly close the SSH tunnel.
affects: >=0.0.0
deprecatedThe package uses ioredis internally; be aware that ioredis v5 has breaking changes if you pass raw commands.
fix
Refer to ioredis documentation for breaking changes between versions.
affects: >=1.0.0
gotchaSSH config must contain either 'privateKey' or 'password'. Missing both will cause connection failure.
fix
Provide at least one authentication method in the SSH config object.
affects: >=0.0.0
gotchaThe package does not support SSH agent forwarding by default; you must provide a private key or password.
fix
Pass 'agent' option in sshConfig if agent forwarding is needed.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Redis.connect is not a function
Incorrect import or require of the package.
fix
Use 'const Redis = require('redis-ssh2')' (default) or 'import Redis from 'redis-ssh2''.
Error: All configured authentication methods failed
SSH authentication failed (invalid key, password, or host).
fix
Verify sshConfig has correct host, user, and either privateKey or password.
Redis.close is not a function
Calling close on the client object instead of the Redis module.
fix
Call Redis.close() (static method) not client.close().
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
ssh2requiredCreates the SSH tunnel required to reach the remote Redis server.
ioredisrequiredProvides the Redis client that communicates over the tunnel.
Agent activity
14 hits · last 30 days
node
12
Meta
1
Resources
redis-ssh2 — npm install redis-ssh2 · libregistry