harp_apps.storage.services.blob_storages.redis

Inheritance diagram of harp_apps.storage.services.blob_storages.redis

class RedisBlobStorage[source]

Bases: IBlobStorage

__init__(client)[source]
Parameters:

client (Redis)

async delete(blob_id)[source]
async delete_blobs(blobs)[source]

Delete each blob, unless it was stored again with other data since it was read.

Parameters:

blobs (Iterable[Blob])

Return type:

None

async delete_stale(blob_ids, /, *, older_than)[source]

Delete the given blobs, except those written after older_than. Returns how many were deleted.

Parameters:
Return type:

int

async exists(blob_id)[source]
Parameters:

blob_id (str)

Return type:

bool

async force_put(blob)
Parameters:

blob (Blob)

Return type:

Blob

async get(blob_id)[source]
async iter_blob_ids()[source]

Every blob id stored under the HARP prefix.

Return type:

AsyncIterator[str]

async iter_blobs(content_type)[source]

Every stored blob of this content type.

Only the first bytes of each value are read to tell the type, so the bodies of other blobs stay in Redis.

Parameters:

content_type (str)

Return type:

AsyncIterator[Blob]

async put(blob)[source]
Parameters:

blob (Blob)

Return type:

Blob

type: str = 'redis'
BLOB_PREFIX = 'harp:blob:'

Every blob lives at <prefix><blob id>: the Redis database may be shared with other applications, whose keys HARP never lists or sweeps. Blobs stored before the prefix existed sit under their bare id (a 40 or 64 character hexdigest): they are still read and deleted by id, but never listed.

WRITE_MARKER_PREFIX = 'harp:blob-written:'

Marks a blob as recently written: key <prefix><blob id>, holding the write time, living ORPHAN_GRACE. Redis blobs have no created_at; the marker is what keeps the janitor from deleting content whose message is not committed yet, as blobs.created_at does for SQL.