mirror of
https://github.com/elyby/chrly.git
synced 2024-11-23 05:33:18 +05:30
Отныне мы используем пул соединений для редиса
This commit is contained in:
parent
4da7a566f7
commit
915c465224
@ -20,12 +20,12 @@ type SkinItem struct {
|
||||
|
||||
func (s *SkinItem) Save() {
|
||||
str, _ := json.Marshal(s)
|
||||
services.Redis.Cmd("SET", tools.BuildKey(s.Nickname), str)
|
||||
services.RedisPool.Cmd("SET", tools.BuildKey(s.Nickname), 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) {
|
||||
|
@ -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
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"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"
|
||||
@ -15,7 +15,7 @@ import (
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
||||
client, redisErr := redis.Dial("tcp", "redis:6379")
|
||||
pool, redisErr := pool.New("tcp", "redis:6379", 10)
|
||||
if redisErr != nil {
|
||||
log.Fatal("Redis unavailable")
|
||||
}
|
||||
@ -36,7 +36,7 @@ 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
|
||||
|
||||
log.Fatal(http.ListenAndServe(":80", router))
|
||||
|
Loading…
Reference in New Issue
Block a user