• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HDT3213 / godis / 15238419529

25 May 2025 01:32PM UTC coverage: 72.019% (-3.7%) from 75.704%
15238419529

push

github

HDT3213
update github actions go version

1 of 1 new or added line in 1 file covered. (100.0%)

1149 existing lines in 29 files now uncovered.

8473 of 11765 relevant lines covered (72.02%)

0.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.73
/database/systemcmd.go
1
package database
2

3
import (
4
        "fmt"
5
        "github.com/hdt3213/godis/config"
6
        "github.com/hdt3213/godis/interface/redis"
7
        "github.com/hdt3213/godis/redis/protocol"
8
        "github.com/hdt3213/godis/tcp"
9
        "os"
10
        "runtime"
11
        "strings"
12
        "time"
13
)
14

15
// Ping the server
16
func Ping(c redis.Connection, args [][]byte) redis.Reply {
1✔
17
        if len(args) == 0 {
2✔
18
                return &protocol.PongReply{}
1✔
19
        } else if len(args) == 1 {
3✔
20
                return protocol.MakeStatusReply(string(args[0]))
1✔
21
        } else {
2✔
22
                return protocol.MakeErrReply("ERR wrong number of arguments for 'ping' command")
1✔
23
        }
1✔
24
}
25

26
// Info the information of the godis server returned by the INFO command
27
func Info(db *Server, args [][]byte) redis.Reply {
1✔
28
        if len(args) == 0 {
2✔
29
                infoCommandList := [...]string{"server", "client", "cluster", "keyspace"}
1✔
30
                var allSection []byte
1✔
31
                for _, s := range infoCommandList {
2✔
32
                        allSection = append(allSection, GenGodisInfoString(s, db)...)
1✔
33
                }
1✔
34
                return protocol.MakeBulkReply(allSection)
1✔
35
        } else if len(args) == 1 {
2✔
36
                section := strings.ToLower(string(args[0]))
1✔
37
                switch section {
1✔
38
                case "server":
1✔
39
                        reply := GenGodisInfoString("server", db)
1✔
40
                        return protocol.MakeBulkReply(reply)
1✔
41
                case "client":
1✔
42
                        return protocol.MakeBulkReply(GenGodisInfoString("client", db))
1✔
43
                case "cluster":
1✔
44
                        return protocol.MakeBulkReply(GenGodisInfoString("cluster", db))
1✔
45
                case "keyspace":
1✔
46
                        return protocol.MakeBulkReply(GenGodisInfoString("keyspace", db))
1✔
47
                default:
1✔
48
                        return protocol.MakeErrReply("Invalid section for 'info' command")
1✔
49
                }
50
        }
51
        return protocol.MakeArgNumErrReply("info")
1✔
52
}
53

54
// Auth validate client's password
55
func Auth(c redis.Connection, args [][]byte) redis.Reply {
1✔
56
        if len(args) != 1 {
2✔
57
                return protocol.MakeErrReply("ERR wrong number of arguments for 'auth' command")
1✔
58
        }
1✔
59
        if config.Properties.RequirePass == "" {
2✔
60
                return protocol.MakeErrReply("ERR Client sent AUTH, but no password is set")
1✔
61
        }
1✔
62
        passwd := string(args[0])
1✔
63
        c.SetPassword(passwd)
1✔
64
        if config.Properties.RequirePass != passwd {
2✔
65
                return protocol.MakeErrReply("ERR invalid password")
1✔
66
        }
1✔
67
        return &protocol.OkReply{}
1✔
68
}
69

70
func isAuthenticated(c redis.Connection) bool {
1✔
71
        if config.Properties.RequirePass == "" {
2✔
72
                return true
1✔
73
        }
1✔
74
        return c.GetPassword() == config.Properties.RequirePass
1✔
75
}
76

77
func DbSize(c redis.Connection, db *Server) redis.Reply {
1✔
78
        keys, _ := db.GetDBSize(c.GetDBIndex())
1✔
79
        return protocol.MakeIntReply(int64(keys))
1✔
80
}
1✔
81

