# zrplatform-redis-sharding-plugin

> 基于hashring，并且参考redis-sharding，实现客户端分片Redis客户端，并且优化连接处理

Latest version **1.0.4** (published 2020-01-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install zrplatform-redis-sharding-plugin
pnpm add zrplatform-redis-sharding-plugin
yarn add zrplatform-redis-sharding-plugin
bun add zrplatform-redis-sharding-plugin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-01-08 |
| First published | 2019-11-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | zhaoxiang |
| Maintainers | xiang.zhao |
| Keywords | node, redis, sharding, hashring |

## Links

- npm: https://www.npmjs.com/package/zrplatform-redis-sharding-plugin
- Repository: https://github.com/zxtyjx/zrplatform-redis-sharding-plugin
- Issues: https://github.com/zxtyjx/zrplatform-redis-sharding-plugin/issues
- npm.io page: https://npm.io/package/zrplatform-redis-sharding-plugin

## Dependencies (3)

- [redis](https://npm.io/package/redis.md) ^2.8.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.7.1
- [hashring](https://npm.io/package/hashring.md) ^3.2.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2020-01-08
- 1.0.3 — 2019-12-27
- 1.0.2 — 2019-11-07
- 1.0.1 — 2019-11-07

## README

# ZRPlatform-Redis-Sharding-Plugin
为zrplatform提供redis客户端分片插件


### 使用示例:

**1、引用**:

```ts
import RedisSharding from 'zrplatform-redis-sharding-plugin';
const sharding = new Sharding(
  [
    { host: '127.0.0.1', port: '16379' ,password: '******'},
    { host: '127.0.0.1', port: '16380' ,password: '******'},
  ]
)

const client = sharding.getProxy();

````

**2、使用**:

```ts
  await client.set('a1', 'foo1')
  await client.set('b1', 'foo2')
  await client.set('c1', 'foo3')
  await client.set('d1', 'foo4')

  await client.get('a1')
  await client.get('b1')
  await client.get('c1')
  await client.get('d1')
```

**3、事务使用**:
  >由于Redis事务不支持回滚,只支持放弃当前事务命令，所以客户端分片插件虽然提供了事务功能，但是不建议在较重场景下使用，仅作为参考。

```ts
  await client.multi()
  await client.set('a', 'foo1')
  await client.set('b', 'foo2')
  await client.set('c', 'foo3')
  await client.set('d', 'foo4')

  await client.get('a')
  await client.get('b')
  await client.get('c')
  await client.get('d')

  const replies2 = await client.execAsync()
  console.log('replies2', replies2);
```

**3、关闭所有客户端连接**:

```ts
  client.destroyAllClients();
```

---
_Source: https://npm.io/package/zrplatform-redis-sharding-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
