Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Redis Instance Info #790

Merged
merged 2 commits into from
Mar 30, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion newrelic/hooks/datastore_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def _conn_attrs_to_dict(connection):

def _instance_info(kwargs):
host = kwargs.get("host") or "localhost"
port_path_or_id = str(kwargs.get("port") or kwargs.get("path", "unknown"))
port_path_or_id = str(kwargs.get("path") or kwargs.get("port", "unknown"))
db = str(kwargs.get("db") or 0)

return (host, port_path_or_id, db)
Expand Down
18 changes: 2 additions & 16 deletions tests/datastore_redis/test_instance_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def test_strict_redis_connection_instance_info(args, kwargs, expected):
if (3, 5, 3) >= REDIS_PY_VERSION >= (2, 7, 5):
_instance_info_from_url_tests.append((("redis://127.0.0.1",), {}, ("127.0.0.1", "6379", "0")))


if REDIS_PY_VERSION >= (2, 10):
_instance_info_from_url_tests.extend(
[
Expand All @@ -116,13 +115,6 @@ def test_strict_redis_connection_instance_info(args, kwargs, expected):
]
)

if REDIS_PY_VERSION >= (4, 5, 2):
_instance_info_from_url_tests_4_5_2 = _instance_info_from_url_tests[:-3] + [
(("unix:///path/to/socket.sock",), {}, ("localhost", "6379", "0")),
(("unix:///path/to/socket.sock?db=2",), {}, ("localhost", "6379", "2")),
(("unix:///path/to/socket.sock",), {"db": 2}, ("localhost", "6379", "2")),
]


@pytest.mark.skipif(REDIS_PY_VERSION < (2, 6), reason="from_url not yet implemented in this redis-py version")
@pytest.mark.parametrize("args,kwargs,expected", _instance_info_from_url_tests)
Expand All @@ -141,10 +133,7 @@ def test_strict_redis_client_from_url(args, kwargs, expected):


@pytest.mark.skipif(REDIS_PY_VERSION < (2, 6), reason="from_url not yet implemented in this redis-py version")
@pytest.mark.parametrize(
"args,kwargs,expected",
_instance_info_from_url_tests if REDIS_PY_VERSION < (4, 5, 2) else _instance_info_from_url_tests_4_5_2,
)
@pytest.mark.parametrize("args,kwargs,expected", _instance_info_from_url_tests)
def test_redis_connection_from_url(args, kwargs, expected):
r = redis.Redis.from_url(*args, **kwargs)
if r.connection_pool.connection_class is redis.Connection:
Expand All @@ -164,10 +153,7 @@ def test_redis_connection_from_url(args, kwargs, expected):


@pytest.mark.skipif(REDIS_PY_VERSION < (2, 6), reason="from_url not yet implemented in this redis-py version")
@pytest.mark.parametrize(
"args,kwargs,expected",
_instance_info_from_url_tests if REDIS_PY_VERSION < (4, 5, 2) else _instance_info_from_url_tests_4_5_2,
)
@pytest.mark.parametrize("args,kwargs,expected", _instance_info_from_url_tests)
def test_strict_redis_connection_from_url(args, kwargs, expected):
r = redis.StrictRedis.from_url(*args, **kwargs)
if r.connection_pool.connection_class is redis.Connection:
Expand Down