Better way to extract array of objects from Redis on node.js using CoffeeScript -
please review code below , suggest more elegant ways of doing same.
i storing json strings in redis database. extract array of objects, use following code works. learning though wanted find better ways of doing same. here coffeescript code:
redis = require "redis" client = module.exports.client = redis.createclient() getrecord = module.exports.getrecord = (key, fn) -> client.get key, (err, result) -> fn err, null if err obj = json.parse(result) fn null, obj getdataset = module.exports.getdataset = (pattern, fn) -> client.keys pattern, (err, result) -> fn err, null if err dataset = [] length = result.length count = 0 key in result getrecord key, (err, obj) -> fn err, null if err count = count + 1 dataset.push obj fn null, dataset if count length
i think code pretty solid. warned your
for key in result
loop creating list comprehension; means if result.length
large, you're going see significant performance overhead , perhaps memory issues. avoid this, need add explicit return
:
for key in result getrecord key, (err, obj) -> ... return
there proposal introduce void function syntax such cases, none of coffeescript's core committers seem fond of it.
Comments
Post a Comment