async-task-worker 0.4.3__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. async_task_worker-0.5.0/.coveragerc +37 -0
  2. async_task_worker-0.4.3/README.md → async_task_worker-0.5.0/PKG-INFO +56 -1
  3. async_task_worker-0.4.3/PKG-INFO → async_task_worker-0.5.0/README.md +23 -22
  4. async_task_worker-0.5.0/pyproject.toml +142 -0
  5. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_cache/__init__.py +11 -20
  6. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_cache/adapters/__init__.py +1 -0
  7. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_cache/adapters/memory.py +6 -6
  8. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_cache/adapters/redis.py +23 -30
  9. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_cache/core.py +71 -68
  10. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_cache/exceptions.py +3 -0
  11. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_cache/key_utils.py +17 -16
  12. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_cache/serialization.py +15 -36
  13. async_task_worker-0.5.0/src/async_events/__init__.py +23 -0
  14. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_events/event_manager.py +4 -4
  15. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_events/sse_client.py +9 -16
  16. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/__init__.py +40 -40
  17. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/adapters/__init__.py +1 -1
  18. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/adapters/cache_adapter.py +54 -63
  19. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/api.py +29 -45
  20. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/core.py +62 -86
  21. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/exceptions.py +23 -43
  22. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/executor.py +61 -60
  23. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/futures.py +2 -6
  24. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/pool.py +31 -24
  25. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/queue.py +3 -8
  26. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/registry.py +2 -1
  27. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/src/async_task_worker/status.py +20 -18
  28. async_task_worker-0.5.0/uv.lock +839 -0
  29. async_task_worker-0.4.3/CLAUDE.md +0 -60
  30. async_task_worker-0.4.3/pyproject.toml +0 -84
  31. async_task_worker-0.4.3/src/async_events/__init__.py +0 -22
  32. async_task_worker-0.4.3/uv.lock +0 -416
  33. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/.gitignore +0 -0
  34. {async_task_worker-0.4.3 → async_task_worker-0.5.0}/LICENSE +0 -0
