|
1 | 1 | import functools |
2 | 2 | import hashlib |
| 3 | +import inspect |
3 | 4 | import itertools |
4 | 5 | import logging |
5 | 6 | import math |
@@ -2740,58 +2741,50 @@ def repr_pieces(self): |
2740 | 2741 |
|
2741 | 2742 |
|
2742 | 2743 | class FakeRedisMixin: |
2743 | | - def __init__(self, host='localhost', port=6379, |
2744 | | - db=0, password=None, socket_timeout=None, |
2745 | | - socket_connect_timeout=None, |
2746 | | - socket_keepalive=None, socket_keepalive_options=None, |
2747 | | - connection_pool=None, unix_socket_path=None, |
2748 | | - encoding='utf-8', encoding_errors='strict', |
2749 | | - charset=None, errors=None, |
2750 | | - decode_responses=False, retry_on_timeout=False, |
2751 | | - ssl=False, ssl_keyfile=None, ssl_certfile=None, |
2752 | | - ssl_cert_reqs=None, ssl_ca_certs=None, |
2753 | | - max_connections=None, server=None, |
2754 | | - connected=True): |
2755 | | - if not connection_pool: |
| 2744 | + def __init__(self, *args, server=None, connected=True, **kwargs): |
| 2745 | + # Interpret the positional and keyword arguments according to the |
| 2746 | + # version of redis in use. |
| 2747 | + sig = inspect.signature(redis.Redis) |
| 2748 | + bound = sig.bind(*args, **kwargs) |
| 2749 | + bound.apply_defaults() |
| 2750 | + if not bound.arguments['connection_pool']: |
| 2751 | + charset = bound.arguments['charset'] |
| 2752 | + errors = bound.arguments['errors'] |
2756 | 2753 | # Adapted from redis-py |
2757 | 2754 | if charset is not None: |
2758 | 2755 | warnings.warn(DeprecationWarning( |
2759 | 2756 | '"charset" is deprecated. Use "encoding" instead')) |
2760 | | - encoding = charset |
| 2757 | + bound.arguments['encoding'] = charset |
2761 | 2758 | if errors is not None: |
2762 | 2759 | warnings.warn(DeprecationWarning( |
2763 | 2760 | '"errors" is deprecated. Use "encoding_errors" instead')) |
2764 | | - encoding_errors = errors |
| 2761 | + bound.arguments['encoding_errors'] = errors |
2765 | 2762 |
|
2766 | 2763 | if server is None: |
2767 | 2764 | server = FakeServer() |
2768 | 2765 | server.connected = connected |
2769 | 2766 | kwargs = { |
2770 | | - 'db': db, |
2771 | | - 'password': password, |
2772 | | - 'encoding': encoding, |
2773 | | - 'encoding_errors': encoding_errors, |
2774 | | - 'decode_responses': decode_responses, |
2775 | | - 'max_connections': max_connections, |
2776 | 2767 | 'connection_class': FakeConnection, |
2777 | 2768 | 'server': server |
2778 | 2769 | } |
2779 | | - connection_pool = redis.connection.ConnectionPool(**kwargs) |
2780 | | - # These need to be passed by name due to |
2781 | | - # https://github.com/andymccurdy/redis-py/issues/1276 |
2782 | | - super().__init__( |
2783 | | - host=host, port=port, db=db, password=password, socket_timeout=socket_timeout, |
2784 | | - socket_connect_timeout=socket_connect_timeout, |
2785 | | - socket_keepalive=socket_keepalive, |
2786 | | - socket_keepalive_options=socket_keepalive_options, |
2787 | | - connection_pool=connection_pool, |
2788 | | - unix_socket_path=unix_socket_path, |
2789 | | - encoding=encoding, encoding_errors=encoding_errors, |
2790 | | - charset=charset, errors=errors, |
2791 | | - decode_responses=decode_responses, retry_on_timeout=retry_on_timeout, |
2792 | | - ssl=ssl, ssl_keyfile=ssl_keyfile, ssl_certfile=ssl_certfile, |
2793 | | - ssl_cert_reqs=ssl_cert_reqs, ssl_ca_certs=ssl_ca_certs, |
2794 | | - max_connections=max_connections) |
| 2770 | + conn_pool_args = [ |
| 2771 | + 'db', |
| 2772 | + 'username', |
| 2773 | + 'password', |
| 2774 | + 'socket_timeout', |
| 2775 | + 'encoding', |
| 2776 | + 'encoding_errors', |
| 2777 | + 'decode_responses', |
| 2778 | + 'retry_on_timeout', |
| 2779 | + 'max_connections', |
| 2780 | + 'health_check_interval', |
| 2781 | + 'client_name' |
| 2782 | + ] |
| 2783 | + for arg in conn_pool_args: |
| 2784 | + if arg in bound.arguments: |
| 2785 | + kwargs[arg] = bound.arguments[arg] |
| 2786 | + bound.arguments['connection_pool'] = redis.connection.ConnectionPool(**kwargs) |
| 2787 | + super().__init__(*bound.args, **bound.kwargs) |
2795 | 2788 |
|
2796 | 2789 | @classmethod |
2797 | 2790 | def from_url(cls, url, db=None, **kwargs): |
|
0 commit comments