Create a pymemcache client with optional retry support. Args: servers: List of server addresses **kwargs: Additional options including: - retry_attempts: Number of retry attempts (enables RetryingClient) - retry_delay: Delay between re
(servers=None, **kwargs)
| 58 | raise ImproperlyConfigured(REQUIRES_BACKEND) |
| 59 | |
| 60 | def ClientFactory(servers=None, **kwargs): |
| 61 | """Create a pymemcache client with optional retry support. |
| 62 | |
| 63 | Args: |
| 64 | servers: List of server addresses |
| 65 | **kwargs: Additional options including: |
| 66 | - retry_attempts: Number of retry attempts (enables RetryingClient) |
| 67 | - retry_delay: Delay between retries in seconds |
| 68 | - retry_for: List of exceptions to retry for |
| 69 | - do_not_retry_for: List of exceptions to not retry for |
| 70 | - behaviors, binary: Ignored for backward compatibility |
| 71 | with pylibmc |
| 72 | """ |
| 73 | # Remove pylibmc-specific options for backward compatibility |
| 74 | for option in PYLIBMC_ONLY_OPTIONS: |
| 75 | if option in kwargs: |
| 76 | kwargs.pop(option) |
| 77 | deprecated.warn( |
| 78 | description=f'The {option!r} cache backend option', |
| 79 | removal='6.0', |
| 80 | alternative='It is only supported by pylibmc and is ignored.', |
| 81 | stacklevel=3, |
| 82 | ) |
| 83 | kwargs = {**DEFAULT_CLIENT_OPTIONS, **kwargs} |
| 84 | |
| 85 | # Extract retry-related options |
| 86 | retry_attempts = kwargs.pop('retry_attempts', None) |
| 87 | retry_delay = kwargs.pop('retry_delay', None) |
| 88 | retry_for = kwargs.pop('retry_for', None) |
| 89 | do_not_retry_for = kwargs.pop('do_not_retry_for', None) |
| 90 | |
| 91 | # Normalize/validate servers (CacheBackend passes a list, but guard other callers) |
| 92 | if servers is None: |
| 93 | servers = [] |
| 94 | elif isinstance(servers, str): |
| 95 | servers = [servers] |
| 96 | elif ( |
| 97 | isinstance(servers, tuple) |
| 98 | and len(servers) == 2 |
| 99 | and isinstance(servers[0], str) |
| 100 | and isinstance(servers[1], int) |
| 101 | ): |
| 102 | # Allow passing a single server address as (host, port) |
| 103 | servers = [servers] |
| 104 | elif not isinstance(servers, (list, tuple)): |
| 105 | raise ImproperlyConfigured( |
| 106 | f"Memcache servers must be a sequence of server addresses, got {type(servers)}: {servers!r}" |
| 107 | ) |
| 108 | |
| 109 | # Filter out empty entries (e.g. memcache:// or trailing ';') |
| 110 | servers = [s for s in servers if s] |
| 111 | if not servers: |
| 112 | raise ImproperlyConfigured("No memcache servers provided") |
| 113 | |
| 114 | # Use HashClient for multiple servers, base Client for single server |
| 115 | if len(servers) > 1: |
| 116 | base_client = HashClient(servers, **kwargs) |
| 117 | else: |
nothing calls this directly
no test coverage detected