• [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);
    });
  • 相关阅读:
    LibreOJ2095
    Codeforces
    LibreOJ2241
    LibreOJ2044
    LibreOJ2043
    LibreOJ2045
    LibreOJ2042
    LibreOJ2097
    洛谷P4175
    POJ2888
  • 原文地址:https://www.cnblogs.com/Answer1215/p/3883843.html
Copyright © 2020-2023  润新知