class documentation

class MemCacheProtocol(LineReceiver, TimeoutMixin): (source)

View In Hierarchy

MemCache protocol: connect to a memcached server to store/retrieve values.
Method __init__ Create the protocol.
Method add Add the given key. It must not exist in the server.
Method append Append given data to the value of an existing key.
Method check​And​Set Change the content of key only if the cas value matches the current one associated with the key. Use this to store a value which hasn't been modified since last time you fetched it.
Method cmd_​CLIENT_​ERROR An invalid input as been sent.
Method cmd_​DELETED A delete command has completed successfully.
Method cmd_​END This the end token to a get or a stat operation.
Method cmd_​ERROR A non-existent command has been sent.
Method cmd_​EXISTS A checkAndSet update has failed.
Method cmd_​NOT_​FOUND Manage error response for incr/decr/delete.
Method cmd_​NOT_​STORED Manage a specific 'not stored' response to a set operation: this is not an error, but some condition wasn't met.
Method cmd_​OK The last command has been completed.
Method cmd_​SERVER_​ERROR An error has happened server-side.
Method cmd_​STAT Reception of one stat line.
Method cmd_​STORED Manage a success response to a set operation.
Method cmd_​VALUE Prepare the reading a value after a get.
Method cmd_​VERSION Read version token.
Method connection​Lost Cause any outstanding commands to fail.
Method decrement Decrement the value of key by given value (default to 1). key must be consistent with an int. Return the new value, coerced to 0 if negative.
Method delete Delete an existing key.
Method flush​All Flush all cached values.
Method get No summary
Method get​Multiple No summary
Method increment Increment the value of key by given value (default to 1). key must be consistent with an int. Return the new value.
Method line​Received Receive line commands from the server.
Method prepend Prepend given data to the value of an existing key.
Method raw​Data​Received Collect data for a get.
Method replace Replace the given key. It must already exist in the server.
Method send​Line Override sendLine to add a timeout to response.
Method set Set the given key.
Method stats Get some stats from the server. It will be available as a dict.
Method timeout​Connection Close the connection in case of timeout.
Method version Get the version of the server.
Constant MAX​_KEY​_LENGTH Undocumented
Instance Variable persistent​Time​Out the timeout period used to wait for a response.
Instance Variable time​Out Undocumented
Method _cancel​Commands Cancel all the outstanding commands, making them fail with reason.
Method _get Helper method for get and getMultiple.
Method _incrdecr Internal wrapper for incr/decr.
Method _set Internal wrapper for setting values.
Instance Variable _buffer​Length the total amount of bytes in _getBuffer.
Instance Variable _current current list of requests waiting for an answer from the server.
Instance Variable _disconnected indicate if the connectionLost has been called or not.
Instance Variable _get​Buffer current buffer of data, used to store temporary data when reading in raw mode.
Instance Variable _len​Expected amount of data expected in raw mode, when reading for a value.

Inherited from LineReceiver:

Method clear​Line​Buffer Clear buffered data.
Method data​Received Protocol.dataReceived. Translates bytes into lines, and calls lineReceived (or rawDataReceived, depending on mode.)
Method line​Length​Exceeded Called when the maximum line length has been reached. Override if it needs to be dealt with in some special way.
Method set​Line​Mode Sets the line-mode of this receiver.
Method set​Raw​Mode Sets the raw mode of this receiver. Further data received will be sent to rawDataReceived rather than lineReceived.
Constant MAX​_LENGTH The maximum length of a line to allow (If a sent line is longer than this, the connection is dropped). Default is 16384.
Class Variable delimiter The line-ending delimiter to use. By default this is b'\r\n'.
Instance Variable line​_mode Undocumented
Instance Variable _buffer Undocumented
Instance Variable _busy​Receiving Undocumented

Inherited from Protocol (via LineReceiver):

Method log​Prefix Return a prefix matching the class name, to identify log messages related to this protocol instance.
Class Variable factory Undocumented

Inherited from BaseProtocol (via LineReceiver, Protocol):

