使用 ioredis 在单个原子操作中发送多个 BITOP
Send many BITOP in a single atomic operation using ioredis
我正在使用带 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
),我可以使用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();
我正在使用带 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
),我可以使用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();