|
1 | 1 | # type: ignore
|
2 | 2 | from typing import Any, Tuple
|
| 3 | +from yatq.py_version import AIOREDIS_USE |
3 | 4 |
|
4 |
| -import aioredis |
| 5 | +if AIOREDIS_USE: |
| 6 | + import aioredis |
5 | 7 |
|
6 |
| -if aioredis.__version__ >= "2.0": # pragma: no cover |
7 |
| - from aioredis.exceptions import NoScriptError |
| 8 | + if aioredis.__version__ >= "2.0": |
| 9 | + from aioredis.exceptions import NoScriptError |
8 | 10 |
|
9 |
| - async def eval_sha( |
10 |
| - client: aioredis.Redis, digest: str, args: Tuple[Any] |
11 |
| - ): # pragma: no cover |
12 |
| - return await client.evalsha(digest, 0, *args) |
| 11 | + async def eval_sha( |
| 12 | + client: aioredis.Redis, digest: str, args: Tuple[Any] |
| 13 | + ): # pragma: no cover |
| 14 | + return await client.evalsha(digest, 0, *args) |
13 | 15 |
|
14 |
| -else: # pragma: no cover |
15 |
| - from aioredis.errors import ReplyError |
| 16 | + else: # pragma: no cover |
| 17 | + from aioredis.errors import ReplyError |
16 | 18 |
|
17 |
| - class NoScriptError(ReplyError): |
18 |
| - ... |
| 19 | + class NoScriptError(ReplyError): |
| 20 | + ... |
| 21 | + |
| 22 | + async def eval_sha( |
| 23 | + client: aioredis.Redis, digest: str, args: Tuple[Any] |
| 24 | + ): # pragma: no cover |
| 25 | + try: |
| 26 | + return await client.evalsha(digest, keys=[], args=list(args)) |
| 27 | + except ReplyError as error: |
| 28 | + if error.args[0].startswith("NOSCRIPT"): |
| 29 | + raise NoScriptError(error.args[0]) |
| 30 | + raise |
| 31 | + |
| 32 | +else: # pragma: no cover |
| 33 | + from redis import asyncio as aioredis |
| 34 | + from redis.exceptions import NoScriptError |
19 | 35 |
|
20 | 36 | async def eval_sha(
|
21 | 37 | client: aioredis.Redis, digest: str, args: Tuple[Any]
|
22 | 38 | ): # pragma: no cover
|
23 |
| - try: |
24 |
| - return await client.evalsha(digest, keys=[], args=list(args)) |
25 |
| - except ReplyError as error: |
26 |
| - if error.args[0].startswith("NOSCRIPT"): |
27 |
| - raise NoScriptError(error.args[0]) |
28 |
| - raise |
| 39 | + return await client.execute_command("EVALSHA", digest, 0, *args) |
0 commit comments