package resume

import (
	"World/conf"
	"errors"
	"common/redis"
	"strconv"
	"common/logger"
)

const USER_TOKEN_KEY = "login_token"

var gRedis *redis.RedisClient = nil

func GetRedisClient() *redis.RedisClient{
	return gRedis
}

func TestMyredis() {
	gRedis.HSet("luheng","luhengsb","22")
	gRedis.HSet("luheng","luhengbb","33")
}

func Init() error {
	redis_cfg := conf.GetRedisConf()
	if gRedis = redis.NewRedisClient(redis_cfg.Host, redis_cfg.Password, redis_cfg.Db); gRedis == nil {
		return errors.New("initRedis error")
	}

	//TestMyredis()
	return nil
}

/*
	加载token
 */
func LoadPlayerTokenFromRedis(uid int) (string,error){
	token,err := gRedis.HGet(USER_TOKEN_KEY,strconv.Itoa(uid))
	if err != nil {
		logger.Notic("LoadPlayerTokenFromRedis failed uid:%v err%v",uid,err)
		return "",err
	}
	return token,err
}
