From 7b542693c08da721a619443c6c06e1d48fb828e0 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 28 Jan 2025 15:36:30 +0100 Subject: [PATCH] ci: test with Valkey --- .github/workflows/ci.yml | 10 ++++++++++ compose.yaml | 5 +++++ package.json | 5 +++-- test/util.ts | 11 +++++++---- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b88b958..73015cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,16 @@ jobs: --health-retries 5 ports: - "7000-7005:7000-7005" + valkey: + image: valkey/valkey:8 + options: >- + --health-cmd "valkey-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 6389:6379 + steps: - name: Checkout repository uses: actions/checkout@v4 diff --git a/compose.yaml b/compose.yaml index e0b0417..38beb48 100644 --- a/compose.yaml +++ b/compose.yaml @@ -8,3 +8,8 @@ services: image: grokzen/redis-cluster:7.0.10 ports: - "7000-7005:7000-7005" + + valkey: + image: valkey/valkey:8 + ports: + - "6389:6379" diff --git a/package.json b/package.json index 71e832f..9847373 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,12 @@ "format:check": "prettier --parser typescript --check \"lib/**/*.ts\" \"test/**/*.ts\"", "format:fix": "prettier --parser typescript --write \"lib/**/*.ts\" \"test/**/*.ts\"", "prepack": "npm run compile", - "test": "npm run format:check && npm run compile && npm run test:redis-standalone && npm run test:redis-cluster && npm run test:ioredis-standalone && npm run test:ioredis-cluster", + "test": "npm run format:check && npm run compile && npm run test:redis-standalone && npm run test:redis-cluster && npm run test:ioredis-standalone && npm run test:ioredis-cluster && npm run test:valkey-standalone", "test:redis-standalone": "nyc mocha --require ts-node/register test/**/*.ts", "test:redis-cluster": "cross-env REDIS_CLUSTER=1 mocha --require ts-node/register test/**/*.ts", "test:ioredis-standalone": "cross-env REDIS_LIB=ioredis mocha --require ts-node/register test/**/*.ts", - "test:ioredis-cluster": "cross-env REDIS_LIB=ioredis REDIS_CLUSTER=1 mocha --require ts-node/register test/**/*.ts" + "test:ioredis-cluster": "cross-env REDIS_LIB=ioredis REDIS_CLUSTER=1 mocha --require ts-node/register test/**/*.ts", + "test:valkey-standalone": "cross-env VALKEY=1 mocha --require ts-node/register test/**/*.ts" }, "prettier": { "endOfLine": "auto" diff --git a/test/util.ts b/test/util.ts index c552596..fac8cc8 100644 --- a/test/util.ts +++ b/test/util.ts @@ -43,8 +43,8 @@ const lib = process.env.REDIS_LIB || "redis"; console.log(`[INFO] testing in ${mode} mode with ${lib}`); async function initRedisClient() { - if (process.env.REDIS_CLUSTER === "1") { - if (process.env.REDIS_LIB === "ioredis") { + if (mode === "cluster") { + if (lib === "ioredis") { return new Cluster([ { host: "localhost", @@ -100,10 +100,13 @@ async function initRedisClient() { return redisClient; } } else { - if (process.env.REDIS_LIB === "ioredis") { + if (lib === "ioredis") { return new Redis(); } else { - const redisClient = createClient(); + const port = process.env.VALKEY === "1" ? 6389 : 6379; + const redisClient = createClient({ + url: `redis://localhost:${port}`, + }); await redisClient.connect(); return redisClient;