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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@monksoftware/monredis

v2.3.0

Published

IORedis wrapper with improved cluster support and sensible defaults

Downloads

6

Readme

Monredis

Monredis is a thin wrapper around ioredis providing improved cluster support and sensible defaults for both single-node and cluster redis instances.

Usage

The module exports a factory function, use it to get a ioredis redis client

const Redis = require('monredis')

// Single node redis instance
const redisClient = Redis('redis://:authpwd@host:port')

// Redis cluster with keys prefix
const redisClusterClient = Redis(
  'redis://:authpwd@host:port',
  true,
  {keyPrefix: 'myprefix'}
)

See simple.js file inside example folder for a more complete example.

Documentation

The factory functions takes 4 arguments:

  • host: string or array, required. The redis url to connect to. Can be an array of multiple urls if connecting to a cluster, so that if some nodes are down it will connect to the next one in the array for the initial connection. NOTE: You don't have to pass all the cluster nodes here when connecting to a cluster! ioredis will automatically find and connect to all nodes as soon as it connects to one; the nodes here are only the candidates for the initial connection. One or two are enough unless you have a very unstable cluster.
  • cluster: boolean, default false - pass true to connect to redis cluster
  • nodeOptions: object, optional - ioredis redis options
  • clusterOptions: object, optional - ioredis cluster options, minus the redisOptions key, which we take from the previous nodeOptions parameter.

You can check the default values for nodeOptions and clusterOptions in the main source file and in the ioredis'documentation. The values you provide will overwrite the defaults, so you can change a single key or override everything.

Keys prefix

One particularly useful param in nodeOptions is the keyPrefix one: if supplied, all keys in the commands executed by the client will be automatically and transparently prefixed with the value. For example:

const Monredis = require('monredis')
const redis = Monredis('redis://localhost:6379', false, {keyPrefix: 'dev:'})

// Will actually create and read 'dev:mymapkey'
redisClient.set('mykey', 'value')
redisClient.get('mykey')

This is great for namespacing of keys in shared redis instances, or you can also use this feature to force all your keys to end up in a single redis cluster node by providing a prefix between {} brackets.