Skip to main content

redset

PyPI version build status Coverage Status

You may not need heavyweights like Celery or RQ. Maintaing an AMQP server might be overkill. There’s a simpler, easier way to distribute work.

Redset provides simple, generic sorted sets backed by Redis that can be used to coordinate distributed systems and parcel out work. Unlike more common distribution libraries like Celery or RQ, redset avoids duplicate work for certain use-cases by maintaining a set of tasks instead of a list or queue. And it does so with a dead-simple interface that feels natural for Python.

Redset is currently used in the wild to do things like

  • maintain a high-throughput work queue of streaming updates to be processed

  • power a multi-producer, multi-consumer scraping architecture that won’t do the same work twice

  • maintain a simple, cross-process set of “seen” items that each have a TTL

  • schedule non-duplicate, periodic polling of analytics on social services

Features

  • No worker daemons to run, no heavy AMQP service to monitor

  • Safe for multiple producers and consumers

  • Seamless, simple use with Python objects using serializers

  • Zero dependencies: you provide an object that implements the redis.client.Redis interface, we don’t ask any questions.

  • Simple, easy-to-read implementation

  • Mimics Python’s native set interface

  • Battle-tested

  • Python 3 compatible

Simple example

import json
import redis

from redset import TimeSortedSet

r = redis.Redis()
ss = TimeSortedSet(r, 'important_json_biz', serializer=json)

ss.add({'foo': 'bar1'})
ss.add({'foo': 'bar2'})

ss.add({'foo': 'bar3'})
ss.add({'foo': 'bar3'})

len(ss)
# 3


# ...some other process A

ss.peek()
# {'foo': 'bar1'}

ss.pop()
# {'foo': 'bar1'}


# ...meanwhile in process B (at exactly same time as A's pop)

ss.take(2)
# [{'foo': 'bar2'}, {'foo': 'bar3'}]

Docs

Here

About

This software was developed at Percolate, where we use it for all sorts of things that involve maintaining synchronized sets of things across process boundaries. A common use-case is to use redset for coordinating time-sensitive tasks where duplicate requests may be generated.

Redset is unopinionated about how consumers look or behave. Want to have a plain ‘ol Python consumer managed by supervisor? Fine. Want to be able to pop off items from within a celery job? Great. Redset has no say in where or how it is used: mechanism, not policy.

Usage concepts

redset.SortedSet and its subclasses can be instantiated with a few paramters that are notable.

Specifying a serializer

Since Redis only stores primitive numbers and strings, handling serialization and deserialization is a key part of making redset set usage simple in Python.

A serializer instance can be passed (which adheres to the redset.interfaces.Serializer interface, though it need not subclass it) to automatically handle packing and unpacking items managed with redset.

Specifying a scorer

A callable that specifies how to generate a score for items being added can also be passed to SortedSet’s constructor as scorer. This callable takes one argument, which is the item object (i.e. the item before serialization) to be “scored.”

Metadata

Release files for redset 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redset 0.5.1
File Size Uploaded Provenance
redset-0.5.1.tar.gz 8.6 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for redset 0.5.1
File Interpreter ABI Platform
redset-0.5.1-py3-none-any.whl Python 3 none any Details
redset-0.5.1-py2-none-any.whl Python 2 none any Details

Total release size: 32.1 kB

Release files / redset-0.5.1.tar.gz

Download URL redset-0.5.1.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a1eeab91f95acc586e5886f3fffdc2bcfbdd00dc00d0da881c5d1482b70a92af
BLAKE2b-256 checksum
How to use checksums
f5cfaabbe231b78a8b50a3e7779d03b5a2493e040e470f26f99b7e10644fa49f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / redset-0.5.1-py3-none-any.whl

Download URL redset-0.5.1-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f841ff13156725ab5facbf287cac9c97152dcdd74885880b268b06cff6fbb436
BLAKE2b-256 checksum
How to use checksums
c56e359b7165782e7b517a54b7aed1c9c4b2665fd6ca06256f8acec5b786cd09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / redset-0.5.1-py2-none-any.whl

Download URL redset-0.5.1-py2-none-any.whl
Size 11.7 kB
Tags Python 2
SHA-256 checksum
How to use checksums
d7436d638531bfa3baa93ba4a365afd2262cae8538ec1f49ff8cfe4c6263abbf
BLAKE2b-256 checksum
How to use checksums
70a63823eae1a6c60e17068145e35387163e7e6f657558d674fffb68e74ce136
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for redset 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page