Skip to content

Commit dd2cc30

Browse files
committed
update
1 parent f02e5c4 commit dd2cc30

24 files changed

+94
-94
lines changed

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ include LICENSE
22
include README.md
33
include CHANGELOG.md
44
include requirements.txt
5-
recursive-include redisproxy *.pyx *.pxd *.pxi *.py *.c *.h *.temp *.jinja
5+
recursive-include redishelper *.pyx *.pxd *.pxi *.py *.c *.h *.temp *.jinja

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# redisproxy
1+
# redishelper
22

33
提供redis客户端的代理对象功能.本项目代理的对象是[redis-py](https://github.com/redis/redis-py)中的四种客户端
44

@@ -10,7 +10,7 @@
1010
## 特性
1111

1212
+ 提供了统一的代理对象`RedisProxy`用于代理`redis.Redis`,`redis.cluster.RedisCluster`,`redis.asyncio.Redis``redis.asyncio.cluster.RedisCluster`
13-
+ 针对生产者消费者模式提供了专用代理对象`ChannelConsumerProxy`,`ChannelProducerProxy`,`QueueConsumerProxy`,`QueueProducerProxy`,`StreamConsumerProxy`,`StreamProducerProxy`
13+
+ 针对生产者消费者模式提供了专用代理对象`ChannelConsumerHelper`,`ChannelProducerHelper`,`QueueConsumerHelper`,`QueueProducerHelper`,`StreamConsumerPHelper`,`StreamProducerHelper`
1414
+ 生产者消费者提供了进一步的封装,可以通过上下文管理连接
1515

1616
## 使用
@@ -64,7 +64,7 @@ await r.get(x)
6464
> 同步生产者
6565
6666
```python
67-
qp = cast(StreamProducerProtocol, StreamProducerProxy.from_proxy(rediscli, maxlen=20))
67+
qp = cast(StreamProducerProtocol, StreamProducerHelper.from_proxy(rediscli, maxlen=20))
6868
with qp.mount() as producer:
6969
for i in range(10):
7070
producer.publish(topic,value)
@@ -73,7 +73,7 @@ with qp.mount() as producer:
7373
> 异步生产者
7474
7575
```python
76-
qp = cast(AioStreamProducerProtocol, StreamProducerProxy.from_proxy(rediscli, maxlen=20))
76+
qp = cast(AioStreamProducerProtocol, StreamProducerHelper.from_proxy(rediscli, maxlen=20))
7777
async with qp.mount() as producer:
7878
for i in range(10):
7979
await producer.publish(topic,value)
@@ -82,7 +82,7 @@ async with qp.mount() as producer:
8282
> 同步消费者
8383
8484
```python
85-
qc = cast(ConsumerProtocol, QueueConsumerProxy.from_proxy(rediscli, topics))
85+
qc = cast(ConsumerProtocol, QueueConsumerHelper.from_proxy(rediscli, topics))
8686

8787
with qc.watch() as records:
8888
for record in records:
@@ -92,7 +92,7 @@ with qc.watch() as records:
9292
> 异步消费者
9393
9494
```python
95-
qc = cast(AioConsumerProtocol, QueueConsumerProxy.from_proxy(rediscli, topics))
95+
qc = cast(AioConsumerProtocol, QueueConsumerHelper.from_proxy(rediscli, topics))
9696

9797
async with qc.watch() as records:
9898
async for record in records:
@@ -102,5 +102,5 @@ async with qc.watch() as records:
102102
## 安装
103103

104104
```bash
105-
pip install redisproxy
105+
pip install redishelper
106106
```

document/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# redisproxy
1+
# redishelper
22

33
提供redis客户端的代理对象功能.本项目代理的对象是[redis-py](https://github.com/redis/redis-py)中的四种客户端
44

document/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# -- Project information -----------------------------------------------------
1919

20-
project = 'redisproxy'
20+
project = 'redishelper'
2121
copyright = '2023, mac'
2222
author = 'mac'
2323

@@ -114,4 +114,4 @@ def setup(app):
114114
extensions.append('autoapi.extension')
115115
extensions.append("sphinx.ext.napoleon")
116116
autoapi_type = 'python'
117-
autoapi_dirs = ["/Users/mac/WORKSPACE/GITHUB/PythonTools/redisproxy/redisproxy"]
117+
autoapi_dirs = ["/Users/mac/WORKSPACE/GITHUB/PythonTools/redisproxy/redishelper"]

document/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Welcome to redisproxy's documentation!
1+
# Welcome to redishelper's documentation!
22

33
## 目录
44

redishelper/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from .proxy import RedisProxy
2+
from .channelconsumer import ChannelConsumerHelper
3+
from .channelproducer import ChannelProducerHelper
4+
from .queueconsumer import QueueConsumerHelper
5+
from .queueproducer import QueueProducerHelper
6+
from .streamconsumer import StreamConsumerHelper
7+
from .streamproducer import StreamProducerHelper
8+
9+
from .models import AutoOffsetReset, Acks, ConsumerRecord
10+
from .protocols import ConsumerProtocol, ProducerProtocol, AioConsumerProtocol, AioProducerProtocol, StreamProducerProtocol, AioStreamProducerProtocol

redisproxy/channelconsumer.py renamed to redishelper/channelconsumer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .models import ConsumerRecord
1111

1212

13-
class ChannelConsumerProxy(RedisProxy):
13+
class ChannelConsumerHelper(RedisProxy):
1414
__slots__ = ('instance', "_callbacks", "_instance_check", "_aio", "_cluster", "watch", "_topics")
1515

1616
def __init__(self, topics: str, *, url: Optional[str] = None, addresses: Optional[str] = None, aio: Optional[bool] = None,
@@ -70,7 +70,7 @@ def _watch_sync(self, channel: PubSub, timeout: int = 3) -> Generator[ConsumerRe
7070
yield record
7171

7272
@classmethod
73-
def from_proxy(clz, proxy: RedisProxy, topics: str) -> "ChannelConsumerProxy":
73+
def from_proxy(clz, proxy: RedisProxy, topics: str) -> "ChannelConsumerHelper":
7474
"""从RedisProxy实例创建代理.
7575
7676
Args:
@@ -89,7 +89,7 @@ def from_proxy(clz, proxy: RedisProxy, topics: str) -> "ChannelConsumerProxy":
8989

9090

9191
@asynccontextmanager
92-
async def _watch_async(self: ChannelConsumerProxy) -> AsyncGenerator[AsyncIterable[ConsumerRecord], None]:
92+
async def _watch_async(self: ChannelConsumerHelper) -> AsyncGenerator[AsyncIterable[ConsumerRecord], None]:
9393
if self.instance is None:
9494
raise NotImplemented
9595
try:
@@ -104,7 +104,7 @@ async def _watch_async(self: ChannelConsumerProxy) -> AsyncGenerator[AsyncIterab
104104

105105

106106
@contextmanager
107-
def _watch_sync(self: ChannelConsumerProxy) -> Generator[Iterable[ConsumerRecord], None, None]:
107+
def _watch_sync(self: ChannelConsumerHelper) -> Generator[Iterable[ConsumerRecord], None, None]:
108108
if self.instance is None:
109109
raise NotImplemented
110110
try:

redisproxy/channelproducer.py renamed to redishelper/channelproducer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from types import MethodType
88

99

10-
class ChannelProducerProxy(RedisProxy):
10+
class ChannelProducerHelper(RedisProxy):
1111
__slots__ = ('instance', "_callbacks", "_instance_check", "_aio", "_cluster", "mount")
1212

1313
def __init__(self, *, url: Optional[str] = None, addresses: Optional[str] = None, aio: Optional[bool] = None, **conn_params: Any) -> None:
@@ -38,7 +38,7 @@ def regist_methods(self, instance: Any) -> None:
3838
self.mount = MethodType(_mount_sync, self)
3939

4040
@classmethod
41-
def from_proxy(clz, proxy: RedisProxy) -> "ChannelProducerProxy":
41+
def from_proxy(clz, proxy: RedisProxy) -> "ChannelProducerHelper":
4242
"""从RedisProxy实例创建代理.
4343
4444
Args:
@@ -56,7 +56,7 @@ def from_proxy(clz, proxy: RedisProxy) -> "ChannelProducerProxy":
5656

5757

5858
@contextmanager
59-
def _mount_sync(self: ChannelProducerProxy) -> Generator[ChannelProducerProxy, None, None]:
59+
def _mount_sync(self: ChannelProducerHelper) -> Generator[ChannelProducerHelper, None, None]:
6060
if self.instance is None:
6161
raise NotImplemented
6262
try:
@@ -66,7 +66,7 @@ def _mount_sync(self: ChannelProducerProxy) -> Generator[ChannelProducerProxy, N
6666

6767

6868
@asynccontextmanager
69-
async def _mount_async(self: ChannelProducerProxy) -> AsyncGenerator[ChannelProducerProxy, None]:
69+
async def _mount_async(self: ChannelProducerHelper) -> AsyncGenerator[ChannelProducerHelper, None]:
7070
if self.instance is None:
7171
raise NotImplemented
7272
try:
File renamed without changes.
File renamed without changes.
File renamed without changes.

redisproxy/queueconsumer.py renamed to redishelper/queueconsumer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .models import ConsumerRecord
66

77

8-
class QueueConsumerProxy(RedisProxy):
8+
class QueueConsumerHelper(RedisProxy):
99
__slots__ = ('instance', "_callbacks", "_instance_check", "_aio", "_cluster", "watch", "_l2r", "_topics")
1010

1111
def __init__(self, topics: str, *, url: Optional[str] = None, addresses: Optional[str] = None, aio: Optional[bool] = None,
@@ -83,7 +83,7 @@ def _watch_sync(self, timeout: int = 3) -> Generator[ConsumerRecord, None, None]
8383

8484
@classmethod
8585
def from_proxy(clz, proxy: RedisProxy, topics: str, *,
86-
l2r: bool = False) -> "QueueConsumerProxy":
86+
l2r: bool = False) -> "QueueConsumerHelper":
8787
"""从RedisProxy实例创建代理.
8888
8989
Args:
@@ -103,7 +103,7 @@ def from_proxy(clz, proxy: RedisProxy, topics: str, *,
103103

104104

105105
@asynccontextmanager
106-
async def _watch_async(self: QueueConsumerProxy) -> AsyncGenerator[AsyncIterable[ConsumerRecord], None]:
106+
async def _watch_async(self: QueueConsumerHelper) -> AsyncGenerator[AsyncIterable[ConsumerRecord], None]:
107107
if self.instance is None:
108108
raise NotImplemented
109109
try:
@@ -113,7 +113,7 @@ async def _watch_async(self: QueueConsumerProxy) -> AsyncGenerator[AsyncIterable
113113

114114

115115
@contextmanager
116-
def _watch_sync(self: QueueConsumerProxy) -> Generator[Iterable[ConsumerRecord], None, None]:
116+
def _watch_sync(self: QueueConsumerHelper) -> Generator[Iterable[ConsumerRecord], None, None]:
117117
if self.instance is None:
118118
raise NotImplemented
119119
try:

redisproxy/queueproducer.py renamed to redishelper/queueproducer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from types import MethodType
55

66

7-
class QueueProducerProxy(RedisProxy):
7+
class QueueProducerHelper(RedisProxy):
88
__slots__ = ('instance', "_callbacks", "_instance_check", "_aio", "_cluster", "publish", "mount", "_l2r")
99

1010
def __init__(self, *, url: Optional[str] = None, addresses: Optional[str] = None, aio: Optional[bool] = None,
@@ -46,7 +46,7 @@ def l2r(self) -> bool:
4646

4747
@classmethod
4848
def from_proxy(clz, proxy: RedisProxy, *,
49-
l2r: bool = False) -> "QueueProducerProxy":
49+
l2r: bool = False) -> "QueueProducerHelper":
5050
"""从RedisProxy实例创建代理.
5151
5252
Args:
@@ -64,22 +64,22 @@ def from_proxy(clz, proxy: RedisProxy, *,
6464
return p
6565

6666

67-
async def _publish_async(self: QueueProducerProxy, topic: str, value: Union[str, bytes]) -> None:
67+
async def _publish_async(self: QueueProducerHelper, topic: str, value: Union[str, bytes]) -> None:
6868
if self._l2r:
6969
await self.instance.lpush(topic, value)
7070
else:
7171
await self.instance.rpush(topic, value)
7272

7373

74-
def _publish_sync(self: QueueProducerProxy, topic: str, value: Union[str, bytes]) -> None:
74+
def _publish_sync(self: QueueProducerHelper, topic: str, value: Union[str, bytes]) -> None:
7575
if self._l2r:
7676
self.instance.lpush(topic, value)
7777
else:
7878
self.instance.rpush(topic, value)
7979

8080

8181
@contextmanager
82-
def _mount_sync(self: QueueProducerProxy) -> Generator[QueueProducerProxy, None, None]:
82+
def _mount_sync(self: QueueProducerHelper) -> Generator[QueueProducerHelper, None, None]:
8383
if self.instance is None:
8484
raise NotImplemented
8585
try:
@@ -89,7 +89,7 @@ def _mount_sync(self: QueueProducerProxy) -> Generator[QueueProducerProxy, None,
8989

9090

9191
@asynccontextmanager
92-
async def _mount_async(self: QueueProducerProxy) -> AsyncGenerator[QueueProducerProxy, None]:
92+
async def _mount_async(self: QueueProducerHelper) -> AsyncGenerator[QueueProducerHelper, None]:
9393
if self.instance is None:
9494
raise NotImplemented
9595
try:

redisproxy/streamconsumer.py renamed to redishelper/streamconsumer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from redis.commands.core import AsyncDataAccessCommands, DataAccessCommands
1111

1212

13-
class StreamConsumerProxy(RedisProxy):
13+
class StreamConsumerHelper(RedisProxy):
1414
__slots__ = ('instance', "_callbacks", "_instance_check", "_aio", "_cluster", "watch", "_topics",
1515
"_auto_offset_reset", "_count", "_blocktime",
1616
"_client_id", "_group_id", "_ack")
@@ -203,7 +203,7 @@ def _watch_sync(self) -> Generator[ConsumerRecord, None, None]:
203203
@classmethod
204204
def from_proxy(clz, proxy: RedisProxy, topics: str, *,
205205
auto_offset_reset: AutoOffsetReset = AutoOffsetReset.latest, count: Optional[int] = 20, blocktime: Optional[int] = 1000,
206-
client_id: Optional[str] = None, group_id: Optional[str] = None, ack: Acks = Acks.after) -> "StreamConsumerProxy":
206+
client_id: Optional[str] = None, group_id: Optional[str] = None, ack: Acks = Acks.after) -> "StreamConsumerHelper":
207207
"""从RedisProxy实例创建代理.
208208
209209
Args:
@@ -228,7 +228,7 @@ def from_proxy(clz, proxy: RedisProxy, topics: str, *,
228228

229229

230230
@asynccontextmanager
231-
async def _watch_async(self: StreamConsumerProxy) -> AsyncGenerator[AsyncIterable[ConsumerRecord], None]:
231+
async def _watch_async(self: StreamConsumerHelper) -> AsyncGenerator[AsyncIterable[ConsumerRecord], None]:
232232
if self.instance is None:
233233
raise NotImplemented
234234
try:
@@ -238,7 +238,7 @@ async def _watch_async(self: StreamConsumerProxy) -> AsyncGenerator[AsyncIterabl
238238

239239

240240
@contextmanager
241-
def _watch_sync(self: StreamConsumerProxy) -> Generator[Iterable[ConsumerRecord], None, None]:
241+
def _watch_sync(self: StreamConsumerHelper) -> Generator[Iterable[ConsumerRecord], None, None]:
242242
if self.instance is None:
243243
raise NotImplemented
244244
try:

redisproxy/streamproducer.py renamed to redishelper/streamproducer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from types import MethodType
99

1010

11-
class StreamProducerProxy(RedisProxy):
11+
class StreamProducerHelper(RedisProxy):
1212
__slots__ = ('instance', "_callbacks", "_instance_check", "_aio", "_cluster", "mount", "publish", "_maxlen", "_approximate", "_nomkstream")
1313

1414
def __init__(self, *, url: Optional[str] = None, addresses: Optional[str] = None, aio: Optional[bool] = None,
@@ -48,7 +48,7 @@ def regist_methods(self, instance: Any) -> None:
4848
self.mount = MethodType(_mount_sync, self)
4949

5050
@classmethod
51-
def from_proxy(clz, proxy: RedisProxy, maxlen: Optional[int] = None, approximate: bool = True, nomkstream: bool = False) -> "StreamProducerProxy":
51+
def from_proxy(clz, proxy: RedisProxy, maxlen: Optional[int] = None, approximate: bool = True, nomkstream: bool = False) -> "StreamProducerHelper":
5252
"""从RedisProxy实例创建代理.
5353
5454
Args:
@@ -68,18 +68,18 @@ def from_proxy(clz, proxy: RedisProxy, maxlen: Optional[int] = None, approximate
6868
return p
6969

7070

71-
async def _publish_async(self: StreamProducerProxy, topic: str, value: Dict[str, str]) -> None:
71+
async def _publish_async(self: StreamProducerHelper, topic: str, value: Dict[str, str]) -> None:
7272
p = cast(AsyncDataAccessCommands, self.instance)
7373
await p.xadd(topic, value, maxlen=self._maxlen, approximate=self._approximate, nomkstream=self._nomkstream)
7474

7575

76-
def _publish_sync(self: StreamProducerProxy, topic: str, value: Dict[str, str]) -> None:
76+
def _publish_sync(self: StreamProducerHelper, topic: str, value: Dict[str, str]) -> None:
7777
p = cast(DataAccessCommands, self.instance)
7878
p.xadd(topic, value, maxlen=self._maxlen, approximate=self._approximate, nomkstream=self._nomkstream)
7979

8080

8181
@contextmanager
82-
def _mount_sync(self: StreamProducerProxy) -> Generator[StreamProducerProxy, None, None]:
82+
def _mount_sync(self: StreamProducerHelper) -> Generator[StreamProducerHelper, None, None]:
8383
if self.instance is None:
8484
raise NotImplemented
8585
try:
@@ -89,7 +89,7 @@ def _mount_sync(self: StreamProducerProxy) -> Generator[StreamProducerProxy, Non
8989

9090

9191
@asynccontextmanager
92-
async def _mount_async(self: StreamProducerProxy) -> AsyncGenerator[StreamProducerProxy, None]:
92+
async def _mount_async(self: StreamProducerHelper) -> AsyncGenerator[StreamProducerHelper, None]:
9393
if self.instance is None:
9494
raise NotImplemented
9595
try:
File renamed without changes.

redisproxy/__init__.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[metadata]
2-
name = redisproxy
2+
name = redishelper
33
version = 0.0.2
44
author = mac
55
author_email =
@@ -36,6 +36,6 @@ setup_requires =
3636

3737

3838
[options.packages.find]
39-
include = redisproxy
39+
include = redishelper
4040
exclude = tests
4141

test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from redis.commands.core import DataAccessCommands
2-
from redisproxy.proxy import RedisProxy
2+
from redishelper.proxy import RedisProxy
33
from typing import cast
44

55
rediscli = RedisProxy()

testaio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
from redis.commands.core import AsyncDataAccessCommands
3-
from redisproxy.proxy import RedisProxy
3+
from redishelper.proxy import RedisProxy
44
from typing import cast
55

66
rediscli = RedisProxy()

0 commit comments

Comments
 (0)