mirror of
https://github.com/elyby/chrly.git
synced 2024-12-24 05:59:54 +05:30
Попытка вернуть пул соединений
This commit is contained in:
parent
58c05533f3
commit
8abb5f6bc5
@ -20,19 +20,19 @@ type SkinItem struct {
|
|||||||
|
|
||||||
func (s *SkinItem) Save() {
|
func (s *SkinItem) Save() {
|
||||||
str, _ := json.Marshal(s)
|
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) {
|
func FindRecord(username string) (SkinItem, error) {
|
||||||
var record SkinItem;
|
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) {
|
if (err == nil) {
|
||||||
decodeErr := json.Unmarshal([]byte(result), &record)
|
decodeErr := json.Unmarshal([]byte(result), &record)
|
||||||
if (decodeErr != nil) {
|
if (decodeErr != nil) {
|
||||||
log.Println("Cannot decode record data")
|
log.Println("Cannot decode record data")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Println("Error on request user data")
|
log.Println("Error on request user data: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return record, err
|
return record, err
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mediocregopher/radix.v2/redis"
|
"github.com/mediocregopher/radix.v2/pool"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Redis *redis.Client
|
var RedisPool *pool.Pool
|
||||||
|
|
||||||
var Router *mux.Router
|
var Router *mux.Router
|
||||||
|
@ -3,14 +3,15 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
//"time"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"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/routes"
|
||||||
"elyby/minecraft-skinsystem/lib/services"
|
"elyby/minecraft-skinsystem/lib/services"
|
||||||
|
//"github.com/mediocregopher/radix.v2/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
const redisString string = "redis:6379"
|
const redisString string = "redis:6379"
|
||||||
@ -18,7 +19,7 @@ const redisString string = "redis:6379"
|
|||||||
func main() {
|
func main() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
||||||
client, redisErr := redis.Dial("tcp", redisString)
|
pool, redisErr := pool.New("tcp", redisString, 10)
|
||||||
if redisErr != nil {
|
if redisErr != nil {
|
||||||
log.Fatal("Redis unavailable")
|
log.Fatal("Redis unavailable")
|
||||||
}
|
}
|
||||||
@ -37,10 +38,10 @@ func main() {
|
|||||||
apiRouter := router.PathPrefix("/api").Subrouter()
|
apiRouter := router.PathPrefix("/api").Subrouter()
|
||||||
apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST")
|
apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST")
|
||||||
|
|
||||||
services.Redis = client
|
services.RedisPool = pool
|
||||||
services.Router = router
|
services.Router = router
|
||||||
|
|
||||||
go func() {
|
/*go func() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()*/
|
||||||
|
|
||||||
log.Println("Started");
|
log.Println("Started");
|
||||||
log.Fatal(http.ListenAndServe(":80", router))
|
log.Fatal(http.ListenAndServe(":80", router))
|
||||||
|
Loading…
Reference in New Issue
Block a user