Skip to content

Commit

Permalink
add Ping operation when get conn from poll to clear unread data in th…
Browse files Browse the repository at this point in the history
…e conn(if the conn has)
  • Loading branch information
cheniujh committed Apr 23, 2024
1 parent 8e10f6d commit 6ad70bc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/integration/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pika_integration

import (
"context"
"time"

"github.com/redis/go-redis/v9"
Expand Down Expand Up @@ -41,5 +42,11 @@ func PikaOption(addr string) *redis.Options {
MaxRetries: -1,
PoolSize: 30,
PoolTimeout: 60 * time.Second,
OnConnect: func(ctx context.Context, cn *redis.Conn) error {
// Attempt to clear any unread data (if possible)
// Note: Redis does not provide a direct "clear buffer" command, so we simulate it by pinging
_, err := cn.Ping(ctx).Result()
return err
},
}
}

0 comments on commit 6ad70bc

Please sign in to comment.