From e4605f232b32ada87296b2a793a8c8bae6e90f1f Mon Sep 17 00:00:00 2001 From: Ruben Cid Date: Wed, 26 Sep 2018 18:05:09 +0200 Subject: [PATCH] Support redis URI --- cache/redis/redis.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cache/redis/redis.go b/cache/redis/redis.go index 55fea25e..372dd48b 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -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://@: + 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" }