2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-20 09:16:12 +08:00

feat: add custom unique key option

This commit is contained in:
nyako
2022-06-24 14:55:53 +08:00
parent a04ba6411d
commit 519985f195
4 changed files with 85 additions and 2 deletions

View File

@@ -205,6 +205,12 @@ func UniqueKey(qname, tasktype string, payload []byte) string {
return fmt.Sprintf("%sunique:%s:%s", QueueKeyPrefix(qname), tasktype, hex.EncodeToString(checksum[:]))
}
// CustomUniqueKey returns a redis key with the given type, custom key, and queue name.
func CustomUniqueKey(qname, tasktype string, customKey string) string {
checksum := md5.Sum([]byte(customKey))
return fmt.Sprintf("%sunique:%s:%s", QueueKeyPrefix(qname), tasktype, hex.EncodeToString(checksum[:]))
}
// GroupKeyPrefix returns a prefix for group key.
func GroupKeyPrefix(qname string) string {
return fmt.Sprintf("%sg:", QueueKeyPrefix(qname))