node.js - Node JS批处理获取Redis key

标签 node.js caching redis

我想使用批处理请求立即将很多键/值存储在Redis上。
我正在使用节点js redis客户端。这个想法是异步地对多个键发出get请求,有什么办法吗?
我检查了节点js Redis客户端中的批处理功能,据我了解,如果您想一次获取哈希的所有元素,而不是一次在异步模式下获取不同键的数据,这很有用。

我想做的是读取所有表以根据值的属性(时间戳)选择特定的键/值

最佳答案

您正在根据docs寻找MGET:

redis> SET key1 "Hello"
"OK"
redis> SET key2 "World"
"OK"
redis> MGET key1 key2 nonexisting
1) "Hello"
2) "World"
3) (nil)


如果您使用的是redis软件包,则应如下所示:
client.mget(["key1", "key2", "nonexisting"], (err, val) => {
  console.log(val); //["Hello", "World", null]
});

关于node.js - Node JS批处理获取Redis key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60851580/

相关文章:

c# - 堆栈溢出、Redis 和缓存失效

phpredis 错误在 Linux 中找不到类 Redis

redis - 无法连接到位于 127.0.0.1 的 Redis :0: Connection refused (when using init script to shut down a redis server w/unix socket)

javascript - Restify 和 Angular JS 都位于不同的域中,如何使用 Restify 响应设置 httponly cookie?

node.js - Gulp安装: 'fs: re-evaluating native module sources is not supported' and node-sass errors

javascript - AngularJS - 应用程序内异步加载部件

node.js - 本地安装Gulp失败

hibernate - 如何在grails中缓存(整个表或Domain.list()方法的结果)?

python - 更新类的属性时清除某些方法的 lru_cache?

Redis – 无法打开 .rdb 以保存 : Permission denied