فهرست منبع

update redis option

ls 5 ماه پیش
والد
کامیت
5558b712bc
3فایلهای تغییر یافته به همراه13 افزوده شده و 8 حذف شده
  1. 4 0
      cache/redis.go
  2. 1 0
      map.go
  3. 8 8
      utils.go

+ 4 - 0
cache/redis.go

@@ -10,6 +10,7 @@ import (
 // RedisConfig config
 type RedisConfig struct {
 	Addr         string
+	UserName     string
 	Password     string
 	DB           int
 	DialTimeout  time.Duration
@@ -24,6 +25,7 @@ type RedisClusterConfig struct {
 	// A seed list of host:port addresses of cluster nodes.
 	Addrs []string
 
+	UserName string
 	Password string
 	DB       int
 
@@ -82,6 +84,7 @@ func SetRedisClusterConfig(cfg RedisClusterConfig) {
 func NewRedisCache() *RedisCache {
 	client := redis.NewClient(&redis.Options{
 		Addr:         redisConfig.Addr,
+		Username:     redisConfig.UserName,
 		Password:     redisConfig.Password,
 		DialTimeout:  redisConfig.DialTimeout,
 		ReadTimeout:  redisConfig.ReadTimeout,
@@ -99,6 +102,7 @@ func NewRedisClusterCache() *RedisCache {
 	var config redis.ClusterOptions
 
 	config.Addrs = redisClusterConfig.Addrs
+	config.Username = redisClusterConfig.UserName
 	config.Password = redisClusterConfig.Password
 
 	config.DialTimeout = redisClusterConfig.DialTimeout

+ 1 - 0
map.go

@@ -0,0 +1 @@
+package myth

+ 8 - 8
utils.go

@@ -19,21 +19,21 @@ const (
 	PB
 )
 
-// M is a shortcut for map[string]interface{}
-type M map[string]interface{}
+// M is a shortcut for map[string]any
+type M map[string]any
 
-// NewM new map[string]interface{}
+// NewM new map[string]any
 func NewM() M {
-	return make(map[string]interface{})
+	return make(map[string]any)
 }
 
-// Set key-value to map[string]interface{}
-func (m M) Set(k string, v interface{}) {
+// Set key-value to map[string]any
+func (m M) Set(k string, v any) {
 	m[k] = v
 }
 
-// Get value from map[string]interface{}
-func (m M) Get(k string) (v interface{}, ok bool) {
+// Get value from map[string]any
+func (m M) Get(k string) (v any, ok bool) {
 	v, ok = m[k]
 	return
 }