public
Last active

Q + node_redis

  • Download Gist
qredis.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# Applies Q.nbind to all redis operations and returns a wrapped client
_ = require("underscore")._
Q = require "q"
 
nbindOps = (client) ->
functions = _.functions client
 
# All the ops are available as upper/lowercase functions, I exploit this
# to filter out the Redis operations from the other functions of the client
#
ops = functions.filter (f) -> f.toUpperCase() is f
lc = (op.toLowerCase() for op in ops)
ops = ops.concat(lc)
p = {}
for op in ops
p[op] = Q.nbind client[op], client
 
p["multi"] = p["MULTI"] = ->
m = client.multi.call client, arguments
m.exec = Q.nbind m.exec, m
m
p
 
nbind = (client) ->
client.q = nbindOps(client)
client
 
module.exports =
nbindOps: nbindOps
nbind: nbind

Nice hack on figuring out which methods are redis commands :gem:

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.