我已经为我的 node
应用编写了一个负载测试器。我的 Node 应用程序使用 redis
作为后端来在我的应用程序的不同集群(亚马逊实例)之间共享信息。
当我达到大约 100 个请求/秒时,以下代码生成 null
redisClient.hmset("visitor:" + userID.toString() + ":" + channel.toString(), {
"channel": channel.toString(),
"clusterID": Config.clusterID,
"name": randomName.toString()
});
然后当我尝试查看 hgetall
上的内容时:
"visitor:" + userID.toString() + ":" + channel.toString()
内容为null
。
知道这是怎么发生的吗? 请注意,这仅在达到每秒 100 个或更多请求后才会发生。
对于我的 redis 服务器,我使用的是 ElastiCache
t1.micro
实例
最佳答案
您是否正在等待 hmset 的回调?
应该是
var key = "visitor:" + userID.toString() + ":" + channel.toString();
redisClient.hmset(key, {
"channel": channel.toString(),
"clusterID": Config.clusterID,
"name": randomName.toString()
}, function(err) {
redisClient.hgetall(key, function(err, data) {
console.log(data);
});
});
关于node.js - redis 中的快速 hmset 产生空哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27153322/