diff --git a/internal/base/base.go b/internal/base/base.go index 7ca5c23..8a41f4c 100644 --- a/internal/base/base.go +++ b/internal/base/base.go @@ -45,6 +45,11 @@ func ValidateQueueName(qname string) error { return nil } +// TaskKey returns a redis key for the given task message. +func TaskKey(qname string, id uuid.UUID) string { + return fmt.Sprintf("asynq:{%s}:t:%s", qname, id) +} + // PendingKey returns a redis key for the given queue name. func PendingKey(qname string) string { return fmt.Sprintf("asynq:{%s}:pending", qname) diff --git a/internal/base/base_test.go b/internal/base/base_test.go index 71642f8..1787d93 100644 --- a/internal/base/base_test.go +++ b/internal/base/base_test.go @@ -7,6 +7,7 @@ package base import ( "context" "encoding/json" + "fmt" "sync" "testing" "time" @@ -15,6 +16,25 @@ import ( "github.com/google/uuid" ) +func TestTaskKey(t *testing.T) { + id := uuid.New() + + tests := []struct { + qname string + id uuid.UUID + want string + }{ + {"default", id, fmt.Sprintf("asynq:{default}:t:%s", id)}, + } + + for _, tc := range tests { + got := TaskKey(tc.qname, tc.id) + if got != tc.want { + t.Errorf("TaskKey(%q, %s) = %q, want %q", tc.qname, tc.id, got, tc.want) + } + } +} + func TestQueueKey(t *testing.T) { tests := []struct { qname string