class documentation

class twisted.protocols.memcache.MemCacheProtocol(LineReceiver, TimeoutMixin): (source)

View In Hierarchy

MemCache protocol: connect to a memcached server to store/retrieve values.

Instance Variable persistentTimeOut the timeout period used to wait for a response.
Class Variable MAX_KEY_LENGTH Undocumented
Method __init__ Create the protocol.
Instance Variable timeOut Undocumented
Method timeoutConnection Close the connection in case of timeout.
Method connectionLost Cause any outstanding commands to fail.
Method sendLine Override sendLine to add a timeout to response.
Method rawDataReceived Collect data for a get.
Method cmd_STORED Manage a success response to a set operation.
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_END This the end token to a get or a stat operation.
Method cmd_NOT_FOUND Manage error response for incr/decr/delete.
Method cmd_VALUE Prepare the reading a value after a get.
Method cmd_STAT Reception of one stat line.
Method cmd_VERSION Read version token.
Method cmd_ERROR A non-existent command has been sent.
Method cmd_CLIENT_ERROR An invalid input as been sent.
Method cmd_SERVER_ERROR An error has happened server-side.
Method cmd_DELETED A delete command has completed successfully.
Method cmd_OK The last command has been completed.
Method cmd_EXISTS A checkAndSet update has failed.
Method lineReceived Receive line commands from the server.
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 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 replace Replace the given key. It must already exist in the server.
Method add Add the given key. It must not exist in the server.
Method set Set the given key.
Method checkAndSet 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 append Append given data to the value of an existing key.
Method prepend Prepend given data to the value of an existing key.
Method get No summary
Method getMultiple No summary
Method stats Get some stats from the server. It will be available as a dict.
Method version Get the version of the server.
Method delete Delete an existing key.
Method flushAll Flush all cached values.
Instance Variable _current current list of requests waiting for an answer from the server.
Instance Variable _lenExpected amount of data expected in raw mode, when reading for a value.
Instance Variable _getBuffer current buffer of data, used to store temporary data when reading in raw mode.
Instance Variable _bufferLength the total amount of bytes in _getBuffer.
Instance Variable _disconnected indicate if the connectionLost has been called or not.
Method _cancelCommands Cancel all the outstanding commands, making them fail with reason.
Method _incrdecr Internal wrapper for incr/decr.
Method _set Internal wrapper for setting values.
Method _get Helper method for get and getMultiple.

Inherited from LineReceiver:

Class Variable delimiter The line-ending delimiter to use. By default this is b'\r\n'.
Class Variable 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.
Instance Variable line_mode Undocumented
Method clearLineBuffer Clear buffered data.
Method dataReceived Protocol.dataReceived. Translates bytes into lines, and calls lineReceived (or rawDataReceived, depending on mode.)
Method setLineMode Sets the line-mode of this receiver.
Method setRawMode Sets the raw mode of this receiver. Further data received will be sent to rawDataReceived rather than lineReceived.
Method lineLengthExceeded Called when the maximum line length has been reached. Override if it needs to be dealt with in some special way.
Instance Variable _buffer Undocumented
Instance Variable _busyReceiving Undocumented

Inherited from Protocol (via LineReceiver):

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

Inherited from BaseProtocol (via LineReceiver, Protocol):

Instance Variable connected Undocumented
Instance Variable transport Undocumented
Method makeConnection Make a connection to a transport and a server.
Method connectionMade Called when a connection is made.

Inherited from _PauseableMixin (via LineReceiver):

Instance Variable paused Undocumented
Method pauseProducing Undocumented
Method resumeProducing Undocumented
Method stopProducing Undocumented

Inherited from TimeoutMixin:

Method callLater Wrapper around reactor.callLater for test purpose.
Method resetTimeout Reset the timeout count down.
Method setTimeout Change the timeout period
Instance Variable __timeoutCall Undocumented
Method __timedOut Undocumented
persistentTimeOut = (source)
the timeout period used to wait for a response.
(type: int)
_current = (source)
current list of requests waiting for an answer from the server.
(type: deque of Command)
_lenExpected = (source)
amount of data expected in raw mode, when reading for a value.
(type: int)
_getBuffer = (source)
current buffer of data, used to store temporary data when reading in raw mode.
(type: list)
_bufferLength = (source)
the total amount of bytes in _getBuffer.
(type: int)
_disconnected = (source)
indicate if the connectionLost has been called or not.
(type: bool)
MAX_KEY_LENGTH = (source)

Undocumented

(type: int)
def __init__(self, timeOut=60): (source)

Create the protocol.

ParameterstimeOutthe timeout to wait before detecting that the connection is dead and close it. It's expressed in seconds. (type: int)
def _cancelCommands(self, reason): (source)

Cancel all the outstanding commands, making them fail with reason.

def timeoutConnection(self): (source)

Close the connection in case of timeout.

def connectionLost(self, reason): (source)
def sendLine(self, line): (source)

Override sendLine to add a timeout to response.

def rawDataReceived(self, data): (source)

Collect data for a get.

def cmd_STORED(self): (source)

