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/0will 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()
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| a3redis-0.3.0.tar.gz | 9.9 kB | Without provenance | Details for a3redis-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| a3redis-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for a3redis-0.3.0-py3-none-any.whl |
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
|
Security for a3redis 0.3.0
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.