mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-06 01:07:06 +08:00
rename MultiDB to Server; rename AofHandler to Persister
This commit is contained in:
41
database/systemcmd.go
Normal file
41
database/systemcmd.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/config"
|
||||
"github.com/hdt3213/godis/interface/redis"
|
||||
"github.com/hdt3213/godis/redis/protocol"
|
||||
)
|
||||
|
||||
// Ping the server
|
||||
func Ping(c redis.Connection, args [][]byte) redis.Reply {
|
||||
if len(args) == 0 {
|
||||
return &protocol.PongReply{}
|
||||
} else if len(args) == 1 {
|
||||
return protocol.MakeStatusReply(string(args[0]))
|
||||
} else {
|
||||
return protocol.MakeErrReply("ERR wrong number of arguments for 'ping' command")
|
||||
}
|
||||
}
|
||||
|
||||
// Auth validate client's password
|
||||
func Auth(c redis.Connection, args [][]byte) redis.Reply {
|
||||
if len(args) != 1 {
|
||||
return protocol.MakeErrReply("ERR wrong number of arguments for 'auth' command")
|
||||
}
|
||||
if config.Properties.RequirePass == "" {
|
||||
return protocol.MakeErrReply("ERR Client sent AUTH, but no password is set")
|
||||
}
|
||||
passwd := string(args[0])
|
||||
c.SetPassword(passwd)
|
||||
if config.Properties.RequirePass != passwd {
|
||||
return protocol.MakeErrReply("ERR invalid password")
|
||||
}
|
||||
return &protocol.OkReply{}
|
||||
}
|
||||
|
||||
func isAuthenticated(c redis.Connection) bool {
|
||||
if config.Properties.RequirePass == "" {
|
||||
return true
|
||||
}
|
||||
return c.GetPassword() == config.Properties.RequirePass
|
||||
}
|
Reference in New Issue
Block a user