cluster-key-slot

2018-11-10 admin

cluster-key-slot是什么

什么是cluster-key-slot,Generates CRC hashes for strings - for use by node redis clients to determine key slots.

cluster-key-slot使用教程帮助文档

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');

// 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.

NEW tags x 472,156 ops/sec ±1.80% (90 runs sampled)
OLD tags x 413,725 ops/sec ±1.37% (93 runs sampled)
NEW without tags x 1,287,795 ops/sec ±2.06% (89 runs sampled)
OLD without tags x 633,340 ops/sec ±0.87% (93 runs sampled)
NEW without tags singular x 4,824,560 ops/sec ±1.71% (93 runs sampled)
OLD without tags singular x 2,981,057 ops/sec ±0.22% (96 runs sampled)

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-45079.html

文章标题:cluster-key-slot

回到顶部