跳转到主要内容

一组由Redis支持的Python基本集合。

项目描述

redis-collections 是一个Python库,它提供了一个高级接口,用于访问优秀的键值存储程序Redis。

截至2024年,该项目已废弃。此存储库将作为公共归档保留。

快速入门

从顶层 redis_collections 包导入集合。

标准集合

标准集合(例如 DictListSet)的行为类似于它们的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 LabsRedisredis-py 无关。请自行管理!

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码发行版

redis-collections-0.13.0.tar.gz (41.0 kB 查看哈希值)

上传时间 源代码

构建发行版

redis_collections-0.13.0-py2.py3-none-any.whl (29.9 kB 查看哈希值)

上传时间 Python 2 Python 3

支持者