[Node.js]32. Level 7: Working with Lists -- Redis

As we saw in the video, redis can do more than just simple key-value pairs. We are going to be using redis lists later to add persistance to our live-moderation app, so let's practice using them now.

Using the redis client's lpush command, insert the two questions below into the questions list

var redis = require('redis');
var client = redis.createClient();

var question1 = "Where is the dog?";
var question2 = "Where is the cat?";

client.lpush("questions", question1);
client.lpush("questions", question2);

 

Now that we have seeded the questions list, use the lrange command to return all of the items and log them.

var redis = require('redis');
var client = redis.createClient();

client.lrange('questions', 0, -1, function(err, messages){
    console.log(messages);
});

 

posted @ 2014-07-31 23:52  Zhentiw  阅读(122)  评论(0编辑  收藏  举报