2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-25 23:06:12 +08:00

Merge pull request #5 from 22dm/custom-unique-key

feat: add custom unique key option
This commit is contained in:
徐胖
2022-07-19 15:29:53 +08:00
committed by GitHub
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))