1919 ErrInvalidReadArgs = errors .New ("queue: invalid read arguments" )
2020 ErrInvalidWriteArgs = errors .New ("queue: invalid write arguments" )
2121 ErrNoMatchingMessageInStream = errors .New ("queue: no matching message in stream" )
22+ ErrInvalidMetaCancelation = errors .New ("queue: invalid meta cancelation" )
2223
2324 streamSuffixPattern = regexp .MustCompile (`\A:s(\d+)\z` )
2425)
@@ -51,6 +52,16 @@ func (c *Client) Prepare(ctx context.Context) error {
5152 return prepare (ctx , c .rdb )
5253}
5354
55+ // GC performs all garbage collection operations that cannot be automatically
56+ // performed via key expiry.
57+ func (c * Client ) GC (ctx context.Context ) error {
58+ if _ , err := gcMetaCancelation (ctx , c .rdb ); err != nil {
59+ return err
60+ }
61+
62+ return nil
63+ }
64+
5465// Len calculates the aggregate length (XLEN) of the queue. It adds up the
5566// lengths of all the streams in the queue.
5667func (c * Client ) Len (ctx context.Context , name string ) (int64 , error ) {
@@ -286,9 +297,9 @@ type metaCancelation struct {
286297// Del supports removal of a message when the given `fieldValue` matches a "meta
287298// cancelation" key as written when using a client with tracking support.
288299func (c * Client ) Del (ctx context.Context , fieldValue string ) error {
289- metaCancelationKey := fmt .Sprintf ("_meta:cancelation: %x" , sha1 .Sum ([]byte (fieldValue )))
300+ metaCancelationKey := fmt .Sprintf ("%x" , sha1 .Sum ([]byte (fieldValue )))
290301
291- msgBytes , err := c .rdb .Get (ctx , metaCancelationKey ).Bytes ()
302+ msgBytes , err := c .rdb .HGet (ctx , MetaCancelationHash , metaCancelationKey ).Bytes ()
292303 if err != nil {
293304 return err
294305 }
@@ -298,6 +309,14 @@ func (c *Client) Del(ctx context.Context, fieldValue string) error {
298309 return err
299310 }
300311
312+ if msg .StreamID == "" {
313+ return fmt .Errorf ("empty stream_id: %w" , ErrInvalidMetaCancelation )
314+ }
315+
316+ if msg .MsgID == "" {
317+ return fmt .Errorf ("empty msg_id: %w" , ErrInvalidMetaCancelation )
318+ }
319+
301320 n , err := c .rdb .XDel (ctx , msg .StreamID , msg .MsgID ).Result ()
302321 if err != nil {
303322 return err
0 commit comments