2017-06-29 22 views
10

düğüm v: 8.1.2kullanımı düğüm Redis 8 util.promisify

nod 8 util.promisify, bir blurbird ile REDIS müşteri node_redis kullanın.

geri arama redis.get Tamam, ama

için çözüldü promisify tip olsun hata mesajı

TypeError: Cannot read property 'internal_send_command' of undefined
at get (D:\Github\redis-test\node_modules\redis\lib\commands.js:62:24)
at get (internal/util.js:229:26)
at D:\Github\redis-test\app.js:23:27
at Object. (D:\Github\redis-test\app.js:31:3)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)

benim test kodu

const util = require('util'); 

var redis = require("redis"), 
    client = redis.createClient({ 
     host: "192.168.99.100", 
     port: 32768, 
    }); 

let get = util.promisify(client.get); 

(async function() { 
    client.set(["aaa", JSON.stringify({ 
     A: 'a', 
     B: 'b', 
     C: "C" 
    })]); 

    client.get("aaa", (err, value) => { 
     console.log(`use callback: ${value}`); 
    }); 

    try { 
     let value = await get("aaa"); 
     console.log(`use promisify: ${value}`); 
    } catch (e) { 
     console.log(`promisify error:`); 
     console.log(e); 
    } 

    client.quit(); 
})() 

cevap

15

let get = util.promisify(client.get).bind(client); için let get = util.promisify(client.get);

değişen bana :)

+0

Teşekkürler! 'çözüldü' bu sorun ' [this.internal_send_command] (https://github.com/NodeRedis/node_redis/blob/ff9b727609ea125919828f7373e40082fd432eec/lib/commands.js#L62) bağlama olmadan' this 'undefined –