1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 17:40:48 +00:00

Merge pull request #3339 from GNURub/hotfix/redis-uri

Support redis URI format
This commit is contained in:
astaxie 2018-09-30 15:43:41 +08:00 committed by GitHub
commit c4ed5030da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,6 +39,7 @@ import (
"github.com/gomodule/redigo/redis"
"github.com/astaxie/beego/cache"
"strings"
)
var (
@ -164,6 +165,14 @@ func (rc *Cache) StartAndGC(config string) error {
if _, ok := cf["conn"]; !ok {
return errors.New("config has no conn key")
}
// Format redis://<password>@<host>:<port>
cf["conn"] = strings.Replace(cf["conn"], "redis://", "", 1)
if i := strings.Index(cf["conn"], "@"); i > -1 {
cf["password"] = cf["conn"][0:i]
cf["conn"] = cf["conn"][i+1:]
}
if _, ok := cf["dbNum"]; !ok {
cf["dbNum"] = "0"
}