@@ -175,52 +175,63 @@ impl<H: DurableExecution> Queue<H> {
175175 & self . name
176176 }
177177
178+ /// Redis Cluster hash tag used to keep all queue keys in the same slot.
179+ /// See: https://redis.io/docs/latest/operate/oss_and_stack/reference/cluster-spec/#hash-tags
180+ fn redis_hash_tag ( & self ) -> String {
181+ format ! ( "{{{}}}" , self . name( ) )
182+ }
183+
178184 pub fn pending_list_name ( & self ) -> String {
179- format ! ( "twmq:{}:pending" , self . name ( ) )
185+ format ! ( "twmq:{}:pending" , self . redis_hash_tag ( ) )
180186 }
181187
182188 pub fn active_hash_name ( & self ) -> String {
183- format ! ( "twmq:{}:active" , self . name )
189+ format ! ( "twmq:{}:active" , self . redis_hash_tag ( ) )
184190 }
185191
186192 pub fn delayed_zset_name ( & self ) -> String {
187- format ! ( "twmq:{}:delayed" , self . name )
193+ format ! ( "twmq:{}:delayed" , self . redis_hash_tag ( ) )
188194 }
189195
190196 pub fn success_list_name ( & self ) -> String {
191- format ! ( "twmq:{}:success" , self . name )
197+ format ! ( "twmq:{}:success" , self . redis_hash_tag ( ) )
192198 }
193199
194200 pub fn failed_list_name ( & self ) -> String {
195- format ! ( "twmq:{}:failed" , self . name )
201+ format ! ( "twmq:{}:failed" , self . redis_hash_tag ( ) )
196202 }
197203
198204 pub fn job_data_hash_name ( & self ) -> String {
199- format ! ( "twmq:{}:jobs:data" , self . name )
205+ format ! ( "twmq:{}:jobs:data" , self . redis_hash_tag ( ) )
200206 }
201207
202208 pub fn job_meta_hash_name ( & self , job_id : & str ) -> String {
203- format ! ( "twmq:{}:job:{}:meta" , self . name , job_id)
209+ format ! ( "twmq:{}:job:{}:meta" , self . redis_hash_tag ( ) , job_id)
204210 }
205211
206212 pub fn job_errors_list_name ( & self , job_id : & str ) -> String {
207- format ! ( "twmq:{}:job:{}:errors" , self . name , job_id)
213+ format ! ( "twmq:{}:job:{}:errors" , self . redis_hash_tag ( ) , job_id)
208214 }
209215
210216 pub fn job_result_hash_name ( & self ) -> String {
211- format ! ( "twmq:{}:jobs:result" , self . name )
217+ format ! ( "twmq:{}:jobs:result" , self . redis_hash_tag ( ) )
212218 }
213219
214220 pub fn dedupe_set_name ( & self ) -> String {
215- format ! ( "twmq:{}:dedup" , self . name )
221+ format ! ( "twmq:{}:dedup" , self . redis_hash_tag ( ) )
216222 }
217223
218224 pub fn pending_cancellation_set_name ( & self ) -> String {
219- format ! ( "twmq:{}:pending_cancellations" , self . name )
225+ format ! ( "twmq:{}:pending_cancellations" , self . redis_hash_tag ( ) )
220226 }
221227
222228 pub fn lease_key_name ( & self , job_id : & str , lease_token : & str ) -> String {
223- format ! ( "twmq:{}:job:{}:lease:{}" , self . name, job_id, lease_token)
229+ format ! (
230+ "twmq:{}:job:{}:lease:{}" ,
231+ self . redis_hash_tag( ) ,
232+ job_id,
233+ lease_token
234+ )
224235 }
225236
226237 pub async fn push (
@@ -301,7 +312,8 @@ impl<H: DurableExecution> Queue<H> {
301312 let position_string = delay. position . to_string ( ) ;
302313
303314 let _result: ( i32 , String ) = script
304- . key ( & self . name )
315+ // Redis Cluster: all KEYS must be in the same slot
316+ . key ( self . redis_hash_tag ( ) )
305317 . key ( self . delayed_zset_name ( ) )
306318 . key ( self . pending_list_name ( ) )
307319 . key ( self . job_data_hash_name ( ) )
@@ -742,7 +754,8 @@ impl<H: DurableExecution> Queue<H> {
742754 Vec < String > ,
743755 Vec < String > ,
744756 ) = script
745- . key ( self . name ( ) )
757+ // Redis Cluster: all KEYS must be in the same slot
758+ . key ( self . redis_hash_tag ( ) )
746759 . key ( self . delayed_zset_name ( ) )
747760 . key ( self . pending_list_name ( ) )
748761 . key ( self . active_hash_name ( ) )
@@ -990,7 +1003,8 @@ impl<H: DurableExecution> Queue<H> {
9901003 ) ;
9911004
9921005 let trimmed_count: usize = trim_script
993- . key ( self . name ( ) )
1006+ // Redis Cluster: all KEYS must be in the same slot
1007+ . key ( self . redis_hash_tag ( ) )
9941008 . key ( self . success_list_name ( ) )
9951009 . key ( self . job_data_hash_name ( ) )
9961010 . key ( self . job_result_hash_name ( ) ) // results_hash
@@ -1168,7 +1182,8 @@ impl<H: DurableExecution> Queue<H> {
11681182 ) ;
11691183
11701184 let trimmed_count: usize = trim_script
1171- . key ( self . name ( ) )
1185+ // Redis Cluster: all KEYS must be in the same slot
1186+ . key ( self . redis_hash_tag ( ) )
11721187 . key ( self . failed_list_name ( ) )
11731188 . key ( self . job_data_hash_name ( ) )
11741189 . key ( self . dedupe_set_name ( ) )
0 commit comments