library-go/store/valkey/conf.go

61 lines
1.2 KiB
Go
Raw Normal View History

2024-11-24 06:45:55 +00:00
package valkey
import (
"errors"
"time"
)
var (
// ErrEmptyHost is an error that indicates no redis host is set.
ErrEmptyHost = errors.New("empty redis host")
// ErrEmptyType is an error that indicates no redis type is set.
ErrEmptyType = errors.New("empty redis type")
// ErrEmptyKey is an error that indicates no redis key is set.
ErrEmptyKey = errors.New("empty redis key")
)
type (
// A VKConf is a redis config.
VKConf struct {
Host string
Type string `json:",default=node,options=node|cluster"`
Pass string `json:",optional"`
Tls bool `json:",optional"`
NonBlock bool `json:",default=true"`
// PingTimeout is the timeout for ping redis.
PingTimeout time.Duration `json:",default=1s"`
}
// A VkKeyConfConf is a redis config with key.
VkKeyConfConf struct {
VKConf
Key string
}
)
// Validate validates the RedisConf.
func (rc VKConf) Validate() error {
if len(rc.Host) == 0 {
return ErrEmptyHost
}
if len(rc.Type) == 0 {
return ErrEmptyType
}
return nil
}
// Validate validates the RedisKeyConf.
func (rkc VkKeyConfConf) Validate() error {
if err := rkc.VKConf.Validate(); err != nil {
return err
}
if len(rkc.Key) == 0 {
return ErrEmptyKey
}
return nil
}