func LoadDb() {
	r := common.DefaultRedisPool().Get()
	defer r.Close()

	// 서버 목록들을 읽어와서 IRCClient를 생성하고 접속
	reply, err := redis.Values(r.Do("KEYS", "servers:*"))
	if err != nil {
		log.Println("LoadDb: ", err)
		os.Exit(1)
	}
	for _, key := range reply {
		key, _ := redis.String(key, nil)
		var servers []*common.IRCServer
		err = common.RedisSliceLoad(key, &servers)
		if err != nil {
			log.Println("LoadDb: ", err)
			os.Exit(1)
		}
		for _, server := range servers {
			server.Active = false
			ircMgr.register <- NewClient(server)
		}
	}

	// 채널 목록을 읽어와서 채널을 추가
	reply, err = redis.Values(r.Do("KEYS", "channels:*"))
	if err != nil {
		log.Println("LoadDb: ", err)
		os.Exit(1)
	}
	for _, key := range reply {
		key, _ := redis.String(key, nil)
		var channels []*common.IRCChannel
		err = common.RedisSliceLoad(key, &channels)
		if err != nil {
			log.Println("LoadDb: ", err)
			os.Exit(1)
		}
		for _, channel := range channels {
			c := ircMgr.GetClient(channel.UserId, channel.ServerId)
			channel.Joined = false
			c.AddChannel(channel.Name)
		}
	}
}
func (um *UserManager) GetUserByKey(key string) (*User, error) {
	r := common.DefaultRedisPool().Get()
	defer r.Close()

	id, err := redis.String(r.Do("HGET", "key", key))
	if err != nil {
		return nil, &CacheNotFound{key: key}
	}
	return um.GetUserById(id)
}
示例#3
0
func (um *UserManager) GetUserByKey(key string) (*User, error) {
	r := common.DefaultRedisPool().Get()
	defer r.Close()

	redisKey := "key:" + key
	id, err := redis.String(r.Do("GET", redisKey))
	if err != nil {
		return nil, &CacheNotFound{key: key}
	}
	r.Do("EXPIRE", redisKey, 172800)
	return um.GetUserById(id)
}