github.com/zhongdalu/gf@v1.0.0/g/database/gredis/gredis_config.go (about) 1 // Copyright 2019 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 7 package gredis 8 9 import "github.com/zhongdalu/gf/g/container/gmap" 10 11 const ( 12 // Default configuration group name. 13 DEFAULT_GROUP_NAME = "default" 14 ) 15 16 var ( 17 // Configuration groups. 18 configs = gmap.NewStrAnyMap() 19 ) 20 21 // SetConfig sets the global configuration for specified group. 22 // If <name> is not passed, it sets configuration for the default group name. 23 func SetConfig(config Config, name ...string) { 24 group := DEFAULT_GROUP_NAME 25 if len(name) > 0 { 26 group = name[0] 27 } 28 configs.Set(group, config) 29 instances.Remove(group) 30 } 31 32 // GetConfig returns the global configuration with specified group name. 33 // If <name> is not passed, it returns configuration of the default group name. 34 func GetConfig(name ...string) (config Config, ok bool) { 35 group := DEFAULT_GROUP_NAME 36 if len(name) > 0 { 37 group = name[0] 38 } 39 if v := configs.Get(group); v != nil { 40 return v.(Config), true 41 } 42 return Config{}, false 43 } 44 45 // RemoveConfig removes the global configuration with specified group. 46 // If <name> is not passed, it removes configuration of the default group name. 47 func RemoveConfig(name ...string) { 48 group := DEFAULT_GROUP_NAME 49 if len(name) > 0 { 50 group = name[0] 51 } 52 configs.Remove(group) 53 instances.Remove(group) 54 } 55 56 // ClearConfig removes all configurations and instances of redis. 57 func ClearConfig() { 58 configs.Clear() 59 instances.Clear() 60 }