Попытка вернуть пул соединений

This commit is contained in:
ErickSkrauch 2016-07-29 12:24:31 +03:00
parent 58c05533f3
commit 8abb5f6bc5
3 changed files with 12 additions and 11 deletions

View File

@ -20,19 +20,19 @@ type SkinItem struct {
func (s *SkinItem) Save() {
str, _ := json.Marshal(s)
services.Redis.Cmd("SET", tools.BuildKey(s.Username), str)
services.RedisPool.Cmd("SET", tools.BuildKey(s.Username), str)
}
func FindRecord(username string) (SkinItem, error) {
var record SkinItem;
result, err := services.Redis.Cmd("GET", tools.BuildKey(username)).Str();
result, err := services.RedisPool.Cmd("GET", tools.BuildKey(username)).Str();
if (err == nil) {
decodeErr := json.Unmarshal([]byte(result), &record)
if (decodeErr != nil) {
log.Println("Cannot decode record data")
}
} else {
log.Println("Error on request user data")
log.Println("Error on request user data: " + err.Error())
}
return record, err

View File

@ -1,10 +1,10 @@
package services
import (
"github.com/mediocregopher/radix.v2/redis"
"github.com/mediocregopher/radix.v2/pool"
"github.com/gorilla/mux"
)
var Redis *redis.Client
var RedisPool *pool.Pool
var Router *mux.Router

View File

@ -3,14 +3,15 @@ package main
import (
"log"
"runtime"
"time"
//"time"
"net/http"
"github.com/gorilla/mux"
"github.com/mediocregopher/radix.v2/redis"
"github.com/mediocregopher/radix.v2/pool"
"elyby/minecraft-skinsystem/lib/routes"
"elyby/minecraft-skinsystem/lib/services"
//"github.com/mediocregopher/radix.v2/redis"
)
const redisString string = "redis:6379"
@ -18,7 +19,7 @@ const redisString string = "redis:6379"
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
client, redisErr := redis.Dial("tcp", redisString)
pool, redisErr := pool.New("tcp", redisString, 10)
if redisErr != nil {
log.Fatal("Redis unavailable")
}
@ -37,10 +38,10 @@ func main() {
apiRouter := router.PathPrefix("/api").Subrouter()
apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST")
services.Redis = client
services.RedisPool = pool
services.Router = router
go func() {
/*go func() {
for {
time.Sleep(5 * time.Second)
@ -56,7 +57,7 @@ func main() {
}
}
}
}()
}()*/
log.Println("Started");
log.Fatal(http.ListenAndServe(":80", router))