Skip to content

Commit 5806c2f

Browse files
committed
fix: do not pass empty array of values into redis commands
1 parent c5fdc19 commit 5806c2f

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

adapter.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,19 @@ export default function ({ redis, scanCount, hashSlot = true }) {
246246

247247
function getKeys(scan, matcher, count) {
248248
function page(cursor, keys) {
249+
if (cursor === '0') return Async.of(keys).toPromise()
250+
249251
return scan(cursor, { pattern: matcher, count })
250252
.map(([nCursor, nKeys]) => {
251253
keys = keys.concat(nKeys)
252254

253-
return nCursor === '0'
254-
? keys
255-
/**
256-
* Return a thunk that continues the next iteration, thus ensuring the callstack
257-
* is only ever one call deep.
258-
*
259-
* This is continuation passing style, to be leverage by our trampoline
260-
*/
261-
: () => page(nCursor, keys)
255+
/**
256+
* Return a thunk that continues the next iteration, thus ensuring the callstack
257+
* is only ever one call deep.
258+
*
259+
* This is continuation passing style, to be leverage by our trampoline
260+
*/
261+
return () => page(nCursor, keys)
262262
}).toPromise()
263263
}
264264

@@ -275,6 +275,8 @@ function getValues({ get, mget }, store, count, hashSlot) {
275275

276276
return function (keys) {
277277
function page(keys, values) {
278+
if (!keys.length) return Async.of(values).toPromise()
279+
278280
const nKeys = keys.splice(0, count)
279281
return Async.of()
280282
/**
@@ -297,15 +299,13 @@ function getValues({ get, mget }, store, count, hashSlot) {
297299
})),
298300
)
299301

300-
return keys.length === 0
301-
? values
302-
/**
303-
* Return a thunk that continues the next iteration, thus ensuring the callstack
304-
* is only ever one call deep.
305-
*
306-
* This is continuation passing style, to be leverage by our trampoline
307-
*/
308-
: () => page(keys, values)
302+
/**
303+
* Return a thunk that continues the next iteration, thus ensuring the callstack
304+
* is only ever one call deep.
305+
*
306+
* This is continuation passing style, to be leverage by our trampoline
307+
*/
308+
return () => page(keys, values)
309309
}).toPromise()
310310
}
311311

@@ -322,6 +322,8 @@ function deleteKeys(del, count, hashSlot) {
322322
count = maxPageSize(count, hashSlot)
323323

324324
function page(keys) {
325+
if (!keys.length) return Async.of([]).toPromise()
326+
325327
const nKeys = keys.splice(0, count)
326328
return Async.of()
327329
/**
@@ -336,17 +338,13 @@ function deleteKeys(del, count, hashSlot) {
336338
* on any given operation
337339
*/
338340
.chain(() => hashSlot ? del(...nKeys) : Async.all(nKeys.map((key) => del(key))))
339-
.map(() => {
340-
return keys.length === 0
341-
? []
342-
/**
343-
* Return a thunk that continues the next iteration, thus ensuring the callstack
344-
* is only ever one call deep.
345-
*
346-
* This is continuation passing style, to be leverage by our trampoline
347-
*/
348-
: () => page(keys)
349-
}).toPromise()
341+
/**
342+
* Return a thunk that continues the next iteration, thus ensuring the callstack
343+
* is only ever one call deep.
344+
*
345+
* This is continuation passing style, to be leverage by our trampoline
346+
*/
347+
.map(() => () => page(keys)).toPromise()
350348
}
351349

352350
/**

0 commit comments

Comments
 (0)