Skip to content

Commit

Permalink
Fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Dec 1, 2016
1 parent 92b1393 commit 96001b9
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions lib/domain/storage/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ function getCodeAndPopulateCache(storage, namespace, id, preCache) {
});
}


function getMultiCodes(storage, codes, preCache) {
const keys = codes.map(({ namespace, id }) => redisKey(namespace, id));
const pipeline = storage.client.pipeline();

for (const key of keys) {
pipeline.hget(key, 'hash');
}
return pipeline
.exec()
.then(results => results.map(([err, hash], i) => {
if (err) {
return Promise.reject(err);
}
const key = keys[i];
const { namespace, id } = codes[i];
const cacheItem = storage.cache[key];

if (hash && cacheItem && cacheItem.hash === hash) {
return cacheItem;
}

// populate the cache
return getCodeAndPopulateCache(storage, namespace, id, preCache);
}));
}


class StorageRedis extends Storage {
constructor(customOptions = null, callback = null) {
super('Redis');
Expand Down Expand Up @@ -223,31 +251,4 @@ class StorageRedis extends Storage {
}
}


function getMultiCodes(storage, codes, preCache) {
const keys = codes.map(({ namespace, id }) => redisKey(namespace, id));
const pipeline = storage.client.pipeline();

for (const key of keys) {
pipeline.hget(key, 'hash');
}
return pipeline
.exec()
.then(results => results.map(([err, hash], i) => {
if (err) {
return Promise.reject(err);
}
const key = keys[i];
const { namespace, id } = codes[i];
const cacheItem = storage.cache[key];

if (hash && cacheItem && cacheItem.hash === hash) {
return cacheItem;
}

// populate the cache
return getCodeAndPopulateCache(storage, namespace, id, preCache);
}));
}

module.exports = StorageRedis;

0 comments on commit 96001b9

Please sign in to comment.