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

@outofsync/memory-cache

v2.0.2

Published

A Promise-based, simple, Redis-like, in-memory cache written in pure Javascript

Downloads

498

Readme

memory-cache

NPM

Actual version published on npm Master build Total npm module downloads Codacy Badge Codacy Coverate Badge Dependencies badge

memory-cache is a simple, Redis-like, in-memory cache written in pure Javascript.

Memory Cache is designed to be a fully-functional stand-in replacement for mocking Redis and fail-over in production systems for when Redis is not available. This package is intentionally designed to mimic the behavior of the node redis module and can be used with nearly all commands supported by Redis.

Unlike some other Redis mocking library, thought has been put into achieving full Redis command coverage. Many other libraries only provide incomplete coverage by providing only the most commonly used commands. MemoryCache currently provides 224 of 267 (~85%) of the available Redis commands. With coverage for the remaining commands planned. All commands have been rigorously tested with over 500 unit test.

See below

Installation

npm install @outofsync/memory-cache

Usage

const MemoryCache = require('@outofsync/memory-cache');
const client = new MemoryCache({ bypassUnsupported: true });

client.createClient();
client.set("TestKey", 10);
client.get("TestKey");

API Reference

constructor(options)

Create a new MemoryCache client with the passed options. MemoryCache only supports one option bypassUnsupported which if set true causes any unsupported commands to fail silently instead of throwing an error.

const MemoryCache = require('@outofsync/memory-cache');
const client = new MemoryCache({ bypassUnsupported: true });

MemoryCache.createClient()

Connect to the memory cache and emits the connect and ready events.

MemoryCache.quit()

Disconnects from the memory cache and emits the end event.

MemoryCache.end()

Disconnects from the memory cache and emits the end event. Unlike the Redis client this is identical to calling quit.

Command simplification

Where possible, this module mimics the return data behavior of the Redis module. For example, the .hmset will accept a single object hash to set multiple fields. Similar .hmget will return an object hash.

Multiple parameters

Many Redis commands like set, mget, etc. accept multiple parameters. The memory cache library support passing all additional parameters.

For example:

  client.mget('key1', 'key2', 'key3', 'key4');

Additionally, if a command is multiple words, then the additional portion of the command may be passed as the first parameter.

For example:

  client.flushall('async');

Using Promises

Every Redis command can be called with *Async at the end. This will invoke the Promisified variant of the command and return a Promise.

For Example:

  client.getAsync('testkey')
  .then((res) => {
    // Do something useful
  })
  .catch((err) => {
    // Do something useful
  });

Redis Commands

MemoryCache support all but a select few Redis Commands and returns then data as close to identically as possible to the redis module. Any errors are thrown as exceptions which should be caught. The commands which are unavailable are as follows:

  • BGREWRITEAOF
  • BITFIELD
  • BITPOS
  • BLPOP
  • BRPOP
  • BRPOPLPUSH
  • CLIENT *
  • CLUSTER
  • COMMAND *
  • CONFIG *
  • DEBUG *
  • EVAL
  • EVALSHA
  • GEORADIUS
  • GEORADIUSBYMEMBER
  • HSCAN
  • MIGRATE
  • MONITOR
  • OBJECT
  • PFADD
  • PFCOUNT
  • PFMERGE
  • PSUBSCRIBE
  • PUBLISH
  • PUBSUB
  • PUNSUBSCRIBE
  • READONLY
  • READWRITE
  • REPLICAOF
  • SCAN
  • SCRIPT *
  • SHUTDOWN
  • SLAVEOF
  • SLOWLOG
  • SORT
  • SSCAN
  • SUBSCRIBE
  • SYNC
  • UNSUBSCRIBE
  • UNWATCH
  • WAIT
  • WATCH
  • ZINTERSTORE
  • ZSCAN
  • ZUNIONSTORE

If an unavailable command is issued, then the module throws a MemoryCacheError -- "MemoryCache does not support that operation". This thrown error can be bypassed by passing the option bypassUnsupported as true in the constructor. Or by directly setting your MemoryCache instance instance.options.bypassUnsupported = true

License

Copyright (c) 2018-2019 Jay Reardon Copyright (c) 2019-2021 Out of Sync Studios LLC -- Licensed under the MIT license.