@@ -0,0 +1,37 @@
1
+ [run]
2
+ source =
3
+ src/async_events
4
+ src/async_task_worker
5
+ src/async_cache
6
+
7
+ omit =
8
+ */tests/*
9
+ */test_*
10
+ */__pycache__/*
11
+ */migrations/*
12
+ */.venv/*
13
+ */.env/*
14
+ setup.py
15
+
16
+ [report]
17
+ exclude_lines =
18
+ pragma: no cover
19
+ def __repr__
20
+ if self.debug:
21
+ if settings.DEBUG
22
+ raise AssertionError
23
+ raise NotImplementedError
24
+ if 0:
25
+ if __name__ == .__main__.:
26
+ class .*\bProtocol\):
27
+ @(abc\.)?abstractmethod
28
+
29
+ show_missing = True
30
+ skip_covered = False
31
+ precision = 2
32
+
33
+ [html]
34
+ directory = htmlcov
35
+
36
+ [xml]
37
+ output = coverage.xml
@@ -1,5 +1,45 @@
1
+ Metadata-Version: 2.5
2
+ Name: async-task-worker
3
+ Version: 0.5.0
4
+ Summary: Async Test Worker
5
+ Project-URL: Homepage, https://github.com/descoped/async-task-worker
6
+ Project-URL: Repository, https://github.com/descoped/async-task-worker
7
+ Project-URL: Issues, https://github.com/descoped/async-task-worker/issues
8
+ Author-email: Ove Ranheim <oranheim@gmail.com>
9
+ License-File: LICENSE
10
+ Keywords: asyncio,cache,processor,task,worker
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: msgpack>=1.2.4
21
+ Requires-Dist: pydantic>=2.14.4
22
+ Provides-Extra: all
23
+ Requires-Dist: fastapi>=0.165.1; extra == 'all'
24
+ Requires-Dist: httpx>=0.29.0; extra == 'all'
25
+ Requires-Dist: redis>=8.2.0; extra == 'all'
26
+ Provides-Extra: api
27
+ Requires-Dist: fastapi>=0.165.1; extra == 'api'
28
+ Provides-Extra: redis
29
+ Requires-Dist: redis>=8.2.0; extra == 'redis'
30
+ Provides-Extra: sse
31
+ Requires-Dist: httpx>=0.29.0; extra == 'sse'
32
+ Description-Content-Type: text/markdown
33
+
1
34
  # Async Task Worker
2
35
 
36
+ [![Build Status](https://github.com/descoped/async-task-worker/actions/workflows/build-test.yml/badge.svg)](https://github.com/descoped/async-task-worker/actions/workflows/build-test.yml)
37
+ [![Coverage](https://codecov.io/gh/descoped/async-task-worker/branch/master/graph/badge.svg)](https://codecov.io/gh/descoped/async-task-worker)
38
+ [![Python Version](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
39
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
40
+ [![Release](https://img.shields.io/github/v/release/descoped/async-task-worker)](https://github.com/descoped/async-task-worker/releases)
41
+ [![PyPI - Version](https://img.shields.io/pypi/v/async-task-worker?color=blue)](https://pypi.org/project/async-task-worker/)
42
+
3
43
  A robust asynchronous task worker system for Python applications with built-in caching support. This library provides a flexible framework for executing and managing background tasks with features like priority scheduling, progress tracking, and result caching.
4
44
 
5
45
  ## Installation
@@ -8,6 +48,21 @@ A robust asynchronous task worker system for Python applications with built-in c
8
48
  pip install async-task-worker
9
49
  ```
10
50
 
51
+ Optional features are installed as extras:
52
+
53
+ | Extra | Adds | Installs |
54
+ |---------|-------------------------------------------------|-----------|
55
+ | `api` | FastAPI router (`create_task_worker_router`) | fastapi |
56
+ | `redis` | Redis cache adapter (`RedisCacheAdapter`) | redis |
57
+ | `sse` | Server-Sent Events client (`async_events.SSEClient`) | httpx |
58
+ | `all` | All of the above | |
59
+
60
+ ```bash
61
+ pip install "async-task-worker[all]"
62
+ ```
63
+
64
+ Requires Python 3.11 or newer (tested on 3.11 to 3.15).
65
+
11
66
  ## Features
12
67
 
13
68
  - **Asynchronous Execution**: Built on Python's asyncio for efficient concurrent task processing
@@ -1019,7 +1074,7 @@ The AsyncTaskWorker library includes a FastAPI router that you can integrate int
1019
1074
  ### Install requirement
1020
1075
 
1021
1076
  ```bash
1022
- pip install fastapi
1077
+ pip install "async-task-worker[api]"
1023
1078
  ```
1024
1079
 
1025
1080
  ### Quick Start
@@ -1,26 +1,12 @@
1
- Metadata-Version: 2.4
2
- Name: async-task-worker
3
- Version: 0.4.3
4
- Summary: Async Test Worker
5
- Project-URL: Homepage, https://github.com/descoped/async-task-worker
6
- Project-URL: Repository, https://github.com/descoped/async-task-worker
7
- Project-URL: Issues, https://github.com/descoped/async-task-worker/issues
8
- Author-email: Ove Ranheim <oranheim@gmail.com>
9
- License-File: LICENSE
10
- Keywords: asyncio,cache,processor,task,worker
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Operating System :: OS Independent
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Programming Language :: Python :: 3.13
17
- Requires-Python: >=3.11
18
- Requires-Dist: msgpack>=1.1.0
19
- Requires-Dist: pydantic>=2.11.5
20
- Description-Content-Type: text/markdown
21
-
22
1
  # Async Task Worker
23
2
 
3
+ [![Build Status](https://github.com/descoped/async-task-worker/actions/workflows/build-test.yml/badge.svg)](https://github.com/descoped/async-task-worker/actions/workflows/build-test.yml)
4
+ [![Coverage](https://codecov.io/gh/descoped/async-task-worker/branch/master/graph/badge.svg)](https://codecov.io/gh/descoped/async-task-worker)
5
+ [![Python Version](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![Release](https://img.shields.io/github/v/release/descoped/async-task-worker)](https://github.com/descoped/async-task-worker/releases)
8
+ [![PyPI - Version](https://img.shields.io/pypi/v/async-task-worker?color=blue)](https://pypi.org/project/async-task-worker/)
9
+
24
10
  A robust asynchronous task worker system for Python applications with built-in caching support. This library provides a flexible framework for executing and managing background tasks with features like priority scheduling, progress tracking, and result caching.
25
11
 
26
12
  ## Installation
@@ -29,6 +15,21 @@ A robust asynchronous task worker system for Python applications with built-in c
29
15
  pip install async-task-worker
30
16
  ```
31
17
 
18
+ Optional features are installed as extras:
19
+
20
+ | Extra | Adds | Installs |
21
+ |---------|-------------------------------------------------|-----------|
22
+ | `api` | FastAPI router (`create_task_worker_router`) | fastapi |
23
+ | `redis` | Redis cache adapter (`RedisCacheAdapter`) | redis |
24
+ | `sse` | Server-Sent Events client (`async_events.SSEClient`) | httpx |
25
+ | `all` | All of the above | |
26
+
27
+ ```bash
28
+ pip install "async-task-worker[all]"
29
+ ```
30
+
31
+ Requires Python 3.11 or newer (tested on 3.11 to 3.15).
32
+
32
33
  ## Features
33
34
 
34
35
  - **Asynchronous Execution**: Built on Python's asyncio for efficient concurrent task processing
@@ -1040,7 +1041,7 @@ The AsyncTaskWorker library includes a FastAPI router that you can integrate int
1040
1041
  ### Install requirement
1041
1042
 
1042
1043
  ```bash
1043
- pip install fastapi
1044
+ pip install "async-task-worker[api]"
1044
1045
  ```
1045
1046
 
1046
1047
  ### Quick Start
@@ -0,0 +1,142 @@
1
+ [project]
2
+ name = "async-task-worker"
3
+ version = "0.5.0"
4
+ description = "Async Test Worker"
5
+ authors = [
6
+ { name = "Ove Ranheim", email = "oranheim@gmail.com" }
7
+ ]
8
+ requires-python = ">=3.11"
9
+ readme = "README.md"
10
+ keywords = ["asyncio", "worker", "task", "processor", "cache"]
11
+ classifiers = [
12
+ "Programming Language :: Python :: 3",
13
+ "Programming Language :: Python :: 3.11",
14
+ "Programming Language :: Python :: 3.12",
15
+ "Programming Language :: Python :: 3.13",
16
+ "Programming Language :: Python :: 3.14",
17
+ "Programming Language :: Python :: 3.15",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ ]
21
+ dependencies = [
22
+ "msgpack>=1.2.4",
23
+ "pydantic>=2.14.4",
24
+ ]
25
+
26
+ [project.optional-dependencies]
27
+ api = ["fastapi>=0.165.1"]
28
+ redis = ["redis>=8.2.0"]
29
+ sse = ["httpx>=0.29.0"]
30
+ all = ["async-task-worker[api,redis,sse]"]
31
+
32
+ [dependency-groups]
33
+ dev = [
34
+ "async-task-worker[all]",
35
+ "ruff>=0.17.6",
36
+ ]
37
+ test = [
38
+ "httpx2>=2.17.0",
39
+ "pytest>=9.2.0",
40
+ "pytest-asyncio>=1.5.0",
41
+ "pytest-cov>=7.1.0",
42
+ "pyyaml>=6.0.4",
43
+ ]
44
+
45
+ [tool.pytest.ini_options]
46
+ pythonpath = ["src", "tests"]
47
+ testpaths = ["tests"]
48
+ python_files = ["test_*.py"]
49
+ asyncio_mode = "auto"
50
+ asyncio_default_fixture_loop_scope = "function"
51
+ markers = [
52
+ "asyncio: mark test as async",
53
+ "integration: mark test as integration test",
54
+ ]
55
+ addopts = "-m 'not integration'"
56
+
57
+ [build-system]
58
+ requires = ["hatchling>=1.33.0"]
59
+ build-backend = "hatchling.build"
60
+
61
+ [tool.hatch.build.targets.wheel]
62
+ packages = ["src/async_events", "src/async_task_worker", "src/async_cache"]
63
+
64
+ [tool.hatch.build]
65
+ exclude = [
66
+ "docs/*",
67
+ "examples/*",
68
+ "tests/*",
69
+ ".github/*",
70
+ "*.gif",
71
+ "*.png",
72
+ "dist/*",
73
+ "build/*",
74
+ ".pytest_cache",
75
+ ".ruff_cache",
76
+ "__pycache__",
77
+ "*.pyc"
78
+ ]
79
+
80
+ [project.urls]
81
+ Homepage = "https://github.com/descoped/async-task-worker"
82
+ Repository = "https://github.com/descoped/async-task-worker"
83
+ Issues = "https://github.com/descoped/async-task-worker/issues"
84
+
85
+ [[tool.uv.index]]
86
+ name = "pypi"
87
+ url = "https://pypi.org/simple/"
88
+ publish-url = "https://upload.pypi.org/legacy/"
89
+
90
+ [[tool.uv.index]]
91
+ name = "testpypi"
92
+ url = "https://test.pypi.org/simple/"
93
+ publish-url = "https://test.pypi.org/legacy/"
94
+
95
+
96
+ [tool.ruff]
97
+ # Target Python 3.11+
98
+ target-version = "py311"
99
+ # Modern line length for readability
100
+ line-length = 120
101
+ # Include all Python files
102
+ include = ["*.py", "*.pyi", "**/pyproject.toml"]
103
+
104
+ [tool.ruff.lint]
105
+ # Only select rules that catch real errors/bugs that should block builds
106
+ select = [
107
+ "E9", # Runtime errors (syntax errors, indentation errors)
108
+ "F63", # Invalid print syntax
109
+ "F7", # Syntax errors
110
+ "I", # Import sorting
111
+ ]
112
+
113
+ # Ignore common architectural patterns and forward references
114
+ ignore = [
115
+ "E402", # Module level import not at top (needed for circular import avoidance)
116
+ "E501", # Line length (handled by formatter)
117
+ "E722", # Bare except (sometimes intentional)
118
+ "F821", # Undefined name (forward references in type annotations)
119
+ ]
120
+
121
+ # Allow autofix for all enabled rules
122
+ fixable = ["ALL"]
123
+ unfixable = []
124
+
125
+ [tool.ruff.lint.per-file-ignores]
126
+ # Test files can have unused imports
127
+ "tests/*" = ["F401"]
128
+ # Examples can be more relaxed
129
+ "examples/*" = ["F401", "F841"]
130
+
131
+ [tool.ruff.lint.isort]
132
+ # Group imports cleanly
133
+ combine-as-imports = true
134
+ force-wrap-aliases = true
135
+
136
+ [tool.ruff.format]
137
+ # Use double quotes for strings
138
+ quote-style = "double"
139
+ # Indent with spaces
140
+ indent-style = "space"
141
+ # Unix line endings
142
+ line-ending = "lf"
@@ -1,13 +1,22 @@
1
1
  """Async Cache - A flexible asynchronous caching system."""
