Socket
Socket
Sign inDemoInstall

cluster-key-slot

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cluster-key-slot

Generates CRC hashes for strings - for use by node redis clients to determine key slots.


Version published
Weekly downloads
5.6M
increased by0.74%
Maintainers
1
Install size
11.9 kB
Created
Weekly downloads
 

Package description

What is cluster-key-slot?

The cluster-key-slot npm package is designed for calculating the hash slot for a given key in a Redis Cluster. This is crucial for applications that interact with Redis Clusters, as it allows them to determine which node in the cluster is responsible for a given key. By doing so, it enables efficient data access and manipulation within a distributed Redis environment.

What are cluster-key-slot's main functionalities?

Calculate hash slot for a key

This feature allows you to calculate the hash slot for a given key. The code sample demonstrates how to import the cluster-key-slot package, use it to calculate the hash slot for the key 'myKey', and then log the result. This is useful for determining which node in a Redis Cluster will handle the key.

"use strict";
const calculateSlot = require('cluster-key-slot');
const slot = calculateSlot('myKey');
console.log(slot);

Other packages similar to cluster-key-slot

Readme

Source

Coverage Status Downloads npm version dependencies License Follow on Twitter

Redis Key Slot Calculator

A high performance redis cluster key slot calculator for node redis clients e.g. node_redis, ioredis and redis-clustr.

This also handles key tags such as somekey{actualTag}.

Install

Install with NPM:

npm install cluster-key-slot --save

Usage

const calculateSlot = require('cluster-key-slot');
const calculateMultipleSlots = require('cluster-key-slot').generateMulti;

// ...

// a single slot number
const slot = calculateSlot('test:key:{butOnlyThis}redis');
// Buffer is also supported
const anotherSlot = calculateSlot(Buffer.from([0x7b, 0x7d, 0x2a]));

// multiple keys - multi returns a single key slot number, returns -1 if any
// of the keys does not match the base slot number (base is defaulted to first keys slot)
// This is useful to quickly determine a singe slot for multi keys operations.
const slotForRedisMulti = calculateMultipleSlots([
  'test:key:{butOnlyThis}redis',
  'something:key45:{butOnlyThis}hello',
  'example:key46:{butOnlyThis}foobar',
]);

Benchmarks

OLD in these benchmarks refers to the ioredis crc calc and many of the other calculators that use Buffer.

node -v                                                                                                                                                                                                ✔  16.38G RAM  10:29:07
v10.15.3

NEW tags x 721,445 ops/sec ±0.44% (90 runs sampled)
OLD tags x 566,777 ops/sec ±0.97% (96 runs sampled)
NEW without tags x 2,054,845 ops/sec ±1.77% (92 runs sampled)
OLD without tags x 865,839 ops/sec ±0.43% (96 runs sampled)
NEW without tags singular x 6,354,097 ops/sec ±1.25% (94 runs sampled)
OLD without tags singular x 4,012,250 ops/sec ±0.96% (94 runs sampled)
NEW tags (Buffer) x 552,346 ops/sec ±1.35% (92 runs sampled)

Keywords

FAQs

Last updated on 01 Nov 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc