From 16fbe9d99dbb1992e43d0e803a8c8f4d77795691 Mon Sep 17 00:00:00 2001 From: irvv17 Date: Fri, 14 Oct 2022 22:20:58 -0500 Subject: [PATCH 1/4] add: docker-compose.yml file * it will allow us to use redis/redis-stack: within a docker container --- docker-compose.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0340036 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.9" +services: + redis: + container_name: redis-caching-slow-database-queries + image: "redis/redis-stack:latest" + ports: + - 6379:6379 + - 8001:8001 + deploy: + restart_policy: + condition: on-failure From 578533118fd8c8a5420a71c9db2fe4ea98f7c9fe Mon Sep 17 00:00:00 2001 From: irvv17 Date: Fri, 14 Oct 2022 22:21:43 -0500 Subject: [PATCH 2/4] update docs about docker --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8bfc988..406d332 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Simple caching examples with Redis and Node.js! - SQLite - SQLite3 - Redis +- Docker (Optional) +- A Redis Stack database, or Redis with the RediSearch and RedisJSON modules installed. We've provided a docker-compose.yml for this. You can also sign up for a free 30Mb database with Redis Enterprise Cloud - be sure to check the Redis Stack option when creating your cloud database. ## Installing this application @@ -33,10 +35,15 @@ $ npm install Ensure you have Redis installed and running. -For Docker: +Start and run Redis in a Docker container: ```bash -$ docker run -p 6379:6379 --name redis6 -d redis:6 +$ docker-compose up -d +``` + +You can also run redis-cli in the container +```bash +$ docker exec -it redis-caching-slow-database-queries redis-cli ``` Ensure you have SQLite3 installed. From a950fcbdd254e1e8bb1bc547e7687b2632c429a1 Mon Sep 17 00:00:00 2001 From: irvv17 Date: Fri, 14 Oct 2022 23:43:28 -0500 Subject: [PATCH 3/4] update: docs --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 406d332..7c58dff 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,7 @@ Simple caching examples with Redis and Node.js! - SQLite - SQLite3 - Redis -- Docker (Optional) -- A Redis Stack database, or Redis with the RediSearch and RedisJSON modules installed. We've provided a docker-compose.yml for this. You can also sign up for a free 30Mb database with Redis Enterprise Cloud - be sure to check the Redis Stack option when creating your cloud database. +- Docker ## Installing this application @@ -35,7 +34,7 @@ $ npm install Ensure you have Redis installed and running. -Start and run Redis in a Docker container: +You can run it with Docker: ```bash $ docker-compose up -d @@ -46,6 +45,8 @@ You can also run redis-cli in the container $ docker exec -it redis-caching-slow-database-queries redis-cli ``` +You can also use redis-stack on your browser + Ensure you have SQLite3 installed. ### Unzip and import data to the SQLite `weather` table: From f36265fc14898e5eaece79c03063ac4780a30329 Mon Sep 17 00:00:00 2001 From: irvv17 Date: Fri, 14 Oct 2022 23:52:54 -0500 Subject: [PATCH 4/4] update docs: add notes --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7c58dff..6411747 100644 --- a/README.md +++ b/README.md @@ -44,10 +44,19 @@ You can also run redis-cli in the container ```bash $ docker exec -it redis-caching-slow-database-queries redis-cli ``` +> NOTE: If you're using Redis Enterprise Cloud, you'll need the hostname, port number, and password for your database. Use these to set the `REDIS_OM_URL` environment variable like this: -You can also use redis-stack on your browser +```bash +$ export REDIS_OM_URL=redis://default:@: +``` + +(**This step is not required when working with Docker as the Docker container** runs Redis on `localhost` port `6379` with no password, which is the default connection that Redis OM uses.) + +For example if your Redis Enterprise Cloud database is at port `9139` on host `enterprise.redis.com` and your password is `5uper53cret` then you'd set `REDIS_OM_URL` as follows: -Ensure you have SQLite3 installed. +> You can also use redis-stack on your browser + +> Ensure you have SQLite3 installed. ### Unzip and import data to the SQLite `weather` table: @@ -99,4 +108,9 @@ $ node average.js responseTime: '2ms' } ``` +## Shutting Down Redis (Docker) +If you're using Docker, and want to shut down the Redis container when you are finished with the application just use: +```bash +$ docker-compose down +```