Open akshayk-ktk opened 2 months ago
package main
import (
"context"
"log"
"time"
"github.com/redis/go-redis/v9"
)
func main() {
options := redis.Options{
Network: "tcp",
Addr: ":6379",
ClientName: "local-go-client",
PoolSize: 20,
PoolTimeout: 1 * time.Minute,
MinIdleConns: 10,
MaxIdleConns: 15,
OnConnect: func(ctx context.Context, cn *redis.Conn) error {
status, err := cn.ClientSetName(ctx, "local-go-client").Result()
if err != nil {
log.Println("err", err)
return err
}
log.Println("setname status is", status)
return nil
},
OnClose: func(ctx context.Context, cn *redis.Conn) error {
// Ensure the client name is set for idle connections too
_, err := cn.ClientSetName(ctx, "local-go-client").Result()
if err != nil {
log.Println("Error setting client name for idle connection:", err)
}
return nil
},
}
c := redis.NewClient(&options)
ctx := context.Background()
pingReply, err := c.Ping(ctx).Result()
if err != nil {
panic(err)
}
log.Println("Ping Reply", pingReply)
// Keep the connection alive for testing
time.Sleep(5 * time.Minute)
}
Hi @ljluestc ,
I did not find the OnClose key in the fields in the redis options. Can you confirm what version are you using?
Expected Behavior
If there are connections made by the client to the redis server and redis options client name is specified then all the connections should have the client name.
Current Behavior
Only a few connections which get used get assigned the client name.
Steps to Reproduce
Context (Environment)
Example is given from local redis but same issue I am facing in elasticache redis also. The number of connections were crossing threshold and we were getting alerts.
Wanted to check which applications were using most connections but found out that connection name is not available when doing client list.
Detailed Description
I have tried for both redis.Client and redis.ClusterClient and facing issue for both.
Not sure if this is the expected behaviour or a bug, any help here is much appreciated.
go-redis version - github.com/redis/go-redis/v9 v9.5.3
OS - MacOS Sonoma 14.6.1
Redis Server Output
Client List Output