Отправить много BITOP в одной атомарной операции, используя ioredis - PullRequest
0 голосов
/ 18 февраля 2019

Я использую клиент 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) я могу использовать объект pipe и его функцию 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 команды в атомарной операции?Спасибо

1 Ответ

0 голосов
/ 19 февраля 2019

Мне наконец-то удалось это сделать, используя массив команд в качестве параметров для конструктора (как описано в документации 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();
...