def __init__(self, server=None, serde=None, serializer=None, deserializer=None, connect_timeout=None, timeout=None, no_delay=False, ignore_exc=False, default_noreply=True, allow_unicode_keys=False, encoding='ascii'): self._contents = {} self.serde = serde or LegacyWrappingSerde(serializer, deserializer) self.allow_unicode_keys = allow_unicode_keys # Unused, but present for interface compatibility self.server = server self.connect_timeout = connect_timeout self.timeout = timeout self.no_delay = no_delay self.ignore_exc = ignore_exc self.encoding = encoding
def __init__(self, server, serde=None, serializer=None, deserializer=None, connect_timeout=None, timeout=None, no_delay=False, ignore_exc=False, socket_module=socket, key_prefix=b'', max_pool_size=None, lock_generator=None, default_noreply=True, allow_unicode_keys=False, encoding='ascii', tls_context=None): self.server = server self.serde = serde or LegacyWrappingSerde(serializer, deserializer) self.connect_timeout = connect_timeout self.timeout = timeout self.no_delay = no_delay self.ignore_exc = ignore_exc self.socket_module = socket_module self.default_noreply = default_noreply self.allow_unicode_keys = allow_unicode_keys if isinstance(key_prefix, six.text_type): key_prefix = key_prefix.encode('ascii') if not isinstance(key_prefix, bytes): raise TypeError("key_prefix should be bytes.") self.key_prefix = key_prefix self.client_pool = pool.ObjectPool( self._create_client, after_remove=lambda client: client.close(), max_size=max_pool_size, lock_generator=lock_generator) self.encoding = encoding self.tls_context = tls_context
def __init__(self, server, serde=None, serializer=None, deserializer=None, connect_timeout=None, timeout=None, no_delay=False, ignore_exc=False, socket_module=socket, key_prefix=b'', default_noreply=True, allow_unicode_keys=False, encoding='ascii', tls_context=None): """ Constructor. Args: server: tuple(hostname, port) or string containing a UNIX socket path. serde: optional seralizer object, see notes in the class docs. serializer: deprecated serialization function deserializer: deprecated deserialization function connect_timeout: optional float, seconds to wait for a connection to the memcached server. Defaults to "forever" (uses the underlying default socket timeout, which can be very long). timeout: optional float, seconds to wait for send or recv calls on the socket connected to memcached. Defaults to "forever" (uses the underlying default socket timeout, which can be very long). no_delay: optional bool, set the TCP_NODELAY flag, which may help with performance in some cases. Defaults to False. ignore_exc: optional bool, True to cause the "get", "gets", "get_many" and "gets_many" calls to treat any errors as cache misses. Defaults to False. socket_module: socket module to use, e.g. gevent.socket. Defaults to the standard library's socket module. key_prefix: Prefix of key. You can use this as namespace. Defaults to b''. default_noreply: bool, the default value for 'noreply' as passed to store commands (except from cas, incr, and decr, which default to False). allow_unicode_keys: bool, support unicode (utf8) keys encoding: optional str, controls data encoding (defaults to 'ascii'). Notes: The constructor does not make a connection to memcached. The first call to a method on the object will do that. """ self.server = server self.serde = serde or LegacyWrappingSerde(serializer, deserializer) self.connect_timeout = connect_timeout self.timeout = timeout self.no_delay = no_delay self.ignore_exc = ignore_exc self.socket_module = socket_module self.sock = None if isinstance(key_prefix, six.text_type): key_prefix = key_prefix.encode('ascii') if not isinstance(key_prefix, bytes): raise TypeError("key_prefix should be bytes.") self.key_prefix = key_prefix self.default_noreply = default_noreply self.allow_unicode_keys = allow_unicode_keys self.encoding = encoding self.tls_context = tls_context