add exception for when there are no keys

This commit is contained in:
Jakub Sokołowski 2018-11-15 14:30:19 +01:00
parent ff2907cadd
commit 1d115164f0
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
1 changed files with 1 additions and 0 deletions

View File

@ -22,6 +22,7 @@ class Counter {
async list () { async list () {
let keys = await this.redis.keys('*') let keys = await this.redis.keys('*')
if (keys.length == 0) { return {} }
let vals = await this.redis.mget(keys) let vals = await this.redis.mget(keys)
/* combine list of keys and values into an object */ /* combine list of keys and values into an object */
return keys.reduce((obj, k, i) => ({...obj, [k]: vals[i] }), {}) return keys.reduce((obj, k, i) => ({...obj, [k]: vals[i] }), {})