File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -4711,6 +4711,9 @@ type ClientInfo struct {
47114711 TotalMemory int // tot-mem, total memory consumed by this client in its various buffers
47124712 Redir int64 // client id of current client tracking redirection
47134713 Resp int // redis version 7.0, client RESP protocol version
4714+ TotalNetIn int64 // tot-net-in, total network bytes read from the client connection
4715+ TotalNetOut int64 // tot-net-out, total network bytes sent to the client connection
4716+ TotalCmds int64 // tot-cmds, number of commands executed by the client connection
47144717}
47154718
47164719type ClientInfoCmd struct {
@@ -4857,6 +4860,12 @@ func stringToClientInfo(txt string) (*ClientInfo, error) {
48574860 info .LibName = val
48584861 case "lib-ver" :
48594862 info .LibVer = val
4863+ case "tot-net-in" :
4864+ info .TotalNetIn , err = strconv .ParseInt (val , 10 , 64 )
4865+ case "tot-net-out" :
4866+ info .TotalNetOut , err = strconv .ParseInt (val , 10 , 64 )
4867+ case "tot-cmds" :
4868+ info .TotalCmds , err = strconv .ParseInt (val , 10 , 64 )
48604869 }
48614870
48624871 if err != nil {
Original file line number Diff line number Diff line change @@ -1151,3 +1151,35 @@ func TestCommandErrorHandling(t *testing.T) {
11511151 })
11521152 }
11531153}
1154+
1155+ func TestClientInfoParsing (t * testing.T ) {
1156+ // Test case with the new fields
1157+ testData := "id=123 addr=127.0.0.1:6379 fd=5 name= age=10 idle=5 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=ping user=default redir=-1 resp=3 lib-name=redis-go lib-ver=8.0.0 tot-net-in=1024 tot-net-out=2048 tot-cmds=100"
1158+
1159+ info , err := stringToClientInfo (testData )
1160+ if err != nil {
1161+ t .Fatalf ("Failed to parse client info: %v" , err )
1162+ }
1163+
1164+ // Verify the new fields are parsed correctly
1165+ if info .TotalNetIn != 1024 {
1166+ t .Errorf ("Expected TotalNetIn to be 1024, got %d" , info .TotalNetIn )
1167+ }
1168+
1169+ if info .TotalNetOut != 2048 {
1170+ t .Errorf ("Expected TotalNetOut to be 2048, got %d" , info .TotalNetOut )
1171+ }
1172+
1173+ if info .TotalCmds != 100 {
1174+ t .Errorf ("Expected TotalCmds to be 100, got %d" , info .TotalCmds )
1175+ }
1176+
1177+ // Verify other fields are still parsed correctly
1178+ if info .ID != 123 {
1179+ t .Errorf ("Expected ID to be 123, got %d" , info .ID )
1180+ }
1181+
1182+ if info .Addr != "127.0.0.1:6379" {
1183+ t .Errorf ("Expected Addr to be '127.0.0.1:6379', got '%s'" , info .Addr )
1184+ }
1185+ }
You can’t perform that action at this time.
0 commit comments