我正在使用node.js使用ioredis client(@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
),我可以使用 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
命令?谢谢
我终于设法使用了一系列命令作为构造函数的参数(如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();