Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions redis/_parsers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ def parse_sentinel_state(item):
return result


def parse_sentinel_master(response):
def parse_sentinel_master(response, **options):
return parse_sentinel_state(map(str_if_bytes, response))


def parse_sentinel_state_resp3(response):
def parse_sentinel_state_resp3(response, **options):
result = {}
for key in response:
try:
Expand All @@ -154,27 +154,27 @@ def parse_sentinel_state_resp3(response):
return result


def parse_sentinel_masters(response):
def parse_sentinel_masters(response, **options):
result = {}
for item in response:
state = parse_sentinel_state(map(str_if_bytes, item))
result[state["name"]] = state
return result


def parse_sentinel_masters_resp3(response):
return [parse_sentinel_state(master) for master in response]
def parse_sentinel_masters_resp3(response, **options):
return [parse_sentinel_state_resp3(master) for master in response]


def parse_sentinel_slaves_and_sentinels(response):
def parse_sentinel_slaves_and_sentinels(response, **options):
return [parse_sentinel_state(map(str_if_bytes, item)) for item in response]


def parse_sentinel_slaves_and_sentinels_resp3(response):
return [parse_sentinel_state_resp3(item) for item in response]
def parse_sentinel_slaves_and_sentinels_resp3(response, **options):
return [parse_sentinel_state_resp3(item, **options) for item in response]


def parse_sentinel_get_master(response):
def parse_sentinel_get_master(response, **options):
return response and (response[0], int(response[1])) or None


Expand Down
33 changes: 33 additions & 0 deletions tests/test_asyncio/test_sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import pytest
import pytest_asyncio
from redis.asyncio.client import StrictRedis

import redis.asyncio.sentinel
from redis import exceptions
from redis.asyncio.sentinel import (
Expand All @@ -11,6 +13,7 @@
SentinelConnectionPool,
SlaveNotFoundError,
)
from tests.conftest import is_resp2_connection


@pytest_asyncio.fixture(scope="module", loop_scope="module")
Expand Down Expand Up @@ -363,3 +366,33 @@ async def test_redis_master_usage(deployed_sentinel):
r = await deployed_sentinel.master_for("redis-py-test", db=0)
await r.set("foo", "bar")
assert (await r.get("foo")) == "bar"


@pytest.mark.onlynoncluster
async def test_sentinel_commands_with_strict_redis_client(request):
sentinel_ips = request.config.getoption("--sentinels")
sentinel_host, sentinel_port = sentinel_ips.split(",")[0].split(":")
protocol = request.config.getoption("--protocol", 2)

client = StrictRedis(
host=sentinel_host, port=sentinel_port, decode_responses=True, protocol=protocol
)
# skipping commands that change the state of the sentinel setup
assert isinstance(
await client.sentinel_get_master_addr_by_name("redis-py-test"), tuple
)
assert isinstance(await client.sentinel_master("redis-py-test"), dict)
if is_resp2_connection(client):
assert isinstance(await client.sentinel_masters(), dict)
else:
masters = await client.sentinel_masters()
assert isinstance(masters, list)
for master in masters:
assert isinstance(master, dict)

assert isinstance(await client.sentinel_sentinels("redis-py-test"), list)
assert isinstance(await client.sentinel_slaves("redis-py-test"), list)

assert isinstance(await client.sentinel_ckquorum("redis-py-test"), bool)

await client.close()
31 changes: 31 additions & 0 deletions tests/test_sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from unittest import mock

import pytest
from redis.client import StrictRedis

import redis.sentinel
from redis import exceptions
from redis.sentinel import (
Expand All @@ -10,6 +12,7 @@
SentinelConnectionPool,
SlaveNotFoundError,
)
from tests.conftest import is_resp2_connection


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -342,3 +345,31 @@ def test_redis_master_usage(deployed_sentinel):
r = deployed_sentinel.master_for("redis-py-test", db=0)
r.set("foo", "bar")
assert r.get("foo") == "bar"


@pytest.mark.onlynoncluster
def test_sentinel_commands_with_strict_redis_client(request):
sentinel_ips = request.config.getoption("--sentinels")
sentinel_host, sentinel_port = sentinel_ips.split(",")[0].split(":")
protocol = request.config.getoption("--protocol", 2)

client = StrictRedis(
host=sentinel_host, port=sentinel_port, decode_responses=True, protocol=protocol
)
# skipping commands that change the state of the sentinel setup
assert isinstance(client.sentinel_get_master_addr_by_name("redis-py-test"), tuple)
assert isinstance(client.sentinel_master("redis-py-test"), dict)
if is_resp2_connection(client):
assert isinstance(client.sentinel_masters(), dict)
else:
masters = client.sentinel_masters()
assert isinstance(masters, list)
for master in masters:
assert isinstance(master, dict)

assert isinstance(client.sentinel_sentinels("redis-py-test"), list)
assert isinstance(client.sentinel_slaves("redis-py-test"), list)

assert isinstance(client.sentinel_ckquorum("redis-py-test"), bool)

client.close()