thunk-redis
The fastest thunk/promise-based redis client, support all redis features.
thunks
Implementations:
- thunk-ratelimiter The fastest abstract rate limiter.
- timed-queue Distributed timed job queue, backed by Redis.
examples)
Demo(https://raw.githubusercontent.com/antirez/redis/4.0/redis.conf
Sugest set config cluster-require-full-coverage
to no
in redis cluster!
default thunk API:
const redis = const thunk = const client = redis client client { console return this} { console // current database size: 0 return this} { console // select database 0: OK return thunkall this this this this } { console // transactions: [ 'OK', 'QUEUED', 'QUEUED', [ 'OK', 'redis' ] ] return this} { console // redis client quit: OK}
use promise API:
const redis = const Promise = const client = redis client client
support generator in thunk API:
const redis = const client = redis client { console this this console console var user = id: 'u001' name: 'jay' age: 24 // transaction, it is different from node_redis! this this this this this return this} { console}
Benchmark
Details: https://github.com/thunks/thunk-redis/issues/12
Installation
Node.js:
npm install thunk-redis
More)
API (- redis.createClient([addressArray], [options])
- redis.createClient([port], [host], [options])
- redis.createClient([address], [options])
- redis.calcSlot(str)
- redis.log([...])
redis.log
Helper tool, print result or error stack.
const client = redisclientredislog
redis.createClient
const client1 = redisconst client2 = redisconst client3 = redisconst client4 = redisconst client5 = redis// connect to 2 nodesconst client6 = redisconst client7 = redis // IPv4const client8 = redis // IPv6
redis cluster:
// assume cluster: '127.0.0.1:7000', '127.0.0.1:7001', '127.0.0.1:7002', ...const client1 = redis // will auto find cluster nodes!const client2 = redis const client3 = redis const client4 = redis// All of above will work, it will find redis nodes by self. // Create a client in cluster servers without cluster mode:const clientX = redis
-
options.onlyMaster
: Optional, Type:Boolean
, Default:true
.In replication mode, thunk-redis will try to connect master node and close slave node.
-
options.authPass
: Optional, Type:String
, Default:''
. -
options.database
: Optional, Type:Number
, Default:0
. -
options.returnBuffers
: Optional, Type:Boolean
, Default:false
. -
options.usePromise
: Optional, Type:Boolean
, Default:false
.Export promise commands API.
Use default Promise:
var redis =var client = redis -
options.noDelay
: Optional, Type:Boolean
, Default:true
.Disables the Nagle algorithm. By default TCP connections use the Nagle algorithm, they buffer data before sending it off. Setting true for noDelay will immediately fire off data each time socket.write() is called.
-
options.retryMaxDelay
: Optional, Type:Number
, Default:5 * 60 * 1000
.By default every time the client tries to connect and fails time before reconnection (delay) almost multiply by
1.2
. This delay normally grows infinitely, but settingretryMaxDelay
limits delay to maximum value, provided in milliseconds. -
options.maxAttempts
: Optional, Type:Number
, Default:20
.By default client will try reconnecting until connected. Setting
maxAttempts
limits total amount of reconnects. -
options.pingInterval
: Optional, Type:Number
, Default:0
.How many ms before sending a ping packet. There is no ping packet by default(
0
to disable). If redis server enabletimeout
config, this option will be useful. -
options.IPMap
: Optional, Type:Object
, Default:{}
.This option use o resolve redis internal IP and external IP problem https://github.com/thunks/thunk-redis/issues/19. Define it like:
{internalIP: externalIP}
, for example:const cli = redis