Skip to content

Commit f02e5c4

Browse files
committed
update
1 parent c7b3108 commit f02e5c4

File tree

165 files changed

+33627
-113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+33627
-113
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.0.2
2+
3+
+ 新增list,pubsub,stream3种常用生产者消费者结构的代理类型
4+
+ 细化注释文档
5+
16
# 0.0.1
27

38
项目创建

README.md

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,97 @@
77
+ `redis.asyncio.Redis`
88
+ `redis.asyncio.cluster.RedisCluster`
99

10+
## 特性
11+
12+
+ 提供了统一的代理对象`RedisProxy`用于代理`redis.Redis`,`redis.cluster.RedisCluster`,`redis.asyncio.Redis``redis.asyncio.cluster.RedisCluster`
13+
+ 针对生产者消费者模式提供了专用代理对象`ChannelConsumerProxy`,`ChannelProducerProxy`,`QueueConsumerProxy`,`QueueProducerProxy`,`StreamConsumerProxy`,`StreamProducerProxy`
14+
+ 生产者消费者提供了进一步的封装,可以通过上下文管理连接
15+
1016
## 使用
1117

18+
### RedisProxy的使用
19+
20+
我们可以使用`RedisProxy`延后初始化要代理的对象,从而避免客户端对象在各个函数之间传来传去.
21+
22+
```python
23+
24+
rediscli = RedisProxy()
25+
26+
...
27+
28+
rediscli.initialize_from_url("redis://localhost:6379/0?decode_responses=true")
29+
```
30+
1231
我们可以在运行时通过代理对象的property`aio`和property`cluster`来确认是哪种客户端.
1332

1433
当我们编程时我们应该先确定将使用哪种客户端,然后使用`typing.cast`方法在调用前声明类型.多数时候我们并不需要标明实际的类型,可以只区分同步和异步和具体使用:
1534

16-
+ 数据读写
17-
+ 同步:`r = cast(redis.commands.core.DataAccessCommands,proxy)`
18-
+ 异步:`r = cast(redis.commands.core.AsyncDataAccessCommands,proxy)`
19-
+ pubsub:
20-
+ 同步:`r = cast(redis.commands.core.PubSubCommands,proxy)`
21-
+ 异步:`r = cast(redis.commands.core.AsyncPubSubCommands,proxy)`
35+
> 同步:
36+
37+
```python
38+
r = cast(redis.commands.core.DataAccessCommands,rediscli)
39+
r.get("x")
40+
```
41+
42+
> 异步:
43+
44+
```python
45+
r = cast(redis.commands.core.AsyncDataAccessCommands,rediscli)
46+
await r.get(x)
47+
```
48+
49+
这样我们在写程序是也可以有接口提示.只有用到`pubsub`,`execute_command`或者`pipeline`的少数场景时需要指定具体类型.
50+
51+
### 生产者消费者模式
2252

23-
这样我们在写程序是也可以有接口提示.只有用到`execute_command`或者`pipeline`时需要指定具体类型.
53+
生产者消费者模式提供了基本统一的接口设计
54+
55+
+ `ConsumerProtocol` 通用的同步消费者接口
56+
+ `ProducerProtocol` 除了stream外通用的同步生产者接口
57+
+ `AioConsumerProtocol` 通用的异步消费者接口
58+
+ `AioProducerProtocol` 除了stream外通用的异步生产者接口
59+
+ `StreamProducerProtocol`stream的同步生产者接口
60+
+ `AioStreamProducerProtocol` stream的异步生产者接口
61+
62+
当我们编程时我们应该先确定将使用哪种客户端,然后使用`typing.cast`方法在调用前声明对应代理的接口类型.
63+
64+
> 同步生产者
65+
66+
```python
67+
qp = cast(StreamProducerProtocol, StreamProducerProxy.from_proxy(rediscli, maxlen=20))
68+
with qp.mount() as producer:
69+
for i in range(10):
70+
producer.publish(topic,value)
71+
```
72+
73+
> 异步生产者
74+
75+
```python
76+
qp = cast(AioStreamProducerProtocol, StreamProducerProxy.from_proxy(rediscli, maxlen=20))
77+
async with qp.mount() as producer:
78+
for i in range(10):
79+
await producer.publish(topic,value)
80+
```
81+
82+
> 同步消费者
83+
84+
```python
85+
qc = cast(ConsumerProtocol, QueueConsumerProxy.from_proxy(rediscli, topics))
86+
87+
with qc.watch() as records:
88+
for record in records:
89+
print(f"get msg {record.value} from topic {record.topic}")
90+
```
91+
92+
> 异步消费者
93+
94+
```python
95+
qc = cast(AioConsumerProtocol, QueueConsumerProxy.from_proxy(rediscli, topics))
96+
97+
async with qc.watch() as records:
98+
async for record in records:
99+
print(f"get msg {record.value} from topic {record.topic}")
100+
```
24101

25102
## 安装
26103

docs/.buildinfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: f52c4fc350646a961758dac3f8944985
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7

docs/.doctrees/CHANGELOG.doctree

3.5 KB
Binary file not shown.

docs/.doctrees/README.doctree

19.9 KB
Binary file not shown.

docs/.doctrees/autoapi/index.doctree

4.24 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

docs/.doctrees/environment.pickle

448 KB
Binary file not shown.

