Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

node.js - using async/await in redis on nodejs

I have a class named RedisManger in an typescript project. in that class I have a method to get info from redis database:

   async Get(key: string): Promise<any> {
    let value: any;
    try {
        this.client.get(key, async (err, data) => {
            if (err) { value = err }
            else {
                value = data;
            }
        });
        return value;
    } catch (error) {
        return error.message;
    }
}

but it always returns undefined even though I can see my key has a value in redis-cli.

when I log data in here :

this.client.get(key, async (err, data) => {
            console.log(data)
        });

It also prints undefined

how can I sovle my problem?

question from:https://stackoverflow.com/questions/65867980/using-async-await-in-redis-on-nodejs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...