From 8abb5f6bc5de1603ce237042b38c477be2fb2b7e Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 29 Jul 2016 12:24:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BD=D1=83=D1=82=D1=8C=20=D0=BF=D1=83=D0=BB?= =?UTF-8?q?=20=D1=81=D0=BE=D0=B5=D0=B4=D0=B8=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/data/SkinItem.go | 6 +++--- lib/services/services.go | 4 ++-- minecraft-skinsystem.go | 13 +++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/data/SkinItem.go b/lib/data/SkinItem.go index 8fe0f86..c381ed5 100644 --- a/lib/data/SkinItem.go +++ b/lib/data/SkinItem.go @@ -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 diff --git a/lib/services/services.go b/lib/services/services.go index d62f7ac..f0f612d 100644 --- a/lib/services/services.go +++ b/lib/services/services.go @@ -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 diff --git a/minecraft-skinsystem.go b/minecraft-skinsystem.go index 119e522..04c2b0b 100644 --- a/minecraft-skinsystem.go +++ b/minecraft-skinsystem.go @@ -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))