0

我正在使用带有 node.js 的 ioredis 客户端(@4.6.2),我需要做很多位操作(它们不依赖于彼此)。像这样的东西:

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),我可以使用管道对象及其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在原子操作中发送这些命令?谢谢

4

1 回答 1

0

我终于设法做到了,使用一组命令作为构造函数的参数(如 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();
于 2019-02-19T11:04:45.400 回答