Storing and retrieving data with Redis
Redis is a non-traditional database, dubbed a data structures 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 re-implement our quotes database with Redis.
Getting ready
We'll be using the node_redis
client.
npm install redis
We also need to install the Redis server, which can be downloaded from http://www.redis.io/download along with installation instructions.
Let's also create a new directory with a new quotes.js
file.
How to do it...
Let's create the redis
module, create a connection, and listen for the ready
event emitted by the redis client
, not forgetting to load the command-line arguments into the params
object.
var...