Last active
October 8, 2015 21:28
-
-
Save avnersorek/544487c3fb82ca42c717 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var redisGet = Q.nbind(redisClient.get, redisClient); | |
var mysqlGet = Q.nbind(mysqlClient.get, mysqlClient); | |
function GetUser(userId) { | |
return redisGet(userId) | |
.then(function(redisResult){ | |
if (redisResult !== null) return redisResult; | |
else return mysqlGet(userId); | |
}); | |
} | |
// usage : | |
GetUser('dnkroz') | |
.then(function(user){ | |
console.log('user', user); | |
}) | |
.catch(function(error){ | |
console.error('error', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment