gpt4 book ai didi

node.js - 使用 ioredis 在单个原子操作中发送多个 BITOP

转载 作者:可可西里 更新时间:2023-11-01 11:23:48 28 4
gpt4 key购买 nike

我将 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),我可以使用 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 在单个原子操作中发送多个 BITOP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54750860/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com