I use redis, and here are my codes
const redis = require("redis"), client = redis.createClient()
let count1, count2, countall
client.hgetall('onekey', function(err, object) {
if (object) {
count1 = object.onevalue
console.log(count1)
} else {
count1 = 2
}
client.quit()
})
client.hgetall('twokey', function(err, object) {
if (object) {
count2 = object.twovalue
console.log(count2)
} else {
count2 = 3
}
client.quit()
})
countall = count1 + count2
console.log(countall)
I run this code, and I can get the results of count1
and count2
, but console.log(countall)
shows undefined
, I don't why, how can I pass the value to out of the function block? Many thanks