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);
});

 

相关文章:

  • 2022-02-01
  • 2022-12-23
  • 2022-01-02
  • 2021-07-02
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
猜你喜欢
  • 2021-08-10
  • 2021-10-29
  • 2021-08-30
  • 2021-12-22
  • 2022-01-18
  • 2021-07-15
  • 2021-12-25
相关资源
相似解决方案