Method connection​Made Called when a connection is made.
Method make​Connection Make a connection to a transport and a server.
Instance Variable connected Undocumented
Instance Variable transport Undocumented

Inherited from _PauseableMixin (via LineReceiver):

Method pause​Producing Undocumented
Method resume​Producing Undocumented
Method stop​Producing Undocumented
Instance Variable paused Undocumented

Inherited from TimeoutMixin:

Method call​Later Wrapper around reactor.callLater for test purpose.
Method reset​Timeout Reset the timeout count down.
Method set​Timeout Change the timeout period
Method __timed​Out Undocumented
Instance Variable __timeout​Call Undocumented
def __init__(self, timeOut=60): (source)
Create the protocol.
Parameters
time​Out:intthe timeout to wait before detecting that the connection is dead and close it. It's expressed in seconds.
def add(self, key, val, flags=0, expireTime=0): (source)
Add the given key. It must not exist in the server.
Parameters
key:bytesthe key to add.
val:bytesthe value associated with the key.
flags:intthe flags to store with the key.
expire​Time:intif different from 0, the relative time in seconds when the key will be deleted from the store.
Returns
Deferreda deferred that will fire with True if the operation has succeeded, and False with the key already exists.
def append(self, key, val): (source)
Append given data to the value of an existing key.
Parameters
key:bytesThe key to modify.
val:bytesThe value to append to the current value associated with the key.
Returns
DeferredA deferred that will fire with True if the operation has succeeded, False otherwise.
def checkAndSet(self, key, val, cas, flags=0, expireTime=0): (source)
Change the content of key only if the cas value matches the current one associated with the key. Use this to store a value which hasn't been modified since last time you fetched it.
Parameters
key:bytesThe key to set.
val:bytesThe value associated with the key.
cas:bytesUnique 64-bit value returned by previous call of get.
flags:intThe flags to store with the key.
expire​Time:intIf different from 0, the relative time in seconds when the key will be deleted from the store.
Returns
DeferredA deferred that will fire with True if the operation has succeeded, False otherwise.
def cmd_CLIENT_ERROR(self, errText): (source)
An invalid input as been sent.
def cmd_DELETED(self): (source)
A delete command has completed successfully.
def cmd_END(self): (source)
This the end token to a get or a stat operation.
def cmd_ERROR(self): (source)
A non-existent command has been sent.
def cmd_EXISTS(self): (source)
A checkAndSet update has failed.
def cmd_NOT_FOUND(self): (source)
Manage error response for incr/decr/delete.
def cmd_NOT_STORED(self): (source)
Manage a specific 'not stored' response to a set operation: this is not an error, but some condition wasn't met.
def cmd_OK(self): (source)
The last command has been completed.
def cmd_SERVER_ERROR(self, errText): (source)
An error has happened server-side.
def cmd_STAT(self, line): (source)
Reception of one stat line.
def cmd_STORED(self): (source)
Manage a success response to a set operation.
def cmd_VALUE(self, line): (source)
Prepare the reading a value after a get.
def cmd_VERSION(self, versionData): (source)
Read version token.
def connectionLost(self, reason): (source)
def decrement(self, key, val=1): (source)
Decrement the value of key by given value (default to 1). key must be consistent with an int. Return the new value, coerced to 0 if negative.
Parameters
key:bytesthe key to modify.
val:intthe value to decrement.
Returns
Deferreda deferred with will be called back with the new value associated with the key (after the decrement).
def delete(self, key): (source)
Delete an existing key.
Parameters
key:bytesthe key to delete.
Returns
Deferreda deferred that will be called back with True if the key was successfully deleted, or False if not.
def flushAll(self): (source)
Flush all cached values.
Returns
Deferreda deferred that will be called back with True when the operation has succeeded.
def get(self, key, withIdentifier=False): (source)
Get the given key. It doesn't support multiple keys. If withIdentifier is set to True, the command issued is a gets, that will return the current identifier associated with the value. This identifier has to be used when issuing checkAndSet update later, using the corresponding method.
Parameters
key:bytesThe key to retrieve.
with​Identifier:boolIf set to True, retrieve the current identifier along with the value and the flags.
Returns
DeferredA deferred that will fire with the tuple (flags, value) if withIdentifier is False, or (flags, cas identifier, value) if True. If the server indicates there is no value associated with key, the returned value will be None and the returned flags will be 0.
def getMultiple(self, keys, withIdentifier=False): (source)
Get the given list of keys. If withIdentifier is set to True, the command issued is a gets, that will return the identifiers associated with each values. This identifier has to be used when issuing checkAndSet update later, using the corresponding method.
Parameters
keys:list of bytesThe keys to retrieve.
with​Identifier:boolIf set to True, retrieve the identifiers along with the values and the flags.
Returns
DeferredA deferred that will fire with a dictionary with the elements of keys as keys and the tuples (flags, value) as values if withIdentifier is False, or (flags, cas identifier, value) if True. If the server indicates there is no value associated with key, the returned values will be None and the returned flags will be 0.
Present Since
9.0
def increment(self, key, val=1): (source)
Increment the value of key by given value (default to 1). key must be consistent with an int. Return the new value.
Parameters
key:bytesthe key to modify.
val:intthe value to increment.
Returns
Deferreda deferred with will be called back with the new value associated with the key (after the increment).
def lineReceived(self, line): (source)
Receive line commands from the server.
def prepend(self, key, val): (source)
Prepend given data to the value of an existing key.
Parameters
key:bytesThe key to modify.
val:bytesThe value to prepend to the current value associated with the key.
Returns
DeferredA deferred that will fire with True if the operation has succeeded, False otherwise.
def rawDataReceived(self, data): (source)
Collect data for a get.
def replace(self, key, val, flags=0, expireTime=0): (source)
Replace the given key. It must already exist in the server.
Parameters
key:bytesthe key to replace.
val:bytesthe new value associated with the key.
flags:intthe flags to store with the key.
expire​Time:intif different from 0, the relative time in seconds when the key will be deleted from the store.
Returns
Deferreda deferred that will fire with True if the operation has succeeded, and False with the key didn't previously exist.
def sendLine(self, line): (source)
Override sendLine to add a timeout to response.
def set(self, key, val, flags=0, expireTime=0): (source)
Set the given key.
Parameters
key:bytesthe key to set.
val:bytesthe value associated with the key.
flags:intthe flags to store with the key.
expire​Time:intif different from 0, the relative time in seconds when the key will be deleted from the store.
Returns
Deferreda deferred that will fire with True if the operation has succeeded.
def stats(self, arg=None): (source)
Get some stats from the server. It will be available as a dict.
Parameters
arg:None or bytesAn optional additional string which will be sent along with the stats command. The interpretation of this value by the server is left undefined by the memcache protocol specification.
Returns
Deferreda deferred that will fire with a dict of the available statistics.
def timeoutConnection(self): (source)
Close the connection in case of timeout.
def version(self): (source)
Get the version of the server.
Returns
Deferreda deferred that will fire with the string value of the version.
MAX_KEY_LENGTH: int = (source)

Undocumented

Value
250
persistentTimeOut: int = (source)
the timeout period used to wait for a response.
def _cancelCommands(self, reason): (source)
Cancel all the outstanding commands, making them fail with reason.
def _get(self, keys, withIdentifier, multiple): (source)
Helper method for get and getMultiple.
def _incrdecr(self, cmd, key, val): (source)
Internal wrapper for incr/decr.
def _set(self, cmd, key, val, flags, expireTime, cas): (source)
Internal wrapper for setting values.
_bufferLength: int = (source)
the total amount of bytes in _getBuffer.
_current: deque of Command = (source)
current list of requests waiting for an answer from the server.
_disconnected: bool = (source)
indicate if the connectionLost has been called or not.
_getBuffer: list = (source)
current buffer of data, used to store temporary data when reading in raw mode.
_lenExpected: int = (source)
amount of data expected in raw mode, when reading for a value.