2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-04-22 08:40:22 +08:00

Add TaskKey helper

This commit is contained in:
Ken Hibino 2021-02-21 05:43:50 -08:00
parent fae6c4bdc8
commit 0b043318ba
2 changed files with 25 additions and 0 deletions

View File

@ -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)

View File

@ -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