Skip to main content

rb3, the redis blaster which support Python 3.7

Project description

rb3, the rb fork support Python3.7

Changes compared to getsentry/rb

Not a compatibility upgrade.

From this version, this fork of rb will only support Python3.7+ (Python3.5+ is tested but not recommend).

At the moment, we focus on how to make rb work under Python3.7 like it workd well on Python2.7.

Change in crc32:

For now, we decide to support Python2-like crc32 computing result by editing rb/router.py:

class PartitionRouter(BaseRouter):
    """A straightforward router that just individually routes commands to
    single nodes based on a simple ``crc32 % node_count`` setup.

    This router requires that the hosts are gapless which means that
    the IDs for N hosts range from 0 to N-1.

    ``crc32`` returns different value in Python2 and Python3, for details
    check this link: https://bugs.python.org/issue22341.
    """

    def __init__(self, cluster):
        BaseRouter.__init__(self, cluster)
        assert_gapless_hosts(self.cluster.hosts)

    def get_host_for_key(self, key):
        if isinstance(key, text_type):
            k = key.encode('utf-8')
        else:
            k = bytes_type(key)
        # Make sure return value same as in Python3
        # return (crc32(k) & 0xffffffff) % len(self.cluster.hosts)

        # Make sure return value same as in Python2
        crc_res = crc32(k)
        crc_res = (crc_res - ((crc_res & 0x80000000) <<1))
        return crc_res % len(self.cluster.hosts)

But may turn to use Python 3's native crc32 function in the future.

TODO

  • option to choose crc32's method
  • fix macOS travis test
  • fix pypy travis test

rb's original README

logo

rb - the redis blaster.

The fastest way to talk to many redis nodes. Can do routing as well as blindly blasting commands to many nodes. How does it work?

For full documentation see rb.rtfd.org

Quickstart

Set up a cluster:

from rb import Cluster

cluster = Cluster({
    0: {'port': 6379},
    1: {'port': 6380},
    2: {'port': 6381},
    3: {'port': 6382},
}, host_defaults={
    'host': '127.0.0.1',
})

Automatic routing:

results = []
with cluster.map() as client:
    for key in range(100):
        client.get(key).then(lambda x: results.append(int(x or 0)))

print('Sum: %s' % sum(results))

Fanout:

with cluster.fanout(hosts=[0, 1, 2, 3]) as client:
    infos = client.info()

Fanout to all:

with cluster.fanout(hosts='all') as client:
    client.flushdb()

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

rb3-1.8.tar.gz (21.9 kB view details)

Uploaded Source

File details

Details for the file rb3-1.8.tar.gz.

File metadata

  • Download URL: rb3-1.8.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for rb3-1.8.tar.gz
Algorithm Hash digest
SHA256 67fb6586114c49956ba569f28cf95c5be41c72d68461fd9b4f1d21ec442bc44d
MD5 1a5549bbb5a9ad30b16d30505dd1e75b
BLAKE2b-256 9100355164ad68c4b96bed337e3aa54ed9c592c4c54d2e339a02526c221297a0

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