
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
redis-connection
Advanced tools
Re-use a single or pool of redis connections across several modules/files in your app.
A Global Redis Connection that can be used anywhere in your app and closed once at the end of tests.
At dwyl we use Redis everywhere because its fast!
If you're new to Redis, checkout our beginners tutorial: https://github.com/dwyl/learn-redis
Given that Redis can handle millions of operations per second, it is unlikely to be the bottleneck in your application/stack.
Where you can (unintentionally) create an issue is by having too many connections to your Redis Datastore. Don't laugh, we've seen this happen, where people open a new connection to Redis for each incoming http request (and forget to close them!) and thus quickly run out of available connections to Redis!
Most apps really only need one connection to Redis (per node.js instance) Or, if you are using Redis' Publish/Subscribe feature, you will need two connections per node.js server; one for a "standard" connection (the "Publisher"") and another as a "Subscriber".
Given that we modularise our apps and we don't want each file opening multiple connections to the Redis datastore (because Redis connections are a scarce resource - e.g: RedisCloud is 30 connections - and each connection needs to be closed for tape tests to exit...) we decided write a little script to instantiate a single connection to Redis which can be re-used across multiple files.
An easy way to re-use your single Redis connection (or pair of connections - when using Redis Publish/Subscribe) across multiple files/handlers in your application and close once at the end of your tests.
npm install redis-connection --save
var redisClient = require('redis-connection')(); // require & connect
redisClient.set('hello', 'world');
redisClient.get('hello', function (err, reply) {
console.log('hello', reply.toString()); // hello world
});
You can use the standard redisClient
for publishing but
will need to have a separate connection to subscribe on.
Create a Subscriber connection by supplying the word subscriber
when starting the redis-connection
:
var redisSub = require('redis-connection')('subscriber');
redisSub.subscribe("chat:messages:latest", "chat:people:new");
// see: https://github.com/dwyl/hapi-socketio-redis-chat-example ;-)
Closing your connections is easy.
var redisClient = require('redis-connection')(); // require & connect
redisClient.set('hello', 'world');
redisClient.get('hello', function (err, reply) {
console.log('hello', reply.toString()); // hello world
redisClient.end(true); // this will "flush" any outstanding requests to redis
});
If you have created multiple connections in your app
(you would do this to use Redis' Publish/Subscribe feature),
we have a simple method to "Close All" the connections
you have opened in a single command: killall()
e.g:
var redisClient = require('redis-connection')(); // require & connect
var redisSub = require('redis-connection')('subscriber');
// do things with redisClient and redisSub in your app...
// when you want to close both connections simply call:
require('redis-connection').killall();
redis-connection
with env2
If you are using env2 to load your configuration file, simply require env2
before requiring redis-connection
:
require('env2')('.env'); // load the redis URL
var redisClient = require('redis-connection')();
// now use your redis connection
If you need us to support a different Redis-as-a-service provider
or want to have more configuration options, please let us know!
If you want to help improve/update/extend this module,
please ask us for access to the environment variables
(.env
file) with REDISCLOUD_URL
so you can test your modifications locally.
If you are seeing a "Redis Connection Error" message in your terminal, e.g:
- - - - - - - - Redis Connection Error: - - - - - - - -
{ Error: 'Redis connection to 127.0.0.1:6380 failed',
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 4321 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Either your local instance of Redis is not running or is running on a different port from the standard which is 6379. Confirm Redis is running then try again!
FAQs
Re-use a single or pool of redis connections across several modules/files in your app.
The npm package redis-connection receives a total of 240 weekly downloads. As such, redis-connection popularity was classified as not popular.
We found that redis-connection demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.