Skip to main content

CouchbaseBackend

Couchbase backend.

Attributes​

AttributeTypeDescription
bucketstring = defaultThe name of the Couchbase bucket used for data storage.
hoststring = localhostThe hostname or IP address of the Couchbase server node.
portinteger = 8091The network port number used to connect to the Couchbase cluster.
usernamestring = nullThe username used for authenticating with the Couchbase cluster.
passwordstring = nullThe password used for authenticating with the Couchbase cluster.
quietboolean = falseFlag to determine if connection errors should be suppressed.
supports_autoexpireboolean = trueIndicates that the backend supports automatic expiration of keys via TTL.
timeoutfloat = 2.5The maximum time in seconds to wait for Couchbase operations to complete.
key_ttype = strUse str as couchbase key not bytes

Constructor​

Signature​

def CouchbaseBackend(
url: string = None,
*args: any,
**kwargs: any
)

Parameters​

NameTypeDescription
urlstring = NoneThe connection URL containing Couchbase server details.
*argsanyVariable length argument list passed to the parent class.
**kwargsanyArbitrary keyword arguments passed to the parent class.

Methods​


connection()​

@classmethod
def connection() - > couchbase.collection.Collection

Provides access to the active Couchbase connection, initializing it if it does not already exist.

Returns​

TypeDescription
couchbase.collection.CollectionThe active Couchbase collection used for data operations

get()​

@classmethod
def get(
key: str
) - > Any

Retrieves the content associated with a specific key from the Couchbase bucket.

Parameters​

NameTypeDescription
keystrThe unique identifier for the document to retrieve

Returns​

TypeDescription
AnyThe deserialized content stored under the provided key

set()​

@classmethod
def set(
key: str,
value: Any
)

Stores or updates a value in the Couchbase bucket using an upsert operation with an optional expiration time.

Parameters​

NameTypeDescription
keystrThe unique identifier under which the value will be stored
valueAnyThe data to be stored, which must be compatible with Couchbase JSON serialization

mget()​

@classmethod
def mget(
keys: list
) - > dict

Fetches multiple documents from the Couchbase bucket in a single batch operation.

Parameters​

NameTypeDescription
keyslistA list of unique identifiers for the documents to be retrieved

Returns​

TypeDescription
dictA dictionary mapping the requested keys to their corresponding document results

delete()​

@classmethod
def delete(
key: str
)

Removes a document from the Couchbase bucket based on the provided key.

Parameters​

NameTypeDescription
keystrThe unique identifier of the document to be deleted