Skip to main content

a3redis

English | 简体中文

a3redis is a simple wrapper around redis-py to make it easier to use.

1. Introduction

  • When logically compatible, the Redis service type (standalone, sentinel, or cluster) can be switched by only modifying the configuration without changing the code.
  • You can configure multiple Redis services of different types at the same time; if no Redis service configuration is specified, redis://localhost:6379/0 will be used by default.
  • Provides class forms of commonly used data structures for ease of use.

2. Usage

Install

pip install a3redis

Examples

CONF = {
    "standalone": {
        "mode": "standalone",
        "init": {
            "host": "standalone-redis-master",
            "port": 6379,
            "db": 0,
            "password": "standalone",
            "decode_responses": True
        }
    },
    "sentinel": {
        "mode": "sentinel",
        "init": {
            "sentinels": [
                ["sentinel-redis-node-0.sentinel-redis-headless", 26379],
                ["sentinel-redis-node-1.sentinel-redis-headless", 26379],
                ["sentinel-redis-node-2.sentinel-redis-headless", 26379]
            ],
            "sentinel_kwargs": {
                "password": "sentinel"
            },
            "password": "sentinel",
            "db": 1,
            "decode_responses": True
        },
        "runtime": {
            "service_name": "my-master"
        }
    },
    "cluster": {
        "mode": "cluster",
        "init": {
            "host": "cluster-redis-cluster",
            "port": 6379,
            "password": "cluster",
            "decode_responses": True
        }
    }
}


from a3redis.bases import RedisClientFactory, RedisMode
from a3redis.structures import Hash


class User(Hash):
    main_key = 'user:{id}'
    _hkey_username = 'username'

    def get_username(self) -> str:
        return self.get_member_by_key(self._hkey_username)

    def set_username(self, username: str):
        self.set_member(self._hkey_username, username)


if __name__ == '__main__':
    RedisClientFactory.init_redis_clients(conf=CONF)

    localhost_anonymous_rdb = None
    standalone_rdb = RedisClientFactory.get_rdb(RedisMode.Standalone)
    sentinel_rdb = RedisClientFactory.get_rdb(RedisMode.Sentinel)
    cluster_rdb = RedisClientFactory.get_rdb(RedisMode.Cluster)
    
    for rdb in [localhost_anonymous_rdb, standalone_rdb, sentinel_rdb, cluster_rdb]:
        user = User(id="123", rdb=rdb)
        user.set_username("tom")
        user.get_username()
        user.delete()

Release files for a3redis 0.3.0

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

Source distribution (sdist)

Source distribution for a3redis 0.3.0
File Size Uploaded
a3redis-0.3.0.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for a3redis 0.3.0
File Interpreter ABI Platform
a3redis-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.3 kB

Release files / a3redis-0.3.0.tar.gz

Download URL a3redis-0.3.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
76c03529139838cc0fac6bb6b5b448494376baf576c87d7d84aa31ffd7c85893
BLAKE2b-256 checksum
How to use checksums
ef082965675f817d9e0727233d042d24ed5d10dbfcf7e14f1ca781c595c3a9d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

Release files / a3redis-0.3.0-py3-none-any.whl

Download URL a3redis-0.3.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae8ee15ffff1076d9fe79b6d073e7f82a36e3feeb05c7d1b373fd354c1f58cff
BLAKE2b-256 checksum
How to use checksums
d87c4bfbefeb509104a3e88cfa4d81356a3cd7ffb894be83e639bbdda8349039
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.1.2

1 release file

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