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

@gomomento-poc/node-ioredis-client

v0.17.0

Published

Momento wrapper for @ioredis

Downloads

8

Readme

project status project stability

Momento Node.js IORedis compatibility client

What and why?

This project provides a Momento-backed implementation of ioredis The goal is to provide a drop-in replacement for ioredis so that you can use the same code with either a Redis server or with the Momento Cache service!

Installation

The Momento Node.js IORedis compatibility client is available on npm.js. You can install it via:

npm install @gomomento-poc/node-ioredis-client

Usage

To switch your existing ioredis application to use Momento Cache, you only need to change the code where you construct your client object. Here is an example of constructing a Momento ioredis client:

// Import the Momento redis compatibility client.
import {MomentoRedisAdapter, CacheClient, CredentialProvider} from '@gomomento-poc/node-ioredis-client';

// Instantiate Momento Adapter
const redis = new MomentoRedisAdapter(
  new CacheClient({
    credentialProvider: CredentialProvider.fromEnvironmentVariable('MOMENTO_API_KEY'),
    defaultTtlSeconds: 3600,
  }),
  'cache'
);

// make redis calls!
await redis.set('my-key', 'my-value');
const value = await redis.get('my-key');
console.log(`redis.get('my-key') returned: ${value}`);

Alternately, if you'd like to be able to easily switch back and forth between Momento and Redis using environment variables, you can use the NewIORedisWrapper and NewIORedisClusterWrapper wrapper functions:

import {NewIORedisWrapper} from '@gomomento-poc/node-ioredis-client';

// set env vars to configure Momento; For more info, see Momento wrapper function configuration section.
process.env['MOMENTO_ENABLED'] = 'true';
process.env['MOMENTO_DEFAULT_TTL_SECONDS'] = '3600';
process.env['MOMENTO_CACHE_NAME'] = 'cache';

const redis = NewIORedisWrapper();

// Or initialize Momento as you would an ioredis cluster client
// const redis = NewIORedisClusterWrapper([], {});

// make redis calls!
await redis.set('my-key', 'my-value');
const value = await redis.get('my-key');
console.log(`redis.get('my-key') returned: ${value}`);

NOTE: The Momento ioredis implementation currently supports simple key/value pairs (GET, SET, DELETE) as well as hash values (HGET/HSET). We will continue to add support for additional Redis APIs in the future; for more information see the current Redis API support section later in this doc.

Compression

The Momento ioredis client provides built-in support for compression. If your data contains relatively large text-based data structures (e.g. large JSON objects), compression can significantly speed up your application and potentially reduce network costs. To enable compression, all you need to do is set the compression option to true when constructing your client:

// Import the Momento redis compatibility client.
import {MomentoRedisAdapter, CacheClient, CredentialProvider} from '@gomomento-poc/node-ioredis-client';

// Instantiate Momento Adapter
const redis = new MomentoRedisAdapter(
  new CacheClient({
    credentialProvider: CredentialProvider.fromEnvironmentVariable('MOMENTO_API_KEY'),
    defaultTtlSeconds: 3600,
  }),
  'cache',
  {
    useCompression: true,
  }
);

// make redis calls!
await redis.set('my-key', 'my-value');
const value = await redis.get('my-key');
console.log(`redis.get('my-key') returned: ${value}`);

After making this change to the configuration, all of your data will be compressed before storing it in the Momento cache, and will be automatically decompressed when retrieved.

Momento wrapper function configuration

In this package we provide wrapper functions that help you configure whether or not to use Momento and how client settings should look based off environment variables. This is to try and make for a simpler drop in experience where you might be running Momento or Redis based off the environment or Region. This applies for NewIORedisWrapper and NewIORedisClusterWrapper wrapper functions.

| EnvVar Name | Description | Default | |-----------------------------|------------------------------------------------------------|---------| | MOMENTO_ENABLED | Will allow you to toggle between using Momento and IORedis | false | | MOMENTO_API_KEY | The Momento Auth token you would like to use | "" | | MOMENTO_CACHE_NAME | The name of the Momento Cache to use if Momento is enabled | "" | | MOMENTO_DEFAULT_TTL_SECONDS | The number of seconds to cache items for by default | 86400 |

Current Redis API support

This library supports the most popular Redis APIs, but does not yet support all Redis APIs. We currently support the most common APIs related to string values (GET, SET, DELETE), as well as hash values (HGET/HSET). We will be adding support for additional APIs in the future. If there is a particular API that you need support for, please drop by our Discord or e-mail us at [email protected] and let us know!


For more info, visit our website at https://gomomento.com!