const scan = Pify(self._redis.scan.bind(self._redis));
const hgetall = Pify(self._redis.hgetall.bind(self._redis));
- const cursor = parseInt(this.request.query.cursor) || 0;
- const [nextCursor, keys] = yield scan(cursor, 'MATCH', `${internals.kPostsPrefix}:*`);
+ let keys = [];
+ let nextCursor = 0;
+ let currentKeys = null;
- if (nextCursor > 0) {
- this.append('Link', `<${this.request.origin}${this.request.path}?cursor=${nextCursor}>; rel="next"`);
- }
+ do {
+ [nextCursor, currentKeys] = yield scan(nextCursor || 0, 'MATCH', `${internals.kPostsPrefix}:*`);
+ keys = keys.concat(currentKeys);
+ } while (nextCursor > 0);
const posts = yield keys.map((key) => hgetall(key));
- this.body = posts;
+ this.body = posts.sort((a, b) => b.timestamp - a.timestamp);
};
}