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

@janiscommerce/redis

v2.4.0

Published

A Driver to use Redis

Downloads

174

Readme

redis

Build Status Coverage Status npm version

Installation

npm install @janiscommerce/redis

Breaking changes Since 2.0.0 :warning:

  • Config host is required to connect. Connection will be ignored if not received.
  • The package now works as a wrapper of redis package for using Redis commands
  • Removed Api method set(), get(), del(), use redis commands instead
  • Now async method connect() must be executed before using any other command.

Configuration

Client configuration

Env Vars

If the env vars REDIS_WRITE_URL is set, will create a Redis connection

Config object parameter

Since 2.3.0

The connect() allows to receive an object with the url.

Settings

:warning: Deprecated :warning:

This package uses @janiscommerce/settings.

In .janiscommercerc.json file requires to have the configuration under the redis.

  • The field host is required.

See an example below

{
    "redis": {
        "host": "redis.example.host"
    }
}

Cluster Mode

The env var REDIS_CLUSTER_MODE must be set with a truthy value.

Env Vars

If the env vars REDIS_WRITE_URL and REDIS_READ_URL will be used for creating a Redis cluster connection.

Config object parameter

Since 2.3.0

The connect() allows to receive an object with the url as String or String Array.

API

connect(config = {})

async | Connects the Redis server using settings.

:new: Parameters

  • config the optional configuration.
    • config.url optional url as String for connecting the client of cluster. Since 2.3.0
    • config.url optional url as String Array for connecting. Exclusive for in cluster mode. Since 2.3.0
    • :new: config.maxRetries optional Number indicates the max amount of connection retries. (Default: 3)
      • When the max retries are reached the Client stops retrying and throws an error
      • This won't close the cached connection, the cached connection will persist and won't retry to connect.
        • If you need to set a limit of retries but retry when your process is executed again, then try catch the error and use closeConnection
        • If you don't want it to retry connection until your process is restarted, then don't need to close the connection.
    • :new: config.connectTimeout optional Number indicates the connection timeout in miliseconds. (Default: 5000)

Return

  • client: The Redis client when host is present in settings.
  • undefined: When host is not present in settings.

Throw an Error if Redis Server fails.

closeConnection()

async | Closes the active connection.

Usage


const Redis = require('@janiscommerce/redis');

(async () => {

    const redisCluster = await Redis.connect();

    await redisCluster.set('product-123', 'blue-shirt');

    const value = await redisCluster.get('product-123');

    // expected value: blue-shirt

})();

// Usage with custom max retries
(async () => {

    try {

        const redisCluster = await Redis.connect({
            connectTimeout: 1000,
            maxRetries: 1
        });

    }catch(err) {
        console.log(err.message);
        await Redis.closeConnection();
    }
})();

Errors

The errors are informed with a RedisError. This object has a code that can be useful for a debugging or error handling. The codes are the following:

| Code | Description | |------|----------------------------------- | | 1 | Redis error | | 2 | Max connection retries reached |

:information_source: For more examples see redis