一组由Redis支持的Python基本集合。
项目描述
redis-collections 是一个Python库,它提供了一个高级接口,用于访问优秀的键值存储程序Redis。
截至2024年,该项目已废弃。此存储库将作为公共归档保留。
快速入门
从顶层 redis_collections 包导入集合。
标准集合
标准集合(例如 Dict,List,Set)的行为类似于它们的Python对应项
>>> from redis_collections import Dict, List, Set
>>> D = Dict()
>>> D['answer'] = 42
>>> D['answer']
42
集合 |
Redis类型 |
描述 |
---|---|---|
Dict |
哈希 |
模仿Python的 dict |
List |
List |
模仿Python的 list |
Set |
Set |
模仿Python的 set |
Counter |
哈希 |
模仿Python的 collections.Counter |
DefaultDict |
哈希 |
模仿Python的 collections.defaultdict |
Deque |
List |
模仿Python的 collections.deque |
可同步集合
此包中的可同步集合提供了内容保存在内存中的类型。当调用其 sync 方法时,这些内容将被写入Redis
>>> from redis_collections import SyncableDict
>>> with SyncableDict() as D:
... D['a'] = 1 # No write to Redis
... D['a'] += 1 # No read from or write to Redis
>>> D['a'] # D.sync() is called at the end of the with block
2
集合 |
Python类型 |
描述 |
---|---|---|
SyncableDict |
字典 |
同步到Redis哈希表 |
可同步列表 |
列表 |
同步到Redis列表 |
可同步集合 |
集合 |
同步到Redis集合 |
可同步计数器 |
collections.Counter |
同步到Redis哈希表 |
可同步双端队列 |
collections.deque |
同步到Redis列表 |
可同步默认字典 |
collections.defaultdict |
同步到Redis哈希表 |
其他集合
LRUDict 集合在内存中存储最近使用项。将较旧项推送到Redis
>>> from redis_collections import LRUDict
>>> D = LRUDict(maxsize=2)
>>> D['a'] = 1
>>> D['b'] = 2
>>> D['c'] = 2 # 'a' is pushed to Redis and 'c' is stored locally
>>> D['a'] # 'b' is pushed to Redis and 'a' is retrieved for local storage
1
>>> D.sync() # All items are copied to Redis
SortedSetCounter 提供对Redis 有序集合类型的访问
>>> from redis_collections import SortedSetCounter
>>> ssc = SortedSetCounter([('earth', 300), ('mercury', 100)])
>>> ssc.set_score('venus', 200)
>>> ssc.get_score('venus')
200.0
>>> ssc.items()
[('mercury', 100.0), ('venus', 200.0), ('earth', 300.0)]
文档
有关更多信息,请参阅 redis-collections.readthedocs.io
许可证:ISC
© 2016-2024 Bo Bayles <bbayles@gmail.com> 和贡献者 © 2013-2016 Honza Javorek <mail@honzajavorek.cz> 和贡献者
本作品受 ISC许可证 许可。
此库与 Redis Labs、Redis 或 redis-py 无关。请自行管理!
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码发行版
构建发行版
哈希值 for redis_collections-0.13.0-py2.py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a7c41ff0a1135004f3dec98bedabf89592746fe0a2ca4a6ee455fc3cc12f9060 |
|
MD5 | ff284e5e2dc0c25219a57cf9904c169d |
|
BLAKE2b-256 | 82d4d1eb9a22fe763d6b04df4002a37643974efb3ceea6326adba4ce45ecfeaf |