- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 ioredis我想返回下面示例中的路径和值,一直到匿名函数。
console.log(
function (jsonGraphArg) {
return Redis.hget(jsonGraphArg[0], jsonGraphArg[1], function(error, result){
result = JSON.parse(result);
return {
path: [jsonGraphArg[0], jsonGraphArg[1], jsonGraphArg[2][0]],
value: result[jsonGraphArg[2][0]]
};
});
}
);
我希望 console.log()
中的结果是这样的:
{
path: "something",
value: "something else"
}
但它却给了我:
{
_bitField: 1,
_fulfillmentHandler0: [Function: successAdapter],
_rejectionHandler0: [Function: errorAdapter],
_progressHandler0: undefined,
_promise0: [Function],
_receiver0: [Circular],
_settledValue: undefined
}
最佳答案
首先,您尝试记录函数声明而不是函数执行结果。
console.log(
(function (jsonGraphArg) {
return Redis.hget(jsonGraphArg[0], jsonGraphArg[1], function(error, result){
result = JSON.parse(result);
return {
path: [jsonGraphArg[0], jsonGraphArg[1], jsonGraphArg[2][0]],
value: result[jsonGraphArg[2][0]]
};
});
})();
);
此代码将为您提供函数执行的结果。
第二个问题是Redis.hget
是一个异步函数。要在 redis 返回结果后立即获得结果,您需要使用回调。
var callback = function(res) {
console.log(res);
}
(function (jsonGraphArg, callback) {
return Redis.hget(jsonGraphArg[0], jsonGraphArg[1], function(error, result){
result = JSON.parse(result);
return callback({
path: [jsonGraphArg[0], jsonGraphArg[1], jsonGraphArg[2][0]],
value: result[jsonGraphArg[2][0]]
});
});
})();
使用这段代码,当 Redis 返回数据时,它将调用带有 res
参数的 callback
函数,该参数将是您的具有路径和值属性的对象。
关于javascript - 如何使用 ioredis 在 nodejs 中链接返回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32230118/
我正在遵循 Jest 文档 here 中的手动模拟示例 我正在尝试将此示例扩展到我自己的项目和 ioredis 的手动模拟 (mocks/ioredis.js)。我正在尝试用我自己的 ioredis
我正在遵循 Jest 文档 here 中的手动模拟示例 我正在尝试将此示例扩展到我自己的项目和 ioredis 的手动模拟 (mocks/ioredis.js)。我正在尝试用我自己的 ioredis
当使用 ioredis ( https://github.com/luin/ioredis ) 连接到 redis 集群时,您只需要指定一个节点,例如三节点集群 127.0.0.1:7000127.0
我正在尝试优雅地处理 Redis 错误,以便绕过错误并改为执行其他操作,而不是让我的应用程序崩溃。 但到目前为止,我不能只捕获 ioredis 抛出的异常,它绕过了我的 try/catch 并终止了当
我将 ioredis 与 express (nodejs) 一起使用我知道有一种方法可以通过这样的模式删除键: redis-cli KEYS "sample_pattern:*" | xargs re
我目前正在尝试从运行我的应用程序的服务器连接到存储在另一个实例上的我的 Redis 集群。我正在使用 IoRedis 在我的应用程序和我的 Redis 实例之间建立接口(interface),并且当只
这是我的代码: const Redis = require('ioredis'); const client = new Redis(); // multi set client.mset({'key
我正在使用ioredis。 为了防止巨大的缓冲区可能会使我的应用程序崩溃,我想在redis关闭时忽略请求,并捕获这些请求。 有什么办法可以实现? 最佳答案 您可以使用circuit breaker d
我想用键匹配模式“LOGIN::”搜索 Redis 数据库。我在我的应用程序中使用 ioredis。昨天我搜索了整个网络,我得到了一些可以完成这项工作的选项,如下所示: 按键 扫描流 问题: impo
我正在尝试为 ioredis nodejs 中的一组值设置过期时间。我可以使用此命令将一组添加到 reids redis.sadd('set', 1, 3, 5, 7); 但是我需要为这个集合设置一个
我很难在我的 typescript 测试中模拟第三方库。 我正在基于这个 typescript-starter 创建一个库图书馆。它使用 ava 进行测试。 在我的例子中,我试图模拟 ioredis
我正在使用 ioredis 模块。 var Redis = require('ioredis'); var redis = new Redis(); 在执行 new Redis() 时,与 Redis
在我设置或获取 key 之前,是否有任何方法可以检查 weather redis 是否可用或由于某些问题而终止?我怎样才能做到这一点? 我正在使用 ioredis 模块。 最佳答案 var Redi
const Redis = require('ioredis'); const sub = new Redis(); const pub = new Redis(); sub.on('subscrib
我将 ioredis 客户端 (@4.6.2) 与 node.js 一起使用,我需要做很多位操作(它们不相互依赖)。像这样: import * as ioredis from "ioredis"; .
我有一个基于 Laravel 构建的应用程序。我正在使用 Laradock 并尝试使用 Redis 容器,但我遇到了连接问题。 使用命令: docker inspect laradock_redis_
我正在使用 ioredis我想返回下面示例中的路径和值,一直到匿名函数。 console.log( function (jsonGraphArg) { return Redis
我正在尝试在 Node 脚本的 ioredis 中使用 hget 和 hset,我查看了文档,但找不到如何操作,知道如何操作吗? 谢谢, 最佳答案 这已在评论中得到解答,但对于 future 的搜索引
我想使用 Redis 位图来表示值。 如果我有一个整数值,那么我希望能够将位图的相应索引设置为 1或 true . 我还希望能够检索整个位图并遍历它以确定“1”的位置。 有一个bitfield dat
我们希望我们的 Redis 更具可扩展性,并且我们希望能够添加更多读取实例。 我正在尝试使用这个新的阅读器端点:https://aws.amazon.com/about-aws/whats-new/2
我是一名优秀的程序员,十分优秀!