You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
doc: add jsdoc comments
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
const index = require('../')
|
const index = require('../')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Print a debug statement if in debug mode
|
||||||
|
*/
|
||||||
function debug () {
|
function debug () {
|
||||||
if (index.debugMode) {
|
if (index.debugMode) {
|
||||||
console.error.apply(null, arguments)
|
console.error.apply(null, arguments)
|
||||||
|
57
lib/utils.js
57
lib/utils.js
@@ -1,7 +1,17 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
// hgetall converts its replies to an Object. If the reply is empty, null is returned.
|
/**
|
||||||
// These function are only called with internal data and have therefore always the same instanceof X
|
* @description Convert an array to an object
|
||||||
|
*
|
||||||
|
* hgetall converts its replies to an object. If the reply is empty, null is returned.
|
||||||
|
* The reply might be a string or a buffer if this is called in a transaction (multi)
|
||||||
|
* because of the queuing response.
|
||||||
|
*
|
||||||
|
* reply.length can be undefined but `undefined > 0` === false.
|
||||||
|
*
|
||||||
|
* @param {any} reply
|
||||||
|
* @returns object
|
||||||
|
*/
|
||||||
function replyToObject (reply) {
|
function replyToObject (reply) {
|
||||||
// The reply might be a string or a buffer if this is called in a transaction (multi)
|
// The reply might be a string or a buffer if this is called in a transaction (multi)
|
||||||
if (reply.length === 0 || !(reply instanceof Array)) {
|
if (reply.length === 0 || !(reply instanceof Array)) {
|
||||||
@@ -14,6 +24,12 @@ function replyToObject (reply) {
|
|||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description receive an array with values and convert all buffers to strings
|
||||||
|
*
|
||||||
|
* @param {any[]} reply
|
||||||
|
* @returns any[]|string
|
||||||
|
*/
|
||||||
function replyToStrings (reply) {
|
function replyToStrings (reply) {
|
||||||
if (reply === null) {
|
if (reply === null) {
|
||||||
return null
|
return null
|
||||||
@@ -33,8 +49,15 @@ function replyToStrings (reply) {
|
|||||||
return reply
|
return reply
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deep clone arbitrary objects with arrays. Can't handle cyclic structures (results in a range error)
|
/**
|
||||||
// Any attribute with a non primitive value besides object and array will be passed by reference (e.g. Buffers, Maps, Functions)
|
* @description Deep clone arbitrary objects with arrays.
|
||||||
|
* Can't handle cyclic structures (results in a range error).
|
||||||
|
* Any attribute with a non primitive value besides object
|
||||||
|
* and array will be passed by reference (e.g. Buffers, Maps, Functions)
|
||||||
|
*
|
||||||
|
* @param {any} obj
|
||||||
|
* @returns any
|
||||||
|
*/
|
||||||
function clone (obj) {
|
function clone (obj) {
|
||||||
var copy
|
var copy
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
@@ -55,18 +78,36 @@ function clone (obj) {
|
|||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Calls clone and returns an object
|
||||||
|
*
|
||||||
|
* @param {undefined|object} obj
|
||||||
|
* @returns object
|
||||||
|
*/
|
||||||
function convenienceClone (obj) {
|
function convenienceClone (obj) {
|
||||||
return clone(obj) || {}
|
return clone(obj) || {}
|
||||||
}
|
}
|
||||||
|
|
||||||
function replyInOrder (self, callback, err, res, queue) {
|
/**
|
||||||
// If the queue is explicitly passed, use that, otherwise fall back to the offline queue first,
|
* @description Make sure a reply is handled in order by delaying a execution
|
||||||
// as there might be commands in both queues at the same time
|
* the to right moment.
|
||||||
|
*
|
||||||
|
* If the queue is explicitly passed, use that, otherwise fall back to the
|
||||||
|
* offline queue first, as there might be commands in both queues at the same
|
||||||
|
* time.
|
||||||
|
*
|
||||||
|
* @param {RedisClient} client
|
||||||
|
* @param {function} callback
|
||||||
|
* @param {Error|null} err
|
||||||
|
* @param {any} res
|
||||||
|
* @param {Denque} queue
|
||||||
|
*/
|
||||||
|
function replyInOrder (client, callback, err, res, queue) {
|
||||||
var commandObj
|
var commandObj
|
||||||
if (queue) {
|
if (queue) {
|
||||||
commandObj = queue.peekBack()
|
commandObj = queue.peekBack()
|
||||||
} else {
|
} else {
|
||||||
commandObj = self.offlineQueue.peekBack() || self.commandQueue.peekBack()
|
commandObj = client.offlineQueue.peekBack() || client.commandQueue.peekBack()
|
||||||
}
|
}
|
||||||
if (!commandObj) {
|
if (!commandObj) {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
|
Reference in New Issue
Block a user