From 88329f305478a097e310e9421a31e48f6d8d4a47 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Mon, 1 Jan 2024 16:34:31 +0200 Subject: [PATCH] Fix redis 6.2.14 installation --- .../install-redis-modules/action.yml | 2 +- .github/workflows/install-redis/action.yml | 17 ++-- node/tests/RedisClusterClient.test.ts | 11 ++- node/tests/SharedTests.ts | 80 +++++++++++++------ node/tests/TestUtilities.ts | 5 +- python/python/tests/test_async_client.py | 51 +++++++----- utils/cluster_manager.py | 1 - 7 files changed, 109 insertions(+), 58 deletions(-) diff --git a/.github/workflows/install-redis-modules/action.yml b/.github/workflows/install-redis-modules/action.yml index e14df66..afbdb63 100644 --- a/.github/workflows/install-redis-modules/action.yml +++ b/.github/workflows/install-redis-modules/action.yml @@ -84,7 +84,7 @@ runs: with: repository: "RedisJSON/RedisJSON" path: "./redisjson" - ref: ${{ startsWith(inputs.redis-version, '6') && '2.6' || '' }} + ref: ${{ startsWith(inputs.redis-version, '6') && 'v2.6.0' || '' }} submodules: recursive - name: Build RedisJSON diff --git a/.github/workflows/install-redis/action.yml b/.github/workflows/install-redis/action.yml index 47b41ec..f4a7491 100644 --- a/.github/workflows/install-redis/action.yml +++ b/.github/workflows/install-redis/action.yml @@ -13,7 +13,7 @@ runs: using: "composite" steps: - - run: mkdir ~/redis-binaries + - run: mkdir -p ~/redis-binaries/${{ inputs.redis-version }} shell: bash - uses: actions/checkout@v4 @@ -24,9 +24,9 @@ runs: id: cache-redis with: path: | - ~/redis-binaries/redis-cli - ~/redis-binaries/redis-server - key: ${{ runner.os }}-install-redis + ~/redis-binaries/${{ inputs.redis-version }}/redis-cli + ~/redis-binaries/${{ inputs.redis-version }}/redis-server + key: ${{ runner.os }}-${{ inputs.redis-version }}-install-redis - name: Install redis shell: bash @@ -35,8 +35,13 @@ runs: sudo apt-get update wget https://github.com/redis/redis/archive/${{ inputs.redis-version }}.tar.gz; tar -xzvf ${{ inputs.redis-version }}.tar.gz; - pushd redis-${{ inputs.redis-version }} && BUILD_TLS=yes make && sudo mv src/redis-server src/redis-cli ~/redis-binaries && popd; + pushd redis-${{ inputs.redis-version }} && BUILD_TLS=yes make && sudo mv src/redis-server src/redis-cli ~/redis-binaries/${{ inputs.redis-version }} && popd; + + - name: Remove the source package + shell: bash + if: steps.cache-redis.outputs.cache-hit != 'true' + run: sudo rm -r redis-${{ inputs.redis-version }} - name: Copy executable to place shell: bash - run: sudo cp ~/redis-binaries/redis-server ~/redis-binaries/redis-cli /usr/bin/ + run: sudo cp ~/redis-binaries/${{ inputs.redis-version }}/redis-server ~/redis-binaries/${{ inputs.redis-version }}/redis-cli /usr/bin/ diff --git a/node/tests/RedisClusterClient.test.ts b/node/tests/RedisClusterClient.test.ts index 1d77070..73d156c 100644 --- a/node/tests/RedisClusterClient.test.ts +++ b/node/tests/RedisClusterClient.test.ts @@ -15,7 +15,7 @@ import { RedisClusterClient, } from "../"; import { runBaseTests } from "./SharedTests"; -import { flushallOnPort, transactionTest } from "./TestUtilities"; +import { flushallOnPort, getFirstResult, transactionTest } from "./TestUtilities"; type Context = { client: RedisClusterClient; @@ -152,8 +152,12 @@ describe("RedisClusterClient", () => { const client = await RedisClusterClient.createClient( getOptions(cluster.ports()) ); - const result = (await client.info([ + const info_server = getFirstResult(await client.info([ InfoOptions.Server, + ])); + expect(info_server).toEqual(expect.stringContaining("# Server")); + + const result = (await client.info([ InfoOptions.Replication, ])) as Record; const clusterNodes = await client.customCommand([ @@ -164,7 +168,6 @@ describe("RedisClusterClient", () => { (clusterNodes as string)?.split("master").length - 1 ).toEqual(Object.keys(result).length); Object.values(result).every((item) => { - expect(item).toEqual(expect.stringContaining("# Server")); expect(item).toEqual(expect.stringContaining("# Replication")); expect(item).toEqual( expect.not.stringContaining("# Errorstats") @@ -217,7 +220,7 @@ describe("RedisClusterClient", () => { ); const transaction = new ClusterTransaction(); const expectedRes = transactionTest(transaction); - const result = await client.exec(transaction); + const result = await client.exec(transaction) expect(result).toEqual(expectedRes); client.close(); }, diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 1d90a60..172cbe8 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -1013,18 +1013,37 @@ export function runBaseTests(config: { expect(await client.ttl(key)).toBeLessThanOrEqual(10); /// set command clears the timeout. expect(await client.set(key, "bar")).toEqual("OK"); - expect( - await client.pexpire(key, 10000, ExpireOptions.HasNoExpiry) - ).toEqual(true); + const version = await getVersion(); + if (version[0] < 7 ) { + expect( + await client.pexpire(key, 10000) + ).toEqual(true); + } + else { + expect( + await client.pexpire(key, 10000, ExpireOptions.HasNoExpiry) + ).toEqual(true); + } + expect(await client.ttl(key)).toBeLessThanOrEqual(10); /// TTL will be updated to the new value = 15 - expect( - await client.expire( - key, - 15, - ExpireOptions.HasExistingExpiry - ) - ).toEqual(true); + if (version[0] < 7 ) { + expect( + await client.expire( + key, + 15 + ) + ).toEqual(true); + } + else { + expect( + await client.expire( + key, + 15, + ExpireOptions.HasExistingExpiry + ) + ).toEqual(true); + } expect(await client.ttl(key)).toBeLessThanOrEqual(15); }); }, @@ -1044,24 +1063,37 @@ export function runBaseTests(config: { ) ).toEqual(true); expect(await client.ttl(key)).toBeLessThanOrEqual(10); - expect( - await client.expireAt( - key, - Math.floor(Date.now() / 1000) + 50, - ExpireOptions.NewExpiryGreaterThanCurrent - ) - ).toEqual(true); + const version = await getVersion(); + if (version[0] < 7 ) { + expect( + await client.expireAt( + key, + Math.floor(Date.now() / 1000) + 50 + ) + ).toEqual(true); + } + else{ + expect( + await client.expireAt( + key, + Math.floor(Date.now() / 1000) + 50, + ExpireOptions.NewExpiryGreaterThanCurrent + ) + ).toEqual(true); + } expect(await client.ttl(key)).toBeLessThanOrEqual(50); /// set command clears the timeout. expect(await client.set(key, "bar")).toEqual("OK"); - expect( - await client.pexpireAt( - key, - Date.now() + 50000, - ExpireOptions.HasExistingExpiry - ) - ).toEqual(false); + if (version[0] >= 7) { + expect( + await client.pexpireAt( + key, + Date.now() + 50000, + ExpireOptions.HasExistingExpiry + ) + ).toEqual(false); + } }); }, config.timeout diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index d647aaf..2e4a33e 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -60,9 +60,8 @@ export function transactionTest( const value = uuidv4(); baseTransaction.set(key1, "bar"); baseTransaction.set(key2, "baz", { - conditionalSet: "onlyIfDoesNotExist", - returnOldValue: true, - }); + returnOldValue:true + }); baseTransaction.customCommand(["MGET", key1, key2]); baseTransaction.mset({ [key3]: value }); baseTransaction.mget([key1, key2]); diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 5c87b76..74f8ed7 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -354,14 +354,14 @@ async def test_request_error_raises_exception(self, redis_client: TRedisClient): @pytest.mark.parametrize("cluster_mode", [True, False]) async def test_info_server_replication(self, redis_client: TRedisClient): - sections = [InfoSection.SERVER, InfoSection.REPLICATION] - info = get_first_result(await redis_client.info(sections)) + info = get_first_result(await redis_client.info([InfoSection.SERVER])) assert "# Server" in info - assert "# Replication" in info - assert "# Errorstats" not in info cluster_mode = parse_info_response(info)["redis_mode"] expected_cluster_mode = isinstance(redis_client, RedisClusterClient) assert cluster_mode == "cluster" if expected_cluster_mode else "standalone" + info = get_first_result(await redis_client.info([InfoSection.REPLICATION])) + assert "# Replication" in info + assert "# Errorstats" not in info @pytest.mark.parametrize("cluster_mode", [True, False]) async def test_info_default(self, redis_client: TRedisClient): @@ -853,12 +853,22 @@ async def test_expire_pexpire_ttl_with_positive_timeout( # set command clears the timeout. assert await redis_client.set(key, "bar") == OK - assert await redis_client.pexpire(key, 10000, ExpireOptions.HasNoExpiry) == True + if await check_if_server_version_lt(redis_client, "7.0.0"): + assert await redis_client.pexpire(key, 10000) == True + else: + assert ( + await redis_client.pexpire(key, 10000, ExpireOptions.HasNoExpiry) + == True + ) assert await redis_client.ttl(key) in range(11) - assert ( - await redis_client.expire(key, 15, ExpireOptions.HasExistingExpiry) == True - ) + if await check_if_server_version_lt(redis_client, "7.0.0"): + assert await redis_client.expire(key, 15) == True + else: + assert ( + await redis_client.expire(key, 15, ExpireOptions.HasExistingExpiry) + == True + ) assert await redis_client.ttl(key) in range(16) @pytest.mark.parametrize("cluster_mode", [True, False]) @@ -871,24 +881,27 @@ async def test_expireat_pexpireat_ttl_with_positive_timeout( assert await redis_client.expireat(key, current_time + 10) == 1 assert await redis_client.ttl(key) in range(11) - - assert ( - await redis_client.expireat( - key, current_time + 50, ExpireOptions.NewExpiryGreaterThanCurrent + if await check_if_server_version_lt(redis_client, "7.0.0"): + assert await redis_client.expireat(key, current_time + 50) == 1 + else: + assert ( + await redis_client.expireat( + key, current_time + 50, ExpireOptions.NewExpiryGreaterThanCurrent + ) + == 1 ) - == 1 - ) assert await redis_client.ttl(key) in range(51) # set command clears the timeout. assert await redis_client.set(key, "bar") == OK current_time_ms = int(time.time() * 1000) - assert ( - await redis_client.pexpireat( - key, current_time_ms + 50000, ExpireOptions.HasExistingExpiry + if not check_if_server_version_lt(redis_client, "7.0.0"): + assert ( + await redis_client.pexpireat( + key, current_time_ms + 50000, ExpireOptions.HasExistingExpiry + ) + == False ) - == False - ) @pytest.mark.parametrize("cluster_mode", [True, False]) async def test_expire_pexpire_expireat_pexpireat_past_or_negative_timeout( diff --git a/utils/cluster_manager.py b/utils/cluster_manager.py index d34e889..0d397cd 100644 --- a/utils/cluster_manager.py +++ b/utils/cluster_manager.py @@ -297,7 +297,6 @@ def start_redis_server( raise ValueError( "Please provide the path(s) to the module(s) you want to load." ) - cmd_args.extend(["--enable-module-command", "yes"]) for module_path in load_module: cmd_args.extend(["--loadmodule", module_path]) cmd_args += tls_args