Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6114053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:55:47+00:00 2026-05-23T14:55:47+00:00

Please review the code below and suggest more elegant ways of doing the same.

  • 0

Please review the code below and suggest more elegant ways of doing the same.

I am storing JSON strings in Redis database. To extract an array of objects, I use the following code that works. Just for learning though I wanted to find better ways of doing the same. Here is the 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
    for key in result
      getRecord key, (err, obj) ->
        fn err, null if err
        count = count + 1
        dataSet.push obj
        fn null, dataSet if count is length
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:55:48+00:00Added an answer on May 23, 2026 at 2:55 pm

    I think your code is pretty solid. Just be warned that your

    for key in result
    

    loop is creating a list comprehension; that means that if result.length is large, you’re going to see significant performance overhead and perhaps even memory issues. To avoid this, you need to add an explicit return:

    for key in result
      getRecord key, (err, obj) ->
        ...
    return
    

    There was a proposal to introduce a void function syntax for just such cases, but none of CoffeeScript’s core committers seem very fond of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a memory leak at NSDate . Please review the code below. -(void)myMethods:(NSDate
Please review my brief example code below and tell me if there is better,
Please review my .htaccess code below. The code below was suggested by I User
Please review the example code below, I have a class file that is loaded
I got another problem with the FCKEditor within ASP.NET MVC. Please review the code
I saw some code as below during a peer-code-review session: char *s = new
Please, move this question to Code Review -area . It is better suited there
Please suggest some good resources to start writing Java Web services.
Please, provide code examples in a language of your choice. Update : No constraints
i have a javascript module name SceneModule, see the code snippet below var SceneModule

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.