docs/.doctrees/index.doctree

3.32 KB
Binary file not shown.

docs/.nojekyll

Whitespace-only changes.

docs/CHANGELOG.html

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
2+
3+
<!DOCTYPE html>
4+
<html class="writer-html5" lang="zh-CN" >
5+
<head>
6+
<meta charset="utf-8" />
7+
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
9+
10+
<title>0.0.2 &mdash; redisproxy 0.0.2 文档</title>
11+
12+
13+
14+
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
15+
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
16+
<link rel="stylesheet" href="_static/graphviz.css" type="text/css" />
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
<!--[if lt IE 9]>
28+
<script src="_static/js/html5shiv.min.js"></script>
29+
<![endif]-->
30+
31+
32+
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
33+
<script src="_static/jquery.js"></script>
34+
<script src="_static/underscore.js"></script>
35+
<script src="_static/doctools.js"></script>
36+
<script src="_static/translations.js"></script>
37+
38+
<script type="text/javascript" src="_static/js/theme.js"></script>
39+
40+
41+
<link rel="index" title="索引" href="genindex.html" />
42+
<link rel="search" title="搜索" href="search.html" />
43+
<link rel="prev" title="redisproxy" href="README.html" />
44+
</head>
45+
46+
<body class="wy-body-for-nav">
47+
48+
49+
<div class="wy-grid-for-nav">
50+
51+
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
52+
<div class="wy-side-scroll">
53+
<div class="wy-side-nav-search" >
54+
55+
56+
57+
<a href="index.html" class="icon icon-home"> redisproxy
58+
59+
60+
61+
</a>
62+
63+
64+
65+
66+
<div class="version">
67+
0.0.2
68+
</div>
69+
70+
71+
72+
73+
<div role="search">
74+
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
75+
<input type="text" name="q" placeholder="在文档中搜索" />
76+
<input type="hidden" name="check_keywords" value="yes" />
77+
<input type="hidden" name="area" value="default" />
78+
</form>
79+
</div>
80+
81+
82+
</div>
83+
84+
85+
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
86+
87+
88+
89+
90+
91+
92+
<ul class="current">
93+
<li class="toctree-l1"><a class="reference internal" href="README.html">介绍</a></li>
94+
<li class="toctree-l1 current"><a class="current reference internal" href="#">0.0.2</a></li>
95+
<li class="toctree-l1"><a class="reference internal" href="#id2">0.0.1</a></li>
96+
<li class="toctree-l1"><a class="reference internal" href="autoapi/index.html">API Reference</a></li>
97+
</ul>
98+
99+
100+
101+
</div>
102+
103+
</div>
104+
</nav>
105+
106+
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
107+
108+
109+
<nav class="wy-nav-top" aria-label="top navigation">
110+
111+
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
112+
<a href="index.html">redisproxy</a>
113+
114+
</nav>
115+
116+
117+
<div class="wy-nav-content">
118+
119+
<div class="rst-content">
120+
121+
122+
123+
124+
125+
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
139+
<div role="navigation" aria-label="breadcrumbs navigation">
140+
141+
<ul class="wy-breadcrumbs">
142+
143+
<li><a href="index.html" class="icon icon-home"></a> &raquo;</li>
144+
145+
<li>0.0.2</li>
146+
147+
148+
<li class="wy-breadcrumbs-aside">
149+
150+
151+
<a href="_sources/CHANGELOG.md.txt" rel="nofollow"> 查看页面源码</a>
152+
153+
154+
</li>
155+
156+
</ul>
157+
158+
159+
<hr/>
160+
</div>
161+
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
162+
<div itemprop="articleBody">
163+
164+
<div class="section" id="id1">
165+
<h1>0.0.2<a class="headerlink" href="#id1" title="永久链接至标题"></a></h1>
166+
<ul class="simple">
167+
<li><p>新增list,pubsub,stream3种常用生产者消费者结构的代理类型</p></li>
168+
<li><p>细化注释文档</p></li>
169+
</ul>
170+
</div>
171+
<div class="section" id="id2">
172+
<h1>0.0.1<a class="headerlink" href="#id2" title="永久链接至标题"></a></h1>
173+
<p>项目创建</p>
174+
</div>
175+
176+
177+
</div>
178+
179+
</div>
180+
<footer>
181+
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
182+
<a href="README.html" class="btn btn-neutral float-left" title="redisproxy" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> 上一页</a>
183+
</div>
184+
185+
<hr/>
186+
187+
<div role="contentinfo">
188+
<p>
189+
&#169; 版权所有 2023, mac.
190+
191+
</p>
192+
</div>
193+
194+
195+
196+
利用 <a href="https://www.sphinx-doc.org/">Sphinx</a> 构建,使用了
197+
198+
<a href="https://github.com/readthedocs/sphinx_rtd_theme">主题</a>
199+
200+
<a href="https://readthedocs.org">Read the Docs</a>开发.
201+
202+
</footer>
203+
</div>
204+
</div>
205+
206+
</section>
207+
208+
</div>
209+
210+
211+
<script type="text/javascript">
212+
jQuery(function () {
213+
SphinxRtdTheme.Navigation.enable(true);
214+
});
215+
</script>
216+
217+
218+
219+
220+
221+
222+
</body>
223+
</html>

0 commit comments

Comments
 (0)