forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-redis/redis"
|
||||
)
|
||||
|
||||
var StatRds *Manager
|
||||
|
||||
type Manager struct {
|
||||
client *redis.Client
|
||||
options *redis.Options
|
||||
}
|
||||
|
||||
// Redis 配置项
|
||||
type Options = redis.Options
|
||||
|
||||
func NewManagerWithUrl(url string, fn func(opt *Options)) (*Manager, error) {
|
||||
opts, err := redis.ParseURL(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opts == nil {
|
||||
err = errors.New(fmt.Sprintf("NewManagerWithUrl failed url %s", url))
|
||||
return nil, err
|
||||
}
|
||||
if fn != nil {
|
||||
fn(opts)
|
||||
}
|
||||
return &Manager{options: opts}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user