From 23f89c3da257213f61f0db569460dc422bdf1093 Mon Sep 17 00:00:00 2001 From: Jamie Gaskins Date: Tue, 20 Sep 2022 08:17:59 -0400 Subject: [PATCH 1/5] Add initial CI --- .github/workflows/crystal.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/crystal.yml diff --git a/.github/workflows/crystal.yml b/.github/workflows/crystal.yml new file mode 100644 index 0000000..c89c851 --- /dev/null +++ b/.github/workflows/crystal.yml @@ -0,0 +1,28 @@ +name: Crystal CI + +on: + - push + - pull_request + +jobs: + build: + + runs-on: ubuntu-latest + + container: + image: crystallang/crystal + + steps: + - uses: actions/checkout@v3 + - name: Docker Run Action + # You may pin to the exact commit or the version. + uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 + with: + # Image + image: redis/redis-stack-server + # Run command in container + run: redis-stack-server + - name: Install dependencies + run: shards install + - name: Run tests + run: crystal spec From 0818453e13c024508601bbb24b559dd9788a4043 Mon Sep 17 00:00:00 2001 From: Jamie Gaskins Date: Tue, 20 Sep 2022 18:32:39 -0400 Subject: [PATCH 2/5] Detach Redis server when running --- .github/workflows/crystal.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/crystal.yml b/.github/workflows/crystal.yml index c89c851..d185021 100644 --- a/.github/workflows/crystal.yml +++ b/.github/workflows/crystal.yml @@ -15,12 +15,10 @@ jobs: steps: - uses: actions/checkout@v3 - name: Docker Run Action - # You may pin to the exact commit or the version. uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 with: - # Image image: redis/redis-stack-server - # Run command in container + options: --detach run: redis-stack-server - name: Install dependencies run: shards install From 5ba09b295ac927ddfe9bb4adb279105f5c053ef2 Mon Sep 17 00:00:00 2001 From: Jamie Gaskins Date: Tue, 20 Sep 2022 18:37:29 -0400 Subject: [PATCH 3/5] Expose Redis port --- .github/workflows/crystal.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/crystal.yml b/.github/workflows/crystal.yml index d185021..e15d096 100644 --- a/.github/workflows/crystal.yml +++ b/.github/workflows/crystal.yml @@ -18,7 +18,7 @@ jobs: uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 with: image: redis/redis-stack-server - options: --detach + options: --detach -p 6379:6379 run: redis-stack-server - name: Install dependencies run: shards install From da1475afed516091a516ed1349cf07498477fcb9 Mon Sep 17 00:00:00 2001 From: Jamie Gaskins Date: Tue, 20 Sep 2022 18:42:51 -0400 Subject: [PATCH 4/5] Try the "services" option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I don't know why I didn't try this before 🙃 --- .github/workflows/crystal.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/crystal.yml b/.github/workflows/crystal.yml index e15d096..be23dd0 100644 --- a/.github/workflows/crystal.yml +++ b/.github/workflows/crystal.yml @@ -12,14 +12,18 @@ jobs: container: image: crystallang/crystal + services: + redis: + image: redis/redis-stack-server + # Set health checks to wait until redis has started + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - uses: actions/checkout@v3 - - name: Docker Run Action - uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 - with: - image: redis/redis-stack-server - options: --detach -p 6379:6379 - run: redis-stack-server - name: Install dependencies run: shards install - name: Run tests From 4c535f691cdb9485c331ddaf6053c4c0ad6da018 Mon Sep 17 00:00:00 2001 From: Jamie Gaskins Date: Tue, 20 Sep 2022 18:46:43 -0400 Subject: [PATCH 5/5] Default connection to REDIS_URL This is also what Cluster does, except it uses REDIS_CLUSTER_URL --- .github/workflows/crystal.yml | 2 ++ src/connection.cr | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/crystal.yml b/.github/workflows/crystal.yml index be23dd0..a7afcb8 100644 --- a/.github/workflows/crystal.yml +++ b/.github/workflows/crystal.yml @@ -28,3 +28,5 @@ jobs: run: shards install - name: Run tests run: crystal spec + env: + REDIS_URL: redis://redis/ diff --git a/src/connection.cr b/src/connection.cr index f40a8bc..e45577b 100644 --- a/src/connection.cr +++ b/src/connection.cr @@ -21,7 +21,7 @@ module Redis # SSL connections require specifying the `rediss://` scheme. # Password authentication uses the URI password. # DB selection uses the URI path. - def initialize(@uri = URI.parse("redis:///")) + def initialize(@uri = URI.parse(ENV.fetch("REDIS_URL", "redis:///"))) host = uri.host.presence || "localhost" port = uri.port || 6379 socket = TCPSocket.new(host, port)