IVS-876 - Django Management Command to display Redis Locks#301
Merged
Conversation
aothms
approved these changes
Jun 8, 2026
| def handle(self, *args, **options): | ||
|
|
||
| # Scan for keys matching the lock pattern | ||
| lock_pattern = "lock:celery:user:*:task:*" |
Collaborator
There was a problem hiding this comment.
I tried for a second or so to make this a bit more declarative like but I guess it's not worth it until we have a lot more of these patterns:
@dataclass
class placeholder:
name: str
def to_glob(self): return '*'
def to_re(self): return r'(?P<{self.name}>[^:]+)'
@dataclass
class query:
items : list
def to_glob(self): return ':'.join(i.to_glob() for i in self.items if not isinstance(i, str) else i)
def to_re(self): return re.compile(':'.join(i.to_re() for i in self.items if not isinstance(i, str) else i))
q = query(['lock', 'celery', 'user', placeholder('user_id'), 'task', palceholder('task_name')])
redis_client.keys(q.to_glob())
...
user_id, task_name = q.to_re().match(key).group('user_id', 'task_name')
...
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
display_user_locksExample: