Skip to content

Commit b9e9558

Browse files
authored
Return the db field of type int in the parseRedisConnection function (#189)
1 parent 20461c7 commit b9e9558

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

server/session.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func redisSessionStore(redisUrl string, secret []byte) (sessions.Store, error) {
4343
}
4444
// get the existing secret in the redis, if not exist, set the new secret
4545
// TODO
46-
return redis.NewStoreWithDB(maxIdle, network, address, password, db, secret)
46+
return redis.NewStoreWithDB(maxIdle, network, address, password, strconv.Itoa(db), secret)
4747
}
4848

4949
// parseRedisConnection parse the redis connection string
5050
// for example => redis://127.0.0.1:6379?password=redis_password&db=10&max_idle=10&secret=redis_secret
51-
func parseRedisConnection(redisUrl string) (maxIdle int, network, address, password string, db string, secret []byte, err error) {
51+
func parseRedisConnection(redisUrl string) (maxIdle int, network, address, password string, db int, secret []byte, err error) {
5252
u, err := url.Parse(redisUrl)
5353
if err != nil {
5454
return
@@ -82,16 +82,16 @@ func parseRedisConnection(redisUrl string) (maxIdle int, network, address, passw
8282
secret = []byte(u.Query().Get("secret"))
8383

8484
// db
85-
defaultDB := "0"
86-
db = u.Query().Get("db")
87-
if len(db) == 0 {
88-
db = defaultDB
85+
dbValue := u.Query().Get("db")
86+
if len(dbValue) == 0 {
8987
return
9088
}
91-
if dbInt, dbErr := strconv.Atoi(db); dbErr != nil {
92-
err = fmt.Errorf("invalid redis db => %s", db)
89+
if dbInt, dbErr := strconv.Atoi(dbValue); dbErr != nil {
90+
err = fmt.Errorf("invalid redis db => %s", dbValue)
9391
} else if dbInt < 0 || dbInt > 15 {
94-
err = fmt.Errorf("invalid redis db => %s, db must be between 0 and 15", db)
92+
err = fmt.Errorf("invalid redis db => %s, db must be between 0 and 15", dbValue)
93+
} else {
94+
db = dbInt
9595
}
9696
return
9797
}

0 commit comments

Comments
 (0)