O'Reilly logo

Smashing Node.js: JavaScript Everywhere, 2nd Edition by Guillermo Rauch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14: Redis

Now that you have successfully leveraged two major databases with Node.JS—MongoDB and MySQL—it’s time learn about Redis.

Redis is a database, but it would be more accurately described as a datastructure server, a definition that resonates more with MongoDB than MySQL.

Instead of interacting with rows in tables or documents in collections, you always access data in Redis through keys. As a result, you can think of Redis as a key-value store like the following JavaScript object:

{

    ‘key’: ‘some value’

  , ‘key.2’: ‘some other value’

}

But because it’s a datastructure server, the value is not always a simple string. The following are the fundamental data types that you can assign to keys in Redis:

string

list

set

hash

sorted set

A fundamental difference between Redis and MongoDB, however, is that Redis document structure is always flat. Even though a key, for example, can contain something that resembles a JavaScript object very closely—a hash—that hash can’t contain nested data structures like it could in MongoDB.

Another fundamental difference is how you persist data. Redis is designed to be an extremely fast in-memory store with configurable persistence to disk. It’s important to remember persistence to disk matters because anything stored in memory is volatile and susceptible to be lost upon a system crash or reboot.

What this means is that Redis usage and configuration should be carefully reviewed prior to its deployment for sensitive information ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required