feat: 添加 database - cache(redis)
This commit is contained in:
32
database/cache/option.go
vendored
Normal file
32
database/cache/option.go
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
ctx context.Context
|
||||
redis *string
|
||||
}
|
||||
|
||||
type OptionFn func(*config)
|
||||
|
||||
func WithCtx(ctx context.Context) OptionFn {
|
||||
return func(c *config) {
|
||||
if ctx != nil {
|
||||
c.ctx = ctx
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WithRedis(host string, port int, username, password string) OptionFn {
|
||||
return func(c *config) {
|
||||
uri := fmt.Sprintf("%s:%d", host, port)
|
||||
if username != "" || password != "" {
|
||||
uri = fmt.Sprintf("redis://%s:%s@%s:%d", username, password, host, port)
|
||||
}
|
||||
|
||||
c.redis = &uri
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user