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

[Node.js]32. Level 7: Working with Lists -- Redis的更多相关文章

  1. [Node.js]31. Level 7: Redis coming for Node.js, Simple Redis Commands

    Let's start practicing using the redis key-value store from our node application. First require the  ...

  2. [Node.js]30. Level 6: Listen 'Question' from client, and then Answer the Question

    Clients can also answer each other questions, so let's build that feature by first listening for the ...

  3. [Node.js]29. Level 6: Socket.io: Setting up Socket.io server-side & Client socket.io setup

    Below we've already created an express server, but we want to start building a real-time Q&A mod ...

  4. [Node.js]24. Level 5: Express, Express routes

    Create an express route that responds to GET requests at the URL /tweets that responds with the file ...

  5. [Node.js]23. Level 4: Semantic versioning

    Update the versions on your dependencies to be a little more flexible, adding the ~ in front of your ...

  6. [Node.js]22. Level 4: Dependency

    Add two dependencies to your package.json file, connect and underscore. You'll want to useconnect ve ...

  7. [Node.js]33. Level 7: Persisting Questions

    Let's go back to our live-moderation app and add some persistence, first to the questions people ask ...

  8. [Node.js]28. Level 5: Express Server

    Now let's create an express server which queries out for this search term and just returns the json. ...

  9. [Node.js]27. Level 5: URL Building & Doing the Request

    Let's create a page which calls the twitter search API and displays the last few results for Code Sc ...

随机推荐

  1. SPOJ6717 Two Paths 树形dp

    首先有朴素的\(O(n^2)\)想法 首先枚举断边,之后对于断边之后的两棵子树求出直径 考虑优化这个朴素的想法 考虑换根\(dp\) 具体而言,首先求出\(f[i], fs[i]\)表示\(i\)号点 ...

  2. [BZOJ5287][HNOI2018]毒瘤(虚树DP)

    暴力枚举非树边取值做DP可得75. 注意到每次枚举出一个容斥状态的时候,都要做大量重复操作. 建立虚树,预处理出虚树上两点间的转移系数.也可动态DP解决. 树上倍增.动态DP.虚树DP似乎是这种问题的 ...

  3. 【20181103T2】图【结论+bfs最短路】

    一眼最短路 --感觉是个结论啊 建超级源汇? 什么鬼 合并ab和cd? 不一样的吗 开始想的至少有一条路径是最短路 然后发现不对: 开始对着这个图瞎想 从B开始找A的最短路,然后把到B小于等于的边赋成 ...

  4. BZOJ.4316.小C的独立集(仙人掌 DP)

    题目链接 \(Description\) 求一棵仙人掌的最大独立集. \(Solution\) 如果是树,那么 \(f[i][0/1]\) 表示当前点不取/取的最大独立集大小,直接DP即可,即 \(f ...

  5. Mac OS下不产生.DS_Store 隐藏文件和清理.DS_Store的方法

    一.清理.DS_Store的方法 1. 打开终端 (Macintosh HD > Applications > Utilities > Terminal)2. 输入命令: " ...

  6. oracle中的术语

    数据库:数据库是实实在在存在的文件,一个数据库文件体系中大致包含(数据文件DBF.控制文件CTL.日志文件LOG) 数据库实例:每个数据库都会有一个数据库实例与之对应,外界环境要通过与数据库实例的交互 ...

  7. GDB 自动化操作的技术-PYTHON

    https://github.com/spacewander/debugger-utils http://python.jobbole.com/85415/ https://segmentfault. ...

  8. Nginx和Tomcat负载均衡实现session共享

    以前的项目使用Nginx作为反向代理实现了多个Tomcat的负载均衡,为了实现多个Tomcat之间的session共享,使用了开源的Memcached-Session-Manager框架. 此框架的优 ...

  9. 启明星产品与微软Active Directory活动目录集成说明

    本文介绍启明星Helpdesk系统,如何和微软域集成. (1)确保在集成微软域之前,系统已经能够访问. (2)进入后台,用户管理页面,新加一个账户,此账户需要在微软域里(普通账户即可),然后在角色里设 ...

  10. 3D屏保:魔方2.0版本

    一个三维魔方的屏保软件,可支持2级到72级的魔方.启动后魔方会自动旋转,并最终回到初始状态.有很多人问我这是怎么做到的,用的什么解魔方的算法,其实我自己根本就不会玩魔方,别人用技巧解魔方,我这程序中用 ...