Giter Site home page Giter Site logo

Comments (4)

maritz avatar maritz commented on July 20, 2024

The entire purpose of using redis with node.js is that it's asynchronous. Asynchronous means that you cannot do something like the first, and that's a good thing.

Your options are: do whatever you want to do with the value in the callback or... no, just do it in the callback.

Btw: That your last way works, is a bit lucky because if the redis-server takes just a little longer, "somevar" will still not be "value" by the time you get to the sys.puts().
I suggest that you read up a little on what it means to work in an asynchronous environment. That should clear it up.

from redis-node-client.

marcuswestin avatar marcuswestin commented on July 20, 2024

You should always handle I/O responses in the callback..

redis.lindex('mylist', 0, function (err, value) {
    if (err) { throw err }
    sys.puts(value);
});

from redis-node-client.

jchaney avatar jchaney commented on July 20, 2024

Thank you both for the responses. I shouldn't have posted example 1, I know that won't work. And now I understand why the other two won't work. I think what drove me towards these examples is that I tried this:

redis.lindex('mylist', 0, function (err, value) { sys.puts(value); });

And it wouldn't put anything to the console. It seemed no matter what I did, value wouldn't give me anything unless I first assigned it to another var, which seems ridiculous. I will try it again when I get home, but I'm 99% sure this was not working for me. And yes, there was something in the DB. Thanks again.

from redis-node-client.

fictorial avatar fictorial commented on July 20, 2024

Wow, maritz and marcuswestin beat me to it! Thanks.

@wormwoodmedia: take a look at the test/test.js file for lots of examples.

from redis-node-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.