82
func GenGodisInfoString(section string, db *Server) []byte {
1✔
83
        startUpTimeFromNow := getGodisRuninngTime()
1✔
84
        switch section {
1✔
85
        case "server":
1✔
86
                s := fmt.Sprintf("# Server\r\n"+
1✔
87
                        "godis_version:%s\r\n"+
1✔
88
                        //"godis_git_sha1:%s\r\n"+
1✔
89
                        //"godis_git_dirty:%d\r\n"+
1✔
90
                        //"godis_build_id:%s\r\n"+
1✔
91
                        "godis_mode:%s\r\n"+
1✔
92
                        "os:%s %s\r\n"+
1✔
93
                        "arch_bits:%d\r\n"+
1✔
94
                        //"multiplexing_api:%s\r\n"+
1✔
95
                        "go_version:%s\r\n"+
1✔
96
                        "process_id:%d\r\n"+
1✔
97
                        "run_id:%s\r\n"+
1✔
98
                        "tcp_port:%d\r\n"+
1✔
99
                        "uptime_in_seconds:%d\r\n"+
1✔
100
                        "uptime_in_days:%d\r\n"+
1✔
101
                        //"hz:%d\r\n"+
1✔
102
                        //"lru_clock:%d\r\n"+
1✔
103
                        "config_file:%s\r\n",
1✔
104
                        godisVersion,
1✔
105
                        //TODO,
1✔
106
                        //TODO,
1✔
107
                        //TODO,
1✔
108
                        getGodisRunningMode(),
1✔
109
                        runtime.GOOS, runtime.GOARCH,
1✔
110
                        32<<(^uint(0)>>63),
1✔
111
                        //TODO,
1✔
112
                        runtime.Version(),
1✔
113
                        os.Getpid(),
1✔
114
                        config.Properties.RunID,
1✔
115
                        config.Properties.Port,
1✔
116
                        startUpTimeFromNow,
1✔
117
                        startUpTimeFromNow/time.Duration(3600*24),
1✔
118
                        //TODO,
1✔
119
                        //TODO,
1✔
120
                        config.Properties.CfPath)
1✔
121
                return []byte(s)
1✔
122
        case "client":
1✔
123
                s := fmt.Sprintf("# Clients\r\n"+
1✔
124
                        "connected_clients:%d\r\n",
1✔
125
                        //"client_recent_max_input_buffer:%d\r\n"+
1✔
126
                        //"client_recent_max_output_buffer:%d\r\n"+
1✔
127
                        //"blocked_clients:%d\n",
1✔
128
                        tcp.ClientCounter,
1✔
129
                        //TODO,
1✔
130
                        //TODO,
1✔
131
                        //TODO,
1✔
132
                )
1✔
133
                return []byte(s)
1✔
134
        case "cluster":
1✔
135
                if getGodisRunningMode() == config.ClusterMode {
1✔
UNCOV
136
                        s := fmt.Sprintf("# Cluster\r\n"+
×
UNCOV
137
                                "cluster_enabled:%s\r\n",
×
UNCOV
138
                                "1",
×
UNCOV
139
                        )
×
UNCOV
140
                        return []byte(s)
×
141
                } else {
1✔
142
                        s := fmt.Sprintf("# Cluster\r\n"+
1✔
143
                                "cluster_enabled:%s\r\n",
1✔
144
                                "0",
1✔
145
                        )
1✔
146
                        return []byte(s)
1✔
147
                }
1✔
148
        case "keyspace":
1✔
149
                dbCount := config.Properties.Databases
1✔
150
                var serv []byte
1✔
151
                for i := 0; i < dbCount; i++ {
2✔
152
                        keys, expiresKeys := db.GetDBSize(i)
1✔
153
                        if keys != 0 {
1✔
UNCOV
154
                                ttlSampleAverage := db.GetAvgTTL(i, 20)
×
UNCOV
155
                                serv = append(serv, getDbSize(i, keys, expiresKeys, ttlSampleAverage)...)
×
UNCOV
156
                        }
×
157
                }
158
                prefix := []byte("# Keyspace\r\n")
1✔
159
                keyspaceInfo := append(prefix, serv...)
1✔
160
                return keyspaceInfo
1✔
161
        }
UNCOV
162
        return []byte("")
×
163
}
164

165
// getGodisRunningMode return godis running mode
166
func getGodisRunningMode() string {
1✔
167
        if config.Properties.ClusterEnable {
1✔
UNCOV
168
                return config.ClusterMode
×
169
        } else {
1✔
170
                return config.StandaloneMode
1✔
171
        }
1✔
172
}
173

174
// getGodisRuninngTime return the running time of godis
175
func getGodisRuninngTime() time.Duration {
1✔
176
        return time.Since(config.EachTimeServerInfo.StartUpTime) / time.Second
1✔
177
}
1✔
178

UNCOV
179
func getDbSize(dbIndex, keys, expiresKeys int, ttl int64) []byte {
×
UNCOV
180
        s := fmt.Sprintf("db%d:keys=%d,expires=%d,avg_ttl=%d\r\n",
×
UNCOV
181
                dbIndex, keys, expiresKeys, ttl)
×
UNCOV
182
        return []byte(s)
×
UNCOV
183
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc