You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +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:
@@ -1,6 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const debug = require('./debug')
|
||||
|
||||
const SUBSCRIBE_COMMANDS = {
|
||||
subscribe: true,
|
||||
unsubscribe: true,
|
||||
@@ -8,17 +9,22 @@ const SUBSCRIBE_COMMANDS = {
|
||||
punsubscribe: true
|
||||
}
|
||||
|
||||
function subscribeUnsubscribe (client, reply, type) {
|
||||
// Subscribe commands take an optional callback and also emit an event, but only the Last_ response is included in the callback
|
||||
// The pub sub commands return each argument in a separate return value and have to be handled that way
|
||||
function subscribeUnsubscribe(client, reply, type) {
|
||||
// Subscribe commands take an optional callback and also emit an event, but
|
||||
// only the Last_ response is included in the callback The pub sub commands
|
||||
// return each argument in a separate return value and have to be handled that
|
||||
// way
|
||||
const commandObj = client.commandQueue.peekAt(0)
|
||||
const buffer = client._options.returnBuffers || client._options.detectBuffers && commandObj.bufferArgs
|
||||
const buffer = client._options.returnBuffers ||
|
||||
client._options.detectBuffers && commandObj.bufferArgs
|
||||
const channel = (buffer || reply[1] === null) ? reply[1] : reply[1].toString()
|
||||
const count = +reply[2] // Return the channel counter as number no matter if `stringNumbers` is activated or not
|
||||
// Return the channel counter as number no matter if `stringNumbers` is activated or not
|
||||
const count = +reply[2]
|
||||
debug(type, channel)
|
||||
|
||||
// Emit first, then return the callback
|
||||
if (channel !== null) { // Do not emit or "unsubscribe" something if there was no channel to unsubscribe from
|
||||
// Do not emit or "unsubscribe" something if there was no channel to unsubscribe from
|
||||
if (channel !== null) {
|
||||
if (type === 'subscribe' || type === 'psubscribe') {
|
||||
client._subscriptionSet[`${type}_${channel}`] = channel
|
||||
} else {
|
||||
@@ -29,10 +35,13 @@ function subscribeUnsubscribe (client, reply, type) {
|
||||
client._subscribeChannels.push(channel)
|
||||
}
|
||||
|
||||
if (commandObj.argsLength === 1 || client._subCommandsLeft === 1 || commandObj.argsLength === 0 && (count === 0 || channel === null)) {
|
||||
if (commandObj.argsLength === 1 ||
|
||||
client._subCommandsLeft === 1 ||
|
||||
commandObj.argsLength === 0 && (count === 0 || channel === null)) {
|
||||
if (count === 0) { // Unsubscribed from all channels
|
||||
client._pubSubMode = 0 // Deactivating pub sub mode
|
||||
// This should be a rare case and therefore handling it this way should be good performance wise for the general case
|
||||
// This should be a rare case and therefore handling it this way should be
|
||||
// good performance wise for the general case
|
||||
for (var i = 1; i < client.commandQueue.length; i++) {
|
||||
const runningCommand = client.commandQueue.peekAt(i)
|
||||
if (SUBSCRIBE_COMMANDS[runningCommand.command]) {
|
||||
@@ -45,16 +54,14 @@ function subscribeUnsubscribe (client, reply, type) {
|
||||
commandObj.callback(null, [count, client._subscribeChannels])
|
||||
client._subscribeChannels = []
|
||||
client._subCommandsLeft = 0
|
||||
} else if (client._subCommandsLeft !== 0) {
|
||||
client._subCommandsLeft--
|
||||
} else {
|
||||
if (client._subCommandsLeft !== 0) {
|
||||
client._subCommandsLeft--
|
||||
} else {
|
||||
client._subCommandsLeft = commandObj.argsLength ? commandObj.argsLength - 1 : count
|
||||
}
|
||||
client._subCommandsLeft = commandObj.argsLength ? commandObj.argsLength - 1 : count
|
||||
}
|
||||
}
|
||||
|
||||
function returnPubSub (client, reply) {
|
||||
function returnPubSub(client, reply) {
|
||||
const type = reply[0].toString()
|
||||
if (type === 'message') { // Channel, message
|
||||
if (typeof reply[1] !== 'string') {
|
||||
|
Reference in New Issue
Block a user