Manage a success response to a set operation.

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_END(self): (source)

This the end token to a get or a stat operation.

def cmd_NOT_FOUND(self): (source)

Manage error response for incr/decr/delete.

def cmd_VALUE(self, line): (source)

Prepare the reading a value after a get.

def cmd_STAT(self, line): (source)

Reception of one stat line.

def cmd_VERSION(self, versionData): (source)

Read version token.

def cmd_ERROR(self): (source)

A non-existent command has been sent.

def cmd_CLIENT_ERROR(self, errText): (source)

An invalid input as been sent.

def cmd_SERVER_ERROR(self, errText): (source)

An error has happened server-side.

def cmd_DELETED(self): (source)

A delete command has completed successfully.

def cmd_OK(self): (source)

The last command has been completed.

def cmd_EXISTS(self): (source)

A checkAndSet update has failed.

def lineReceived(self, line): (source)

Receive line commands from the server.

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.

Parameterskeythe key to modify. (type: bytes)
valthe value to increment. (type: int)
Returnsa deferred with will be called back with the new value associated with the key (after the increment). (type: Deferred)
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.

Parameterskeythe key to modify. (type: bytes)
valthe value to decrement. (type: int)
Returnsa deferred with will be called back with the new value associated with the key (after the decrement). (type: Deferred)
def _incrdecr(self, cmd, key, val): (source)

Internal wrapper for incr/decr.

def replace(self, key, val, flags=0, expireTime=0): (source)

Replace the given key. It must already exist in the server.

Parameterskeythe key to replace. (type: bytes)
valthe new value associated with the key. (type: bytes)
flagsthe flags to store with the key. (type: int)
expireTimeif different from 0, the relative time in seconds when the key will be deleted from the store. (type: int)
Returnsa deferred that will fire with True if the operation has succeeded, and False with the key didn't previously exist. (type: Deferred)
def add(self, key, val, flags=0, expireTime=0): (source)

Add the given key. It must not exist in the server.

Parameterskeythe key to add. (type: bytes)
valthe value associated with the key. (type: bytes)
flagsthe flags to store with the key. (type: int)
expireTimeif different from 0, the relative time in seconds when the key will be deleted from the store. (type: int)
Returnsa deferred that will fire with True if the operation has succeeded, and False with the key already exists. (type: Deferred)
def set(self, key, val, flags=0, expireTime=0): (source)

Set the given key.

Parameterskeythe key to set. (type: bytes)
valthe value associated with the key. (type: bytes)
flagsthe flags to store with the key. (type: int)
expireTimeif different from 0, the relative time in seconds when the key will be deleted from the store. (type: int)
Returnsa deferred that will fire with True if the operation has succeeded. (type: Deferred)
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.

ParameterskeyThe key to set. (type: bytes)
valThe value associated with the key. (type: bytes)
casUnique 64-bit value returned by previous call of get. (type: bytes)
flagsThe flags to store with the key. (type: int)
expireTimeIf different from 0, the relative time in seconds when the key will be deleted from the store. (type: int)
ReturnsA deferred that will fire with True if the operation has succeeded, False otherwise. (type: Deferred)
def _set(self, cmd, key, val, flags, expireTime, cas): (source)

Internal wrapper for setting values.

def append(self, key, val): (source)

Append given data to the value of an existing key.

ParameterskeyThe key to modify. (type: bytes)
valThe value to append to the current value associated with the key. (type: bytes)
ReturnsA deferred that will fire with True if the operation has succeeded, False otherwise. (type: Deferred)
def prepend(self, key, val): (source)

Prepend given data to the value of an existing key.

ParameterskeyThe key to modify. (type: bytes)
valThe value to prepend to the current value associated with the key. (type: bytes)
ReturnsA deferred that will fire with True if the operation has succeeded, False otherwise. (type: Deferred)
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.

ParameterskeyThe key to retrieve. (type: bytes)
withIdentifierIf set to True, retrieve the current identifier along with the value and the flags. (type: bool)
ReturnsA 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. (type: Deferred)
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.

ParameterskeysThe keys to retrieve. (type: list of bytes)
withIdentifierIf set to True, retrieve the identifiers along with the values and the flags. (type: bool)
ReturnsA 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. (type: Deferred)
Present Since9.0
def _get(self, keys, withIdentifier, multiple): (source)

Helper method for get and getMultiple.

def stats(self, arg=None): (source)

Get some stats from the server. It will be available as a dict.

ParametersargAn 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. (type: None or bytes)
Returnsa deferred that will fire with a dict of the available statistics. (type: Deferred)
def version(self): (source)

Get the version of the server.

Returnsa deferred that will fire with the string value of the version. (type: Deferred)
def delete(self, key): (source)

Delete an existing key.

Parameterskeythe key to delete. (type: bytes)
Returnsa deferred that will be called back with True if the key was successfully deleted, or False if not. (type: Deferred)
def flushAll(self): (source)

Flush all cached values.

Returnsa deferred that will be called back with True when the operation has succeeded. (type: Deferred)
API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.