"get"λͺ λ Ήμ μ»λ λ°©λ² μ€μ κ°μ΄ 'true'κ° μλλκΉ?
μλ νμΈμ @yuany -- μ΄κ²μ κ²°κ³Όκ° μ€λΉλμμ λ λΉλκΈ°μ μΌλ‘ μ€νν μ½λ°±μ μ 곡νλ€λ μ μμ μ ν΅μ μΈ Node.js λΌμ΄λΈλ¬λ¦¬μ λλ€.
μ¦:
client.get("foo", function (error, value) { /* ... */ })
μ΄κ²μ Node.jsκ° μλνλ λ°©μμ κ²°κ³Όμ΄λ©° IO μμ μ λΉλκΈ°μμΌλ‘ μνλ©λλ€.
μ΄λ¬ν ν¨μμ λ°ν κ°μ κ°μ΄ _not_μ λλ€.
κ°μ¬ν©λλ€, @brycebaril λ€μκ³Ό κ°μ κΈ°λ₯μ μλνμ΅λλ€.
var κ²°κ³Ό = client.get("foo", ν¨μ(μ€λ₯, κ°) { λ°ν κ°});
alert(result);//κ²°κ³Όλ 'κ±°μ§' λλ 'μ°Έ'μ΄μ§λ§ λ°ν κ°μ redisμ ν€λ‘ μ€μ κ°μ
λλ€.
μλ νμΈμ @yuany -- IOλ₯Ό μνν λ λ Έλκ° μλνλ λ°©μμ΄ μλλλ€.
μ½λ°±μ κ²°κ³Όλ₯Ό μ¬μ©ν μ μμ λ μ€νν 컨ν μ€νΈλ₯Ό μ 곡ν©λλ€. IOμ μμ‘΄νμ§ μλ λ€λ₯Έ λͺ¨λ μ½λλ IO μμ μ΄ λκΈ°μ΄μ μΆκ°λκ³ μ€νλκ³ μλ΅μ΄ λκΈ°νλ λμ μ€νλ©λλ€.
μλ λ°©μμ λν΄ μμΈν μμλ³Ό μμλ μ’μ κ³³μ λ€μκ³Ό κ°μ΅λλ€. https://github.com/maxogden/art-of-node#callbacks
μ
client.get("foo", function (error, value) {
// value is only defined in the context of this callback
console.log(value)
})
// this parent code has already executed, before it asked Redis for the value
@brycebaril κ°μ¬ν©λλ€. μ΄μ μ½λ°± ν¨μ μ€νμ΄ λΉλκΈ°μμ΄λΌλ λ¬Έμ κ° λͺ νν΄μ‘μ΅λλ€.
κ°μ₯ μ μ©ν λκΈ
μλ νμΈμ @yuany -- μ΄κ²μ κ²°κ³Όκ° μ€λΉλμμ λ λΉλκΈ°μ μΌλ‘ μ€νν μ½λ°±μ μ 곡νλ€λ μ μμ μ ν΅μ μΈ Node.js λΌμ΄λΈλ¬λ¦¬μ λλ€.
μ¦:
μ΄κ²μ Node.jsκ° μλνλ λ°©μμ κ²°κ³Όμ΄λ©° IO μμ μ λΉλκΈ°μμΌλ‘ μνλ©λλ€.
μ΄λ¬ν ν¨μμ λ°ν κ°μ κ°μ΄ _not_μ λλ€.