Отправить много BITOP за одну атомарную операцию, используя ioredis

Я использую клиент ioredis (@4.6.2) с node.js, и мне нужно выполнять много битовых операций (которые не зависят друг от друга). Что-то вроде этого :

import * as ioredis from "ioredis";

...

private readonly client: ioredis.Redis;
this.client = new ioredis("my_url");

...

await this.client.send_command("BITOP", "OR", "a_or_b", "a", "b");
await this.client.send_command("BITOP", "OR", "a_or_c", "a", "c");
await this.client.send_command("BITOP", "OR", "a_or_d", "a", "d");
await this.client.send_command("BITOP", "OR", "a_or_e", "a", "e");
// etc...

С некоторыми другими операциями (такими как setbit) я могу использовать объект pipeline и его функцию exec() для атомарного запуска:

const pipeline: Pipeline = this.client.pipeline();
pipeline.setbit(a, 1, 1);
pipeline.setbit(a, 12, 0);
pipeline.setbit(b, 3,  1);
await pipeline.exec();

Но я не могу найти ни pipeline.bitop(), ни pipeline.send_command() функции.

Есть ли способ отправить эти BITOP команды в атомарной операции? Спасибо


person Raytho    schedule 18.02.2019    source источник


Ответы (1)


Наконец-то мне удалось это сделать, используя массив команд в качестве параметров конструктора (как описано в документации ioredis), и это намного быстрее!

const result: number[][] = await this.redis.pipeline([
      ["bitop", "OR", "a_or_b", "a", "b"],
      ["bitop", "OR", "a_or_c", "a", "c"],
      ["bitop", "OR", "a_or_d", "a", "d"],
      ...

      ["bitcount", "a_or_b"],
      ["bitcount", "a_or_c"],
      ["bitcount", "a_or_d"],
      ...
]).exec();
person Raytho    schedule 19.02.2019