-
Notifications
You must be signed in to change notification settings - Fork 32
🎨 Use async redis client #7443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sanderegg
merged 20 commits into
ITISFoundation:master
from
bisgaard-itis:romeo-use-async-redis-client
Mar 27, 2025
Merged
🎨 Use async redis client #7443
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
32be5a5
use async redis client
giancarloromeo 5e0a95e
fix client
giancarloromeo b54a48e
fix setup
giancarloromeo 1d68a6c
remove timeout
giancarloromeo c605724
remove revoked
giancarloromeo 84315ea
clean
giancarloromeo 7800e4b
remove inspect
giancarloromeo 4e959a6
add hack
giancarloromeo ec2b890
add task store protocol
giancarloromeo d9caa19
Merge remote-tracking branch 'upstream/master' into use-async-redis-c…
giancarloromeo 8783d33
remove self
giancarloromeo b23966e
fix exists
giancarloromeo 4e662ea
remove unused
giancarloromeo ca89852
remove unused
giancarloromeo 4a06f20
Merge branch 'master' into use-async-redis-client
giancarloromeo e3a4741
fix test
bisgaard-itis a4990b6
bugfix
bisgaard-itis bf43e78
@sanderegg fix relative import
bisgaard-itis c787a1f
@sanderegg readd log_context
bisgaard-itis 51bd9f2
Merge branch 'master' into romeo-use-async-redis-client
bisgaard-itis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
41 changes: 41 additions & 0 deletions
41
services/storage/src/simcore_service_storage/modules/celery/backends/_redis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| from typing import Final | ||
|
|
||
| from servicelib.redis._client import RedisClientSDK | ||
|
|
||
| from ..models import TaskContext, TaskData, TaskID, TaskUUID, build_task_id_prefix | ||
|
|
||
| _CELERY_TASK_META_PREFIX: Final[str] = "celery-task-meta-" | ||
| _CELERY_TASK_ID_KEY_SEPARATOR: Final[str] = ":" | ||
| _CELERY_TASK_SCAN_COUNT_PER_BATCH: Final[int] = 10000 | ||
| _CELERY_TASK_ID_KEY_ENCODING = "utf-8" | ||
|
|
||
|
|
||
| class RedisTaskStore: | ||
| def __init__(self, redis_client_sdk: RedisClientSDK) -> None: | ||
| self._redis_client_sdk = redis_client_sdk | ||
|
|
||
| async def get_task_uuids(self, task_context: TaskContext) -> set[TaskUUID]: | ||
| search_key = build_task_id_prefix(task_context) + _CELERY_TASK_ID_KEY_SEPARATOR | ||
| keys = set() | ||
| async for key in self._redis_client_sdk.redis.scan_iter( | ||
| match=search_key + "*", count=_CELERY_TASK_SCAN_COUNT_PER_BATCH | ||
| ): | ||
| # fake redis (tests) returns bytes, real redis returns str | ||
| _key = ( | ||
| key.decode(_CELERY_TASK_ID_KEY_ENCODING) | ||
| if isinstance(key, bytes) | ||
| else key | ||
| ) | ||
| keys.add(TaskUUID(_key.removeprefix(search_key))) | ||
| return keys | ||
|
|
||
| async def task_exists(self, task_id: TaskID) -> bool: | ||
| n = await self._redis_client_sdk.redis.exists(task_id) | ||
| assert isinstance(n, int) # nosec | ||
| return n > 0 | ||
|
|
||
| async def set_task(self, task_id: TaskID, task_data: TaskData) -> None: | ||
| await self._redis_client_sdk.redis.set( | ||
| task_id, | ||
| task_data.model_dump_json(), | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.