Storing and retrieving data with Redis
Redis is a nontraditional database, dubbed a data structure server, which functions in operational memory with blazingly fast performance.
Redis is excellent for certain tasks, as long as the data model is fairly simple and isn't so large that it swamps your server RAM. Good examples of where Redis shines are in site analytics, server-side session cookies, and providing a list of logged-in users in real time.
In the spirit of our theme, we will reimplement our quotes
database with Redis.
Getting ready
We'll be using the redis
module:
npm install redis
We also need to install the Redis server, which can be downloaded from http://www.redis.io/download along with the installation instructions.
Let's also create a new directory with a new quotes.js
file.
How to do it…
We'll create the redis
module, establish a connection, and listen for the ready
event emitted by the client
, without forgetting to load the command-line arguments into the params
object.
var redis...