Skip to content

wangdahoo/redis-sharding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redis-sharding

simple redis sharding based on Redis and HashRing

How to Use

$ npm i redis-sharding
  • client
const Sharding = require('redis-sharding')

const sharding = new Sharding({
  '127.0.0.1:7000': { vnodes: 50 },
  '127.0.0.1:7001': { vnodes: 50 },
  '127.0.0.1:7002': { vnodes: 50 },
  '127.0.0.1:7003': { vnodes: 50 }
})

const client = sharding.getClient()
client
  .set('foo', 'bar')
  .then(server => console.log(server)) // => 127.0.0.1:7001
  .then(() => client.get('foo'))
  .then(value => console.log(value)) // => bar
  • multi
const Sharding = require('redis-sharding')

const sharding = new Sharding({
  '127.0.0.1:7000': { vnodes: 50 },
  '127.0.0.1:7001': { vnodes: 50 },
  '127.0.0.1:7002': { vnodes: 50 },
  '127.0.0.1:7003': { vnodes: 50 }
})

const multi = sharding.getMulti()
await multi.set('a', 'foo')
await multi.set('b', 'bar')
await multi.get('a')
await multi.get('b')
const replies = await multi.execAsync()
console.log(replies) // => [127.0.0.1:7002, 127.0.0.1:7000, 'foo', 'bar']

About

redis sharding via HashRing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published