File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -34,4 +34,5 @@ set name sojeb
3434- HDEL
3535- HLEN
3636- FLUSHALL
37- - DEL
37+ - DEL
38+ - INFO
Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "fmt"
45 "sync"
56)
67
@@ -15,6 +16,7 @@ var Handlers = map[string]func([]Value) Value{
1516 "HLEN" : hlen ,
1617 "FLUSHALL" : flushall ,
1718 "DEL" : del ,
19+ "INFO" : info ,
1820}
1921
2022func ping (args []Value ) Value {
@@ -194,3 +196,29 @@ func del(args []Value) Value {
194196
195197 return Value {typ : "string" , str : "OK" }
196198}
199+
200+ // info command which shows stats about the server
201+ func info (args []Value ) Value {
202+ if len (args ) != 0 {
203+ return Value {typ : "error" , str : "ERR wrong number of arguments for 'info' command" }
204+ }
205+
206+ SETsMu .RLock ()
207+ totalKeys := len (SETs )
208+ SETsMu .RUnlock ()
209+
210+ HSETsMu .RLock ()
211+ totalHashes := len (HSETs )
212+ totalFields := 0
213+ for _ , m := range HSETs {
214+ totalFields += len (m )
215+ }
216+ HSETsMu .RUnlock ()
217+
218+ infoStr := fmt .Sprintf (
219+ "# Server Info\n keys:%d\n hashes:%d\n fields:%d\n " ,
220+ totalKeys , totalHashes , totalFields ,
221+ )
222+
223+ return Value {typ : "bulk" , bulk : infoStr }
224+ }
You can’t perform that action at this time.
0 commit comments