npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@vortus-solutions/redis-service

v1.1.0

Published

A robust Redis service client for Node.js applications

Readme

Redis Service Package with Lua Scripts

A Node.js package that provides a robust Redis service implementation with built-in Lua script support. This package helps manage Redis connections and execute predefined Lua scripts efficiently.

Features

  • Connection management for multiple Redis instances
  • Built-in Lua scripts for common operations
  • Auto-pipelining support
  • Promise-based API
  • Connection error handling
  • Customizable configuration

Installation

npm install @vortus-solutions/redis-service

Basic Usage

const RedisService = require('@vortus-solutions/redis-service');

// Create a single instance connection
await RedisService.createConnection('main', {
    host: '127.0.0.1',
    port: 6379,
    db: 0
}, []);

// Or create a cluster connection
await RedisService.createClusterConnection('cluster', {
    nodes: [
        { host: 'redis-node1.example.com', port: 6379 },
        { host: 'redis-node2.example.com', port: 6379 }
    ]
}, []);

// Get connection instance
const redis = RedisService.getConnection('main');

Available Lua Scripts

zaddLimit

Adds a member to a sorted set with a limit on the total number of members.

Parameters:

  • key: Sorted set key
  • score: Member score
  • member: Value to add
  • limit: Maximum number of members
  • offset: Number of members to remove from start

expireNX

Sets expiration on a key only if it doesn't have one.

Parameters:

  • key: Redis key
  • ttl: Time to live in seconds

setHIfHigher

Sets hash field value only if new value is higher than existing.

Parameters:

  • key: Hash key
  • field: Hash field
  • value: New value

setHIfLower

Sets hash field value only if new value is lower than existing.

Parameters:

  • key: Hash key
  • field: Hash field
  • value: New value

getPolylineChunks

Retrieves polyline chunks based on latitude and longitude bounds.

Parameters:

  • key: Base key for polyline data
  • latitude: Target latitude
  • longitude: Target longitude

API Reference

RedisService

Constructor

new RedisService()

Methods

  • createConnection(connectionName, options = {}, luaScriptNames = []): Creates a new Redis single-instance connection.
  • createClusterConnection(connectionName, options = {}, luaScriptNames = []): Creates a new Redis cluster connection.
  • getConnection(connectionName): Returns the existing connection by name.
  • closeAll(): Closes all active connections.

LuaScriptsService

Methods

  • register(name, script): Register a new Lua script.
  • get(name): Get a script by name.
  • getScripts(names): Get multiple scripts by their names.
  • getAvailableScripts(): List all available scripts.

Configuration Options

Default connection options can be customized when creating a connection. The service supports both single Redis instances and Redis clusters with separate methods. All additional options are forwarded directly to ioredis, supporting its full range of configuration options.

Single Instance Configuration

Use with createConnection() method:

const singleInstanceOptions = {
    enableAutoPipelining: false,
    showFriendlyErrorStack: true,
    enableOfflineQueue: true,
    host: '127.0.0.1',
    port: 6379,
    db: 0
};

// Create single instance connection
await RedisService.createConnection('main', singleInstanceOptions, []);

Cluster Configuration

Use with createClusterConnection() method:

const clusterOptions = {
    nodes: [
        { host: '127.0.0.1', port: 6379 },
        { host: '127.0.0.1', port: 6380 }
    ],
    scaleReads: 'slave',
    clusterRetryStrategy: (times) => Math.min(times * 100, 2000),
    maxRedirections: 16,
    enableAutoPipelining: true,
    showFriendlyErrorStack: true
};

// Create cluster connection
await RedisService.createClusterConnection('cluster', clusterOptions, []);

Common Options

  • enableAutoPipelining: Enable automatic pipelining for improved performance
  • showFriendlyErrorStack: Show detailed error stack traces
  • enableOfflineQueue: Enable offline queue for connection retries
  • keyPrefix: Prefix for all Redis keys
  • password: Redis authentication password
  • tls: Enable TLS encryption

Error Handling

The package includes built-in error handling for connection issues:

try {
    // For single instance
    await RedisService.createConnection('main', { host: 'localhost' });
    
    // Or for cluster
    await RedisService.createClusterConnection('cluster', { nodes: [...] });
} catch (error) {
    console.error('Redis connection error:', error);
}

Best Practices

  1. Always close connections when done:
    await RedisService.closeAll();
  2. Reuse connections instead of creating new ones.
  3. Handle connection errors appropriately.
  4. Use auto-pipelining for bulk operations.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.