Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
cluster-key-slot
Advanced tools
Generates CRC hashes for strings - for use by node redis clients to determine key slots.
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.
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);
ioredis is a robust, performance-focused, and full-featured Redis client for Node.js. It supports Redis Cluster out of the box, including automatic partitioning of commands across the cluster. While cluster-key-slot focuses solely on calculating hash slots, ioredis provides a comprehensive solution for interacting with Redis, including cluster support, which inherently deals with hash slots as part of its functionality.
redis-clustr is a Redis client for Node.js with support for clustering. It provides transparent command routing to the correct Redis node in a cluster, based on the key's hash slot. Unlike cluster-key-slot, which is a utility for calculating hash slots, redis-clustr is a full client that manages connections and commands within a Redis Cluster, including the calculation and handling of hash slots.
A high performance cluster key slot calculator for node redis clients e.g. node_redis and ioredis.
This also handles key tags such as somekey{actualTag}
.
Install with NPM:
npm install cluster-key-slot --save
const calculateSlot = require('cluster-key-slot');
const calculateMultipleSlots = require('cluster-key-slot').generateMulti;
// ...
// a single slot number
const slot = calculateSlot('test:key:{butOnlyThis}redis');
// 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',
]);
OLD
in these benchmarks refers to the ioredis
crc calc and many of the other calculators that use Buffer
.
NEW tags x 482,204 ops/sec ±1.07% (87 runs sampled)
OLD tags x 204,380 ops/sec ±1.51% (85 runs sampled)
NEW without tags x 1,250,274 ops/sec ±1.30% (87 runs sampled)
OLD without tags x 266,518 ops/sec ±1.29% (87 runs sampled)
NEW without tags singular x 3,617,430 ops/sec ±1.03% (85 runs sampled)
OLD without tags singular x 1,223,707 ops/sec ±1.15% (86 runs sampled)
FAQs
Generates CRC hashes for strings - for use by node redis clients to determine key slots.
The npm package cluster-key-slot receives a total of 4,117,543 weekly downloads. As such, cluster-key-slot popularity was classified as popular.
We found that cluster-key-slot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.