mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 16:57:06 +08:00
Add the keyspace section of the info command
This commit is contained in:
@@ -111,7 +111,7 @@ func (server *Server) Exec(c redis.Connection, cmdLine [][]byte) (result redis.R
|
||||
}
|
||||
// info
|
||||
if cmdName == "info" {
|
||||
return Info(c, cmdLine)
|
||||
return Info(server, cmdLine[1:])
|
||||
}
|
||||
if cmdName == "slaveof" {
|
||||
if c != nil && c.InMultiState() {
|
||||
@@ -388,3 +388,23 @@ func (server *Server) startReplCron() {
|
||||
}
|
||||
}(server)
|
||||
}
|
||||
|
||||
// GetAvgTTL Calculate the average expiration time of keys
|
||||
func (server *Server) GetAvgTTL(dbIndex, randomKeyCount int) int64 {
|
||||
var ttlCount int64
|
||||
db := server.mustSelectDB(dbIndex)
|
||||
keys := db.data.RandomKeys(randomKeyCount)
|
||||
for _, k := range keys {
|
||||
t := time.Now()
|
||||
rawExpireTime, ok := db.ttlMap.Get(k)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
expireTime, _ := rawExpireTime.(time.Time)
|
||||
// if the key has already reached its expiration time during calculation, ignore it
|
||||
if expireTime.Sub(t).Microseconds() > 0 {
|
||||
ttlCount += expireTime.Sub(t).Microseconds()
|
||||
}
|
||||
}
|
||||
return ttlCount / int64(len(keys))
|
||||
}
|
||||
|
Reference in New Issue
Block a user