@@ -7,18 +7,19 @@ import (
77 "time"
88 "errors"
99 "math/rand"
10- redigo "github.com/garyburd/redigo/redis"
10+ "os"
11+ redigo "github.com/gomodule/redigo/redis"
1112)
1213
1314var redisPool * redigo.Pool
1415
1516func init () {
16- log .Printf ("Opening Redis: %s" , config . RedisServerAndPort )
17+ log .Printf ("Opening Redis: %s" , os . Getenv ( "REDIS_ADDRESS" ) )
1718 redisPool = & redigo.Pool {
1819 MaxIdle : 10 ,
1920 IdleTimeout : 1 * time .Second ,
2021 Dial : func () (redigo.Conn , error ) {
21- return redigo .Dial ("tcp" , config . RedisServerAndPort )
22+ return redigo .Dial ("tcp" , os . Getenv ( "REDIS_ADDRESS" ) )
2223 },
2324 TestOnBorrow : func (c redigo.Conn , t time.Time ) (err error ) {
2425 _ , err = c .Do ("PING" )
@@ -33,7 +34,7 @@ func init() {
3334func getFileListByZipReferenceId (id string ) (files []* ZipEntry , err error ) {
3435 redis := redisPool .Get ()
3536 defer redis .Close ()
36-
37+
3738 // Get the value from Redis
3839 result , err := redis .Do ("GET" , "zip:" + id )
3940 if err != nil || result == nil {
@@ -59,10 +60,10 @@ func getFileListByZipReferenceId(id string) (files []*ZipEntry, err error) {
5960func CreateZipReference (files []* ZipEntry ) (ref_id_string string ) {
6061 redis := redisPool .Get ()
6162 defer redis .Close ()
62-
63+
6364 filesJson , err := json .Marshal (files )
6465 HandleError (err )
65-
66+
6667 //get new id redis
6768 ref_id , err := redis .Do ("INCR" , "zip_reference_id" )
6869 HandleError (err )
@@ -71,7 +72,7 @@ func CreateZipReference(files []*ZipEntry) (ref_id_string string) {
7172 // Save JSON files to Redis
7273 _ , err = redis .Do ("SET" , "zip:" + ref_id_string , filesJson )
7374 HandleError (err )
74-
75+
7576 return
7677}
7778
@@ -83,4 +84,4 @@ func RandomString(strlen int) string {
8384 result [i ] = chars [rand .Intn (len (chars ))]
8485 }
8586 return string (result )
86- }
87+ }
0 commit comments