zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

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

RedisJSNode -- with 32 level Working
2023-09-14 08:59:21 时间

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