mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 16:57:06 +08:00
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package db
|
|
|
|
import (
|
|
"github.com/hdt3213/godis/config"
|
|
"github.com/hdt3213/godis/interface/redis"
|
|
"github.com/hdt3213/godis/redis/reply"
|
|
)
|
|
|
|
// Ping the server
|
|
func Ping(db *DB, args [][]byte) redis.Reply {
|
|
if len(args) == 0 {
|
|
return &reply.PongReply{}
|
|
} else if len(args) == 1 {
|
|
return reply.MakeStatusReply(string(args[0]))
|
|
} else {
|
|
return reply.MakeErrReply("ERR wrong number of arguments for 'ping' command")
|
|
}
|
|
}
|
|
|
|
// Auth validate client's password
|
|
func Auth(db *DB, c redis.Connection, args [][]byte) redis.Reply {
|
|
if len(args) != 1 {
|
|
return reply.MakeErrReply("ERR wrong number of arguments for 'auth' command")
|
|
}
|
|
if config.Properties.RequirePass == "" {
|
|
return reply.MakeErrReply("ERR Client sent AUTH, but no password is set")
|
|
}
|
|
passwd := string(args[0])
|
|
c.SetPassword(passwd)
|
|
if config.Properties.RequirePass != passwd {
|
|
return reply.MakeErrReply("ERR invalid password")
|
|
}
|
|
return &reply.OkReply{}
|
|
}
|
|
|
|
func isAuthenticated(c redis.Connection) bool {
|
|
if config.Properties.RequirePass == "" {
|
|
return true
|
|
}
|
|
return c.GetPassword() == config.Properties.RequirePass
|
|
} |