我在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
命令?谢谢
发布于 2019-02-19 03:04:45
我终于成功地做到了,使用一系列命令作为构造函数的参数(如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();
https://stackoverflow.com/questions/54750860
复制