Advertisement
Anatolyukropov

Silmple Redis Queue

Sep 10th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Добавляем в Базу редиса
  2. export async function setQueue(this: Service, queueName, payload) {
  3.   return this.fileDownloadQueue.rpush(queueName, JSON.stringify(payload));
  4. }
  5.  
  6. Достаём из базы
  7. const queueData: QueueData | null = JSON.parse(
  8.     await this.fileDownloadQueue.lpop('downloadQueue'),
  9.   );
  10.  
  11. Посмотреть очередь
  12.  
  13. async handler(ctx: Context) {
  14.     const { page = 1, pageSize = 10 } = ctx.params;
  15.     const toIndex = page * pageSize - 1;
  16.     const fromIndex = toIndex - pageSize;
  17.  
  18.     return this.fileDownloadQueue.lrange('downloadQueue', fromIndex, toIndex);
  19.   },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement