Persisting data with Redis
Redis is an open source in-memory key-value data store. Used in the correct setting, Redis can be a fast-performing data store. It is often used to provide caching in applications, but can also be used as a database.
In this recipe, we're going to create a task list database using Redis.
Getting ready
- As with the previous databases in this chapter, we will use Docker to provision a Redis database using the following command:
$ docker run --publish 6379:6379 --name node-redis --detach redis
By default, the containerized Redis database will be available at
localhost:6379
. - We will also create a new folder named
redis-app
containing a file namedtasks.js
:$ mkdir redis-app $ cd redis-app $ touch tasks.js
- In this recipe, we will be making use of third-party
npm
modules; therefore, we need to initialize our project:$ npm init --yes
Now that we have Redis running and our project set up, we're ready to move on to the recipe.
...