git.zd.zone/hrpc/hrpc@v0.0.12/database/redis/option.go (about) 1 package redis 2 3 type Options struct { 4 Address string `json:"address"` 5 DB int `json:"db"` 6 Username string `json:"username"` 7 Password string `json:"password"` 8 Port int `json:"port"` 9 Network string `json:"network"` 10 // Maximum number of retries before giving up. 11 // Default is 3 retries; -1 (not 0) disables retries. 12 MaxRetries int `json:"max_retries"` 13 14 // customized 15 customized bool 16 } 17 18 type Option func(o *Options) 19 20 // WithCustomized will use your own configurations. 21 // To be reminder that you should make sure the values of Address, DB, Auth, Port have been assigned correctly. 22 func WithCustomized() Option { 23 return func(o *Options) { 24 o.customized = true 25 } 26 } 27 28 func WithAddress(s string) Option { 29 return func(o *Options) { 30 o.Address = s 31 } 32 } 33 34 func WithDB(i int) Option { 35 return func(o *Options) { 36 o.DB = i 37 } 38 } 39 40 func WithAuth(username, password string) Option { 41 return func(o *Options) { 42 o.Username = username 43 o.Password = password 44 } 45 } 46 47 func WithPort(port int) Option { 48 return func(o *Options) { 49 o.Port = port 50 } 51 } 52 53 func WithMaxRetries(i int) Option { 54 return func(o *Options) { 55 o.MaxRetries = i 56 } 57 }