2
2
 
3
3
  # Core components
4
+ # Adapters
5
+ from async_cache.adapters import MemoryCacheAdapter
4
6
  from async_cache.core import AsyncCache, CacheAdapter
5
7
 
8
+ # Exceptions
9
+ from async_cache.exceptions import (
10
+ CacheError,
11
+ InvalidCacheKeyError,
12
+ SerializationError,
13
+ )
14
+
6
15
  # Key utilities
7
16
  from async_cache.key_utils import (
17
+ CacheKeyComponent,
8
18
  CacheKeyContext,
9
19
  CacheKeyFn,
10
- CacheKeyComponent,
11
20
  compose_key_functions,
12
21
  extract_key_component,
13
22
  key_component,
@@ -16,24 +25,14 @@ from async_cache.key_utils import (
16
25
  # Serialization
17
26
  from async_cache.serialization import MsgPackSerializer
18
27
 
19
- # Exceptions
20
- from async_cache.exceptions import (
21
- CacheError,
22
- SerializationError,
23
- InvalidCacheKeyError,
24
- )
25
-
26
- # Adapters
27
- from async_cache.adapters import MemoryCacheAdapter
28
-
29
28
  # Try to import Redis adapter if available
30
29
  try:
31
30
  from async_cache.adapters import RedisCacheAdapter
31
+
32
32
  __all__ = [
33
33
  # Core
34
34
  "AsyncCache",
35
35
  "CacheAdapter",
36
-
37
36
  # Key utils
38
37
  "CacheKeyContext",
39
38
  "CacheKeyFn",
@@ -41,15 +40,12 @@ try:
41
40
  "compose_key_functions",
42
41
  "extract_key_component",
43
42
  "key_component",
44
-
45
43
  # Serialization
46
44
  "MsgPackSerializer",
47
-
48
45
  # Exceptions
49
46
  "CacheError",
50
47
  "SerializationError",
51
48
  "InvalidCacheKeyError",
52
-
53
49
  # Adapters
54
50
  "MemoryCacheAdapter",
55
51
  "RedisCacheAdapter",
@@ -60,7 +56,6 @@ except ImportError:
60
56
  # Core
61
57
  "AsyncCache",
62
58
  "CacheAdapter",
63
-
64
59
  # Key utils
65
60
  "CacheKeyContext",
66
61
  "CacheKeyFn",
@@ -68,16 +63,12 @@ except ImportError:
68
63
  "compose_key_functions",
69
64
  "extract_key_component",
70
65
  "key_component",
71
-
72
66
  # Serialization
73
67
  "MsgPackSerializer",
74
-
75
68
  # Exceptions
76
69
  "CacheError",
77
70
  "SerializationError",
78
71
  "InvalidCacheKeyError",
79
-
80
72
  # Adapters
81
73
  "MemoryCacheAdapter",
82
74
  ]
83
-
@@ -5,6 +5,7 @@ from async_cache.adapters.memory import MemoryCacheAdapter
5
5
  # Try to import Redis adapter if redis is available
6
6
  try:
7
7
  from async_cache.adapters.redis import RedisCacheAdapter
8
+
8
9
  __all__ = ["MemoryCacheAdapter", "RedisCacheAdapter"]
9
10
  except ImportError:
10
11
  # Redis package is not installed
@@ -33,10 +33,10 @@ class MemoryCacheAdapter(CacheAdapter):
33
33
  async def get(self, key: str) -> Tuple[bool, Any]:
34
34
  """
35
35
  Get a value from the cache with TTL support.
36
-
36
+
37
37
  Args:
38
38
  key: The cache key
39
-
39
+
40
40
  Returns:
41
41
  Tuple of (hit, value) where hit is True if the item was in cache and not expired
42
42
  """
@@ -62,7 +62,7 @@ class MemoryCacheAdapter(CacheAdapter):
62
62
  async def set(self, key: str, value: Any, ttl: Optional[int] = None) -> None:
63
63
  """
64
64
  Set a value in the cache with TTL support.
65
-
65
+
66
66
  Args:
67
67
  key: The cache key
68
68
  value: The value to store
@@ -85,10 +85,10 @@ class MemoryCacheAdapter(CacheAdapter):
85
85
  async def delete(self, key: str) -> bool:
86
86
  """
87
87
  Delete a value from the cache.
88
-
88
+
89
89
  Args:
90
90
  key: The cache key
91
-
91
+
92
92
  Returns:
93
93
  True if deleted, False if not found
94
94
  """
@@ -108,7 +108,7 @@ class MemoryCacheAdapter(CacheAdapter):
108
108
  def _evict_one(self) -> None:
109
109
  """
110
110
  Evict the least recently used item from the cache.
111
-
111
+
112
112
  Note: This method should only be called with the lock held.
113
113
  """
114
114
  if not self._access_times:
@@ -2,7 +2,7 @@
2
2
  Redis cache adapter for the async_cache package.
3
3
 
4
4
  Provides a caching implementation that uses Redis as the backend.
5
- Requires the 'redis' package to be installed (available with 'async-cache[redis]').
5
+ Requires the 'redis' package to be installed (available with 'async-task-worker[redis]').
6
6
  """
7
7
 
8
8
  import logging
@@ -22,27 +22,27 @@ logger = logging.getLogger(__name__)
22
22
  class RedisCacheAdapter(CacheAdapter):
23
23
  """
24
24
  Redis-based cache adapter.
25
-
25
+
26
26
  Uses Redis for distributed caching with TTL support.
27
-
27
+
28
28
  Note:
29
29
  Requires the 'redis' package: pip install async-cache[redis]
30
30
  """
31
31
 
32
32
  def __init__(
33
- self,
34
- host: str = "localhost",
35
- port: int = 6379,
36
- db: int = 0,
37
- password: Optional[str] = None,
38
- key_prefix: str = "async_cache:",
39
- connection_pool: Optional[Any] = None,
40
- client: Optional[Any] = None,
41
- **redis_kwargs
33
+ self,
34
+ host: str = "localhost",
35
+ port: int = 6379,
36
+ db: int = 0,
37
+ password: Optional[str] = None,
38
+ key_prefix: str = "async_cache:",
39
+ connection_pool: Optional[Any] = None,
40
+ client: Optional[Any] = None,
41
+ **redis_kwargs,
42
42
  ):
43
43
  """
44
44
  Initialize Redis cache adapter.
45
-
45
+
46
46
  Args:
47
47
  host: Redis host address
48
48
  port: Redis port number
@@ -52,14 +52,13 @@ class RedisCacheAdapter(CacheAdapter):
52
52
  connection_pool: Optional existing Redis connection pool
53
53
  client: Optional existing Redis client instance
54
54
  **redis_kwargs: Additional arguments to pass to Redis client
55
-
55
+
56
56
  Raises:
57
57
  ImportError: If redis package is not installed
58
58
  """
59
59
  if redis is None:
60
60
  raise ImportError(
61
- "Redis adapter requires the 'redis' package. "
62
- "Install with 'pip install async-cache[redis]'"
61
+ "Redis adapter requires the 'redis' package. Install with 'pip install async-cache[redis]'"
63
62
  )
64
63
 
65
64
  self.key_prefix = key_prefix
@@ -71,13 +70,7 @@ class RedisCacheAdapter(CacheAdapter):
71
70
  if connection_pool:
72
71
  self.redis = redis.Redis(connection_pool=connection_pool, **redis_kwargs)
73
72
  else:
74
- self.redis = redis.Redis(
75
- host=host,
76
- port=port,
77
- db=db,
78
- password=password,
79
- **redis_kwargs
80
- )
73
+ self.redis = redis.Redis(host=host, port=port, db=db, password=password, **redis_kwargs)
81
74
 
82
75
  def _prefixed_key(self, key: str) -> str:
83
76
  """Add the prefix to a cache key."""
@@ -86,10 +79,10 @@ class RedisCacheAdapter(CacheAdapter):
86
79
  async def get(self, key: str) -> Tuple[bool, Any]:
87
80
  """
88
81
  Get a value from the Redis cache.
89
-
82
+
90
83
  Args:
91
84
  key: The cache key
92
-
85
+
93
86
  Returns:
94
87
  Tuple of (hit, value) where hit is True if the item was in cache
95
88
  """
@@ -111,7 +104,7 @@ class RedisCacheAdapter(CacheAdapter):
111
104
  async def set(self, key: str, value: Any, ttl: Optional[int] = None) -> None:
112
105
  """
113
106
  Set a value in the Redis cache.
114
-
107
+
115
108
  Args:
116
109
  key: The cache key
117
110
  value: The value to store
@@ -133,10 +126,10 @@ class RedisCacheAdapter(CacheAdapter):
133
126
  async def delete(self, key: str) -> bool:
134
127
  """
135
128
  Delete a value from the Redis cache.
136
-
129
+
137
130
  Args:
138
131
  key: The cache key
139
-
132
+
140
133
  Returns:
141
134
  True if deleted, False if not found
142
135
  """
@@ -151,7 +144,7 @@ class RedisCacheAdapter(CacheAdapter):
151
144
  async def clear(self) -> None:
152
145
  """
153
146
  Clear all items from the cache with the configured prefix.
154
-
147
+
155
148
  Note: This only clears keys with the specified prefix for safety.
156
149
  """
157
150
  try:
@@ -173,7 +166,7 @@ class RedisCacheAdapter(CacheAdapter):
173
166
  async def close(self) -> None:
174
167
  """
175
168
  Close the Redis connection.
176
-
169
+
177
170
  This should be called when the adapter is no longer needed.
178
171
  """
179
172
  try: