MCPcopy Create free account
hub / github.com/celery/celery / get_memcache_client

Function get_memcache_client

celery/backends/cache.py:51–139  ·  view source on GitHub ↗

Get pymemcache client factory.

()

Source from the content-addressed store, hash-verified

49
50
51def get_memcache_client():
52 """Get pymemcache client factory."""
53 try:
54 from pymemcache.client.base import Client
55 from pymemcache.client.hash import HashClient
56 from pymemcache.client.retrying import RetryingClient
57 except ImportError:
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

Callers 1

get_best_memcacheFunction · 0.85

Calls 1

Tested by

no test coverage detected