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 - remove standard and use individual config
Standard is not as up to date and still uses a old eslint version. Instead, use the airbnb default with a couple of modifications. All required changes are included.
This commit is contained in:
@@ -4,10 +4,11 @@ const Command = require('./command')
|
||||
const debug = require('./debug')
|
||||
const Multi = require('./multi')
|
||||
const utils = require('./utils')
|
||||
|
||||
const noPasswordIsSet = /no password is set/
|
||||
const RedisClient = require('./client')
|
||||
|
||||
/********************************************************************************************
|
||||
/** ******************************************************************************************
|
||||
Replace built-in redis functions
|
||||
|
||||
The callback may be hooked as needed. The same does not apply to the rest of the function.
|
||||
@@ -20,9 +21,9 @@ const RedisClient = require('./client')
|
||||
on single and multi calls!
|
||||
|
||||
TODO: Implement hooks to replace this. Most of these things are perfect for hooks
|
||||
********************************************************************************************/
|
||||
******************************************************************************************* */
|
||||
|
||||
function selectCallback (client, db) {
|
||||
function selectCallback(client, db) {
|
||||
return function (err, res) {
|
||||
if (err === null) {
|
||||
// Store db in this.selectDb to restore it on reconnect
|
||||
@@ -32,28 +33,31 @@ function selectCallback (client, db) {
|
||||
}
|
||||
}
|
||||
|
||||
RedisClient.prototype.select = function select (db) {
|
||||
RedisClient.prototype.select = function select(db) {
|
||||
return this.internalSendCommand(new Command('select', [db], null, selectCallback(this, db)))
|
||||
}
|
||||
|
||||
Multi.prototype.select = function select (db) {
|
||||
Multi.prototype.select = function select(db) {
|
||||
this._queue.push(new Command('select', [db], null, selectCallback(this._client, db)))
|
||||
return this
|
||||
}
|
||||
|
||||
RedisClient.prototype.monitor = function monitor () {
|
||||
// Use a individual command, as this is a special case that does not has to be checked for any other command
|
||||
RedisClient.prototype.monitor = function monitor() {
|
||||
// Use a individual command, as this is a special case that does not has to be
|
||||
// checked for any other command
|
||||
const callOnWrite = () => {
|
||||
// Activating monitor mode has to happen before Redis returned the callback. The monitor result is returned first.
|
||||
// Therefore we expect the command to be properly processed. If this is not the case, it's not an issue either.
|
||||
// Activating monitor mode has to happen before Redis returned the callback.
|
||||
// The monitor result is returned first. Therefore we expect the command to
|
||||
// be properly processed. If this is not the case, it's not an issue either.
|
||||
this._monitoring = true
|
||||
}
|
||||
return this.internalSendCommand(new Command('monitor', [], callOnWrite))
|
||||
}
|
||||
|
||||
// Only works with batch, not in a transaction
|
||||
Multi.prototype.monitor = function monitor () {
|
||||
// Use a individual command, as this is a special case that does not has to be checked for any other command
|
||||
Multi.prototype.monitor = function monitor() {
|
||||
// Use a individual command, as this is a special case that does not has to be
|
||||
// checked for any other command
|
||||
if (this._type !== 'multi') {
|
||||
const callOnWrite = () => {
|
||||
this._client._monitoring = true
|
||||
@@ -67,10 +71,11 @@ Multi.prototype.monitor = function monitor () {
|
||||
return this
|
||||
}
|
||||
|
||||
function quitCallback (client) {
|
||||
function quitCallback(client) {
|
||||
return function (err, res) {
|
||||
if (client._stream.writable) {
|
||||
// If the socket is still alive, destroy it. This could happen if quit got a NR_CLOSED error code
|
||||
// If the socket is still alive, destroy it. This could happen if quit got
|
||||
// a NR_CLOSED error code
|
||||
client._stream.destroy()
|
||||
}
|
||||
if (err && err.code === 'NR_CLOSED') {
|
||||
@@ -85,10 +90,11 @@ function quitCallback (client) {
|
||||
}
|
||||
}
|
||||
|
||||
RedisClient.prototype.quit = function quit () {
|
||||
RedisClient.prototype.quit = function quit() {
|
||||
// TODO: Consider this for v.3
|
||||
// Allow the quit command to be fired as soon as possible to prevent it landing in the offline queue.
|
||||
// this.ready = this.offlineQueue.length === 0;
|
||||
//
|
||||
// Allow the quit command to be fired as soon as possible to prevent it
|
||||
// landing in the offline queue. this.ready = this.offlineQueue.length === 0;
|
||||
const backpressureIndicator = this.internalSendCommand(new Command('quit', [], null, quitCallback(this)))
|
||||
// Calling quit should always end the connection, no matter if there's a connection or not
|
||||
this._closing = true
|
||||
@@ -97,7 +103,7 @@ RedisClient.prototype.quit = function quit () {
|
||||
}
|
||||
|
||||
// Only works with batch, not in a transaction
|
||||
Multi.prototype.quit = function quit () {
|
||||
Multi.prototype.quit = function quit() {
|
||||
const callOnWrite = () => {
|
||||
// If called in a multi context, we expect redis is available
|
||||
this._client._closing = true
|
||||
@@ -113,7 +119,7 @@ Multi.prototype.quit = function quit () {
|
||||
* @param {RedisClient} client
|
||||
* @returns {function}
|
||||
*/
|
||||
function infoCallback (client) {
|
||||
function infoCallback(client) {
|
||||
return function (err, res) {
|
||||
if (err) {
|
||||
return err
|
||||
@@ -125,7 +131,7 @@ function infoCallback (client) {
|
||||
|
||||
const obj = {}
|
||||
const lines = res.split('\r\n')
|
||||
var topic = ''
|
||||
let topic = ''
|
||||
|
||||
while (lines.length) {
|
||||
const parts = lines.shift().split(':')
|
||||
@@ -170,18 +176,18 @@ function infoCallback (client) {
|
||||
}
|
||||
|
||||
// Store info in this.serverInfo after each call
|
||||
RedisClient.prototype.info = function info (section) {
|
||||
RedisClient.prototype.info = function info(section) {
|
||||
const args = section ? [section] : []
|
||||
return this.internalSendCommand(new Command('info', args, null, infoCallback(this)))
|
||||
}
|
||||
|
||||
Multi.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)))
|
||||
return this
|
||||
}
|
||||
|
||||
function authCallback (client, pass) {
|
||||
function authCallback(client, pass) {
|
||||
return function (err, res) {
|
||||
if (err) {
|
||||
if (noPasswordIsSet.test(err.message)) {
|
||||
@@ -194,7 +200,7 @@ function authCallback (client, pass) {
|
||||
}
|
||||
}
|
||||
|
||||
RedisClient.prototype.auth = function auth (pass) {
|
||||
RedisClient.prototype.auth = function auth(pass) {
|
||||
debug('Sending auth to %s id %s', this.address, this.connectionId)
|
||||
|
||||
// Stash auth for connect and reconnect.
|
||||
@@ -207,7 +213,7 @@ RedisClient.prototype.auth = function auth (pass) {
|
||||
}
|
||||
|
||||
// Only works with batch, not in a transaction
|
||||
Multi.prototype.auth = function auth (pass) {
|
||||
Multi.prototype.auth = function auth(pass) {
|
||||
debug('Sending auth to %s id %s', this.address, this.connectionId)
|
||||
|
||||
// Stash auth for connect and reconnect.
|
||||
@@ -216,12 +222,7 @@ Multi.prototype.auth = function auth (pass) {
|
||||
return this
|
||||
}
|
||||
|
||||
RedisClient.prototype.client = function client () {
|
||||
const len = arguments.length
|
||||
const arr = new Array(len)
|
||||
for (var i = 0; i < len; i += 1) {
|
||||
arr[i] = arguments[i]
|
||||
}
|
||||
RedisClient.prototype.client = function client(...arr) {
|
||||
var callOnWrite
|
||||
// CLIENT REPLY ON|OFF|SKIP
|
||||
if (arr.length === 2 && arr[0].toString().toUpperCase() === 'REPLY') {
|
||||
@@ -235,12 +236,7 @@ RedisClient.prototype.client = function client () {
|
||||
return this.internalSendCommand(new Command('client', arr, callOnWrite))
|
||||
}
|
||||
|
||||
Multi.prototype.client = function client () {
|
||||
const len = arguments.length
|
||||
const arr = new Array(len)
|
||||
for (var i = 0; i < len; i += 1) {
|
||||
arr[i] = arguments[i]
|
||||
}
|
||||
Multi.prototype.client = function client(...arr) {
|
||||
var callOnWrite
|
||||
// CLIENT REPLY ON|OFF|SKIP
|
||||
if (arr.length === 2 && arr[0].toString().toUpperCase() === 'REPLY') {
|
||||
@@ -255,24 +251,14 @@ Multi.prototype.client = function client () {
|
||||
return this
|
||||
}
|
||||
|
||||
RedisClient.prototype.subscribe = function subscribe () {
|
||||
const len = arguments.length
|
||||
const arr = new Array(len)
|
||||
for (var i = 0; i < len; i += 1) {
|
||||
arr[i] = arguments[i]
|
||||
}
|
||||
RedisClient.prototype.subscribe = function subscribe(...arr) {
|
||||
const callOnWrite = () => {
|
||||
this._pubSubMode = this._pubSubMode || this.commandQueue.length + 1
|
||||
}
|
||||
return this.internalSendCommand(new Command('subscribe', arr, callOnWrite))
|
||||
}
|
||||
|
||||
Multi.prototype.subscribe = function subscribe () {
|
||||
const len = arguments.length
|
||||
const arr = new Array(len)
|
||||
for (var i = 0; i < len; i += 1) {
|
||||
arr[i] = arguments[i]
|
||||
}
|
||||
Multi.prototype.subscribe = function subscribe(...arr) {
|
||||
const callOnWrite = () => {
|
||||
this._client._pubSubMode = this._client._pubSubMode || this._client.commandQueue.length + 1
|
||||
}
|
||||
@@ -280,51 +266,33 @@ Multi.prototype.subscribe = function subscribe () {
|
||||
return this
|
||||
}
|
||||
|
||||
RedisClient.prototype.unsubscribe = function unsubscribe () {
|
||||
const len = arguments.length
|
||||
const arr = new Array(len)
|
||||
for (var i = 0; i < len; i += 1) {
|
||||
arr[i] = arguments[i]
|
||||
}
|
||||
RedisClient.prototype.unsubscribe = function unsubscribe(...arr) {
|
||||
const callOnWrite = () => {
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return
|
||||
// value is manipulated in the callback
|
||||
this._pubSubMode = this._pubSubMode || this.commandQueue.length + 1
|
||||
}
|
||||
return this.internalSendCommand(new Command('unsubscribe', arr, callOnWrite))
|
||||
}
|
||||
|
||||
Multi.prototype.unsubscribe = function unsubscribe () {
|
||||
const len = arguments.length
|
||||
const arr = new Array(len)
|
||||
for (var i = 0; i < len; i += 1) {
|
||||
arr[i] = arguments[i]
|
||||
}
|
||||
Multi.prototype.unsubscribe = function unsubscribe(...arr) {
|
||||
const callOnWrite = () => {
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||
// 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))
|
||||
return this
|
||||
}
|
||||
|
||||
RedisClient.prototype.psubscribe = function psubscribe () {
|
||||
const len = arguments.length
|
||||
const arr = new Array(len)
|
||||
for (var i = 0; i < len; i += 1) {
|
||||
arr[i] = arguments[i]
|
||||
}
|
||||
RedisClient.prototype.psubscribe = function psubscribe(...arr) {
|
||||
const callOnWrite = () => {
|
||||
this._pubSubMode = this._pubSubMode || this.commandQueue.length + 1
|
||||
}
|
||||
return this.internalSendCommand(new Command('psubscribe', arr, callOnWrite))
|
||||
}
|
||||
|
||||
Multi.prototype.psubscribe = function psubscribe () {
|
||||
const len = arguments.length
|
||||
const arr = new Array(len)
|
||||
for (var i = 0; i < len; i += 1) {
|
||||
arr[i] = arguments[i]
|
||||
}
|
||||
Multi.prototype.psubscribe = function psubscribe(...arr) {
|
||||
const callOnWrite = () => {
|
||||
this._client._pubSubMode = this._client._pubSubMode || this._client.commandQueue.length + 1
|
||||
}
|
||||
@@ -332,27 +300,19 @@ Multi.prototype.psubscribe = function psubscribe () {
|
||||
return this
|
||||
}
|
||||
|
||||
RedisClient.prototype.punsubscribe = function punsubscribe () {
|
||||
const len = arguments.length
|
||||
const arr = new Array(len)
|
||||
for (var i = 0; i < len; i += 1) {
|
||||
arr[i] = arguments[i]
|
||||
}
|
||||
RedisClient.prototype.punsubscribe = function punsubscribe(...arr) {
|
||||
const callOnWrite = () => {
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return
|
||||
// value is manipulated in the callback
|
||||
this._pubSubMode = this._pubSubMode || this.commandQueue.length + 1
|
||||
}
|
||||
return this.internalSendCommand(new Command('punsubscribe', arr, callOnWrite))
|
||||
}
|
||||
|
||||
Multi.prototype.punsubscribe = function punsubscribe () {
|
||||
const len = arguments.length
|
||||
const arr = new Array(len)
|
||||
for (var i = 0; i < len; i += 1) {
|
||||
arr[i] = arguments[i]
|
||||
}
|
||||
Multi.prototype.punsubscribe = function punsubscribe(...arr) {
|
||||
const callOnWrite = () => {
|
||||
// Pub sub has to be activated even if not in pub sub mode, as the return value is manipulated in the callback
|
||||
// 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))
|
||||
|
Reference in New Issue
Block a user