gpt4 book ai didi

javascript - 如何将 KEYS 分配给 client.keys() 函数中的值?

转载 作者:可可西里 更新时间:2023-11-01 11:25:50 26 4
gpt4 key购买 nike

我有麻烦了,我想将在 REDIS 中定义的 KEYS 分配给 redisClient.keys 函数中的一个值,但我做不到,我尝试控制台记录它,我得到的结果是正确的,但它不能从该键功能的外部读取。如果你帮助我,我将不胜感激。

const redis = require('redis');
const redisClient = redis.createClient();
var values ;

redisClient.flushall();

redisClient.hmset('Angelica', { "Blues Traveler": 3.5, "Broken Bells": 2.0, "Norah Jones": 4.5, "Phoenix": 5.0, "Slightly Stoopid": 1.5, "The Strokes": 2.5, "Vampire Weekend": 2.0 });
redisClient.hmset('Bill', { "Blues Traveler": 2.0, "Broken Bells": 3.5, "Deadmau5": 4.0, "Phoenix": 2.0, "Slightly Stoopid": 3.5, "Vampire Weekend": 3.0 });
redisClient.hmset('Dan', { "Blues Traveler": 3.0, "Broken Bells": 4.0, "Deadmau5": 4.5, "Phoenix": 3.0, "Slightly Stoopid": 4.5, "The Strokes": 4.0, "Vampire Weekend": 2.0 });
redisClient.hmset('Hailey', { "Broken Bells": 4.0, "Deadmau5": 1.0, "Norah Jones": 4.0, "The Strokes": 4.0, "Vampire Weekend": 1.0 });
redisClient.hmset('Jordyn', { "Broken Bells": 4.5, "Deadmau5": 4.0, "Norah Jones": 5.0, "Phoenix": 5.0, "Slightly Stoopid": 4.5, "The Strokes": 4.0, "Vampire Weekend": 4.0 });
redisClient.hmset('Sam', { "Blues Traveler": 5.0, "Broken Bells": 2.0, "Norah Jones": 3.0, "Phoenix": 5.0, "Slightly Stoopid": 4.0, "The Strokes": 5.0 });
redisClient.hmset('Veronica', { "Blues Traveler": 3.0, "Norah Jones": 5.0, "Phoenix": 4.0, "Slightly Stoopid": 2.5, "The Strokes": 3.0 });
redisClient.hmset('Chan', { "Blues Traveler": 5.0, "Broken Bells": 1.0, "Deadmau5": 1.0, "Norah Jones": 3.0, "Phoenix": 5, "Slightly Stoopid": 1.0 });

redisClient.keys('*', (err, responde) => {
redisClient.hmget(responde);
values=responde.toLocaleString()
console.log(responde.toLocaleString())
})

console.log( values)

最佳答案

我想您可能会发现 console.log(values) 实际上在 redisClient.keys() 方法的回调之前执行。

关于javascript - 如何将 KEYS 分配给 client.keys() 函数中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45484676/

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