Skip to content

Commit 1ea03e1

Browse files
committed
remove hashtag (in favor of optional keyprefix hashing)
1 parent 02db979 commit 1ea03e1

1 file changed

Lines changed: 3 additions & 18 deletions

File tree

backend/valkey/queue.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ type taskQueue[T any] struct {
2727
groupName string
2828
workerName string
2929
queueSetKey string
30-
// hashTag is a Valkey Cluster hash tag ensuring all keys used together
31-
// (across different queues for the same task type) map to the same slot.
32-
// This avoids CrossSlot errors when Valkey is running in clustered/serverless modes
33-
// and XREADGROUP is called on multiple stream keys.
34-
hashTag string
3530
}
3631

3732
type TaskItem[T any] struct {
@@ -60,22 +55,12 @@ func newTaskQueue[T any](keyPrefix, tasktype, workerName string) (*taskQueue[T],
6055
workerName = uuid.NewString()
6156
}
6257

63-
// Use a stable Valkey Cluster hash tag so that all keys for this task type
64-
// hash to the same slot regardless of the specific queue name. Only the
65-
// substring within {...} is used for hashing.
66-
// Example generated keys:
67-
// <prefix>{task:<tasktype>}:task-stream:<queue>
68-
// <prefix>{task:<tasktype>}:task-set:<queue>
69-
// <prefix>{task:<tasktype>}:<tasktype>:queues
70-
hashTag := fmt.Sprintf("{task:%s}", tasktype)
71-
7258
tq := &taskQueue[T]{
7359
keyPrefix: keyPrefix,
7460
tasktype: tasktype,
7561
groupName: "task-workers",
7662
workerName: workerName,
77-
queueSetKey: fmt.Sprintf("%s%s:%s:queues", keyPrefix, hashTag, tasktype),
78-
hashTag: hashTag,
63+
queueSetKey: fmt.Sprintf("%s%s:queues", keyPrefix, tasktype),
7964
}
8065

8166
// Load all Lua scripts
@@ -106,8 +91,8 @@ func (q *taskQueue[T]) Prepare(ctx context.Context, client valkey.Client, queues
10691

10792
func (q *taskQueue[T]) Keys(queue workflow.Queue) KeyInfo {
10893
return KeyInfo{
109-
StreamKey: fmt.Sprintf("%s%s:task-stream:%s", q.keyPrefix, q.hashTag, queue),
110-
SetKey: fmt.Sprintf("%s%s:task-set:%s", q.keyPrefix, q.hashTag, queue),
94+
StreamKey: fmt.Sprintf("%stask-stream:%s:%s", q.keyPrefix, queue, q.tasktype),
95+
SetKey: fmt.Sprintf("%stask-set:%s:%s", q.keyPrefix, queue, q.tasktype),
11196
}
11297
}
11398

0 commit comments

Comments
 (0)