You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
chore: use es6 for multi
This commit is contained in:
@@ -17,19 +17,10 @@ const RedisClient = require('../').RedisClient
|
||||
|
||||
TODO: Implement individual command generation as soon as possible to prevent divergent code
|
||||
on single and multi calls!
|
||||
|
||||
TODO: Implement hooks to replace this. Most of these things are perfect for hooks
|
||||
********************************************************************************************/
|
||||
|
||||
RedisClient.prototype.multi = function multi (args) {
|
||||
const multi = new Multi(this, args)
|
||||
multi.exec = multi.EXEC = multi.execTransaction
|
||||
return multi
|
||||
}
|
||||
|
||||
// ATTENTION: This is not a native function but is still handled as a individual command as it behaves just the same as multi
|
||||
RedisClient.prototype.batch = function batch (args) {
|
||||
return new Multi(this, args)
|
||||
}
|
||||
|
||||
function selectCallback (self, db) {
|
||||
return function (err, res) {
|
||||
if (err === null) {
|
||||
@@ -45,7 +36,7 @@ RedisClient.prototype.select = function select (db) {
|
||||
}
|
||||
|
||||
Multi.prototype.select = function select (db) {
|
||||
this.queue.push(new Command('select', [db], null, selectCallback(this._client, db)))
|
||||
this._queue.push(new Command('select', [db], null, selectCallback(this._client, db)))
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -66,7 +57,7 @@ Multi.prototype.monitor = function monitor () {
|
||||
const callOnWrite = () => {
|
||||
this._client.monitoring = true
|
||||
}
|
||||
this.queue.push(new Command('monitor', [], callOnWrite))
|
||||
this._queue.push(new Command('monitor', [], callOnWrite))
|
||||
return this
|
||||
}
|
||||
// Set multi monitoring to indicate the exec that it should abort
|
||||
@@ -111,7 +102,7 @@ Multi.prototype.quit = function quit () {
|
||||
this._client.closing = true
|
||||
this._client.ready = false
|
||||
}
|
||||
this.queue.push(new Command('quit', [], null, quitCallback(this._client), callOnWrite))
|
||||
this._queue.push(new Command('quit', [], null, quitCallback(this._client), callOnWrite))
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -161,7 +152,7 @@ RedisClient.prototype.info = function info (section) {
|
||||
|
||||
Multi.prototype.info = function info (section) {
|
||||
const args = section ? [section] : []
|
||||
this.queue.push(new Command('info', args, null, infoCallback(this._client)))
|
||||
this._queue.push(new Command('info', args, null, infoCallback(this._client)))
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -196,7 +187,7 @@ Multi.prototype.auth = function auth (pass) {
|
||||
|
||||
// Stash auth for connect and reconnect.
|
||||
this.authPass = pass
|
||||
this.queue.push(new Command('auth', [pass], null, authCallback(this._client)))
|
||||
this._queue.push(new Command('auth', [pass], null, authCallback(this._client)))
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -237,7 +228,7 @@ Multi.prototype.client = function client () {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.queue.push(new Command('client', arr, callOnWrite))
|
||||
this._queue.push(new Command('client', arr, callOnWrite))
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -262,7 +253,7 @@ Multi.prototype.subscribe = function subscribe () {
|
||||
const callOnWrite = () => {
|
||||
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
|
||||
}
|
||||
this.queue.push(new Command('subscribe', arr, callOnWrite))
|
||||
this._queue.push(new Command('subscribe', arr, callOnWrite))
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -289,7 +280,7 @@ Multi.prototype.unsubscribe = function unsubscribe () {
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
|
||||
}
|
||||
this.queue.push(new Command('unsubscribe', arr, callOnWrite))
|
||||
this._queue.push(new Command('unsubscribe', arr, callOnWrite))
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -314,7 +305,7 @@ Multi.prototype.psubscribe = function psubscribe () {
|
||||
const callOnWrite = () => {
|
||||
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
|
||||
}
|
||||
this.queue.push(new Command('psubscribe', arr, callOnWrite))
|
||||
this._queue.push(new Command('psubscribe', arr, callOnWrite))
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -341,6 +332,6 @@ Multi.prototype.punsubscribe = function punsubscribe () {
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||
this._client.pubSubMode = this._client.pubSubMode || this._client.commandQueue.length + 1
|
||||
}
|
||||
this.queue.push(new Command('punsubscribe', arr, callOnWrite))
|
||||
this._queue.push(new Command('punsubscribe', arr, callOnWrite))
|
||||
return this
|
||||
}
|
||||
|
Reference in New Issue
Block a user