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

warp-contracts-redis

v0.4.2

Published

Redis implementation for Warp Contracts

Downloads

29

Readme

License: MIT NPM Test Workflow

Warp Contracts Redis Cache

Warp Contracts SortKeyCache implementation using Redis.

Warp Contracts will open and close the client many times, and we have seen that this causes unexpected errors sometimes, mostly due to client being closed. Furthermore, we would like to have an "online" cache option rather than local caches too. That is why this package was developed.

RedisCache solves the open and close problem with a "managed" setting. Instead of providing a URL, you can provide the Redis client itself. The effects of doing that are as follows:

  • open function will be disabled, calling it will have no effect; it is user's responsibility to connect.
  • close function will be disabled, calling it will have no effect; it is user's responsibility to disconnect.
  • the user should make the necessary configurations for inMemory: true option; a static function is exposed for this purpose: setConfigForInMemory.
  • you can see if the client is managed or not via the isManaged field.

Some of the functionality is achieved via Lua scripts (v5.1), which you can find under src/lua for reference; the actual scripts are written in luaScripts.ts. The prefix and subLevelSeparator must be provided as argument to Lua scripts, because multiple RedisCache instances may be created with different prefixes or sub-level separators but they may connect to the same client; and for that reason we can't simply hardcode them in the script.

[!TIP]

To learn more about SortKeyCache, see the links below:

Installation

You can install the NPM package as shown below:

npm i warp-contracts-redis
yarn add warp-contracts-redis
pnpm add warp-contracts-redis

Usage

The RedisCache constructor takes two inputs, one is of type CacheOptions as is the case for all SortKeyCache implementations of Warp Contracts. The other is Redis-specific options.

import type { CacheOptions } from "warp-contracts";
import type { RedisOptions } from "warp-contracts-redis";

const cacheOptions = {
  // does not dump on close
  inMemory: true,

  // acts as a prefix for all keys
  dbLocation: "redis.location",

  // separates key from sortKey
  subLevelSeparator: "|",
} satisfies CacheOptions;

const redisOptions = {
  // redis connection url
  url: "redis://default:redispw@localhost:6379",

  // leave at least this many on pruning
  minEntriesPerContract: 10,

  // after this many entries, prune
  maxEntriesPerContract: 100,
} satisfies RedisOptions;

const redisCache = new RedisCache(cacheOptions, redisOptions);

For the managed version, simply create your ioredis client outside and pass it within redisOptions similar to the example above; do not pass in URL.

Test

Tests require a Redis server running at the specified URL within tests/constants. We use the default Redis URL for that, if you would like to run tests on a custom URL you must change the URL within the constants file.

pnpm test         # test everything
pnpm test <path>  # test a specific suite

Building

Build the package with:

pnpm build

Styling

Check styling with:

pnpm format
pnpm lint