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 #2581 UnixDomainSocketConnection' object has no attribute '_command_packer' #2583

Merged
merged 3 commits into from
Feb 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ def __init__(
retry=None,
redis_connect_func=None,
credential_provider: Optional[CredentialProvider] = None,
command_packer=None,
):
"""
Initialize a new UnixDomainSocketConnection.
Expand Down Expand Up @@ -1202,6 +1203,7 @@ def __init__(
self.set_parser(parser_class)
self._connect_callbacks = []
self._buffer_cutoff = 6000
self._command_packer = self._construct_command_packer(command_packer)

def repr_pieces(self):
pieces = [("path", self.path), ("db", self.db)]
Expand Down
44 changes: 43 additions & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

import redis
from redis.backoff import NoBackoff
from redis.connection import Connection, HiredisParser, PythonParser
from redis.connection import (
Connection,
HiredisParser,
PythonParser,
SSLConnection,
UnixDomainSocketConnection,
)
from redis.exceptions import ConnectionError, InvalidResponse, TimeoutError
from redis.retry import Retry
from redis.utils import HIREDIS_AVAILABLE
Expand Down Expand Up @@ -163,3 +169,39 @@ def test_connection_parse_response_resume(r: redis.Redis, parser_class):
pytest.fail("didn't receive a response")
assert response
assert i > 0


@pytest.mark.onlynoncluster
@pytest.mark.parametrize(
"Class",
[
Connection,
SSLConnection,
UnixDomainSocketConnection,
],
)
def test_pack_command(Class):
"""
This test verifies that the pack_command works
on all supported connections. #2581
"""
cmd = (
"HSET",
"foo",
"key",
"value1",
b"key_b",
b"bytes str",
b"key_i",
67,
"key_f",
3.14159265359,
)
expected = (
b"*10\r\n$4\r\nHSET\r\n$3\r\nfoo\r\n$3\r\nkey\r\n$6\r\nvalue1\r\n"
b"$5\r\nkey_b\r\n$9\r\nbytes str\r\n$5\r\nkey_i\r\n$2\r\n67\r\n$5"
b"\r\nkey_f\r\n$13\r\n3.14159265359\r\n"
)

actual = Class().pack_command(*cmd)[0]
assert actual == expected, f"actual = {actual}, expected = {expected}"