Skip to main content

Simple, distributed sorted sets with redis

Project description

PyPI version build status

Simple, generic sorted sets backed by Redis that can be used to coordinate distributed systems.

Features

  • Safe for multiple producers and consumers

  • Seamless use with Python objects using serializers

  • No worker daemons to run, no client processes to maintain

  • Simple, easy-to-read implementation

  • Mimics Python’s native set interface

  • Well tested

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.

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'})

len(ss)
# 3


# ...some other process


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

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

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

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.”

Installing

Download this directory, and install it using pip with setup.py:

pip install .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redset-0.2.3.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file redset-0.2.3.tar.gz.

File metadata

  • Download URL: redset-0.2.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for redset-0.2.3.tar.gz
Algorithm Hash digest
SHA256 d68fd36a723986883a47dedcd7faa677aa77b48daee1c455cee2623c8cdc54e3
MD5 c8488b84aaa78edfa110f502f46be0f2
BLAKE2b-256 27d7be55c901e14c8e72dd503787d2aa70ad73995c8d4bb10f6c858b7ab07efb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page