package city

import (
	"github.com/gomodule/redigo/redis"
	"miads/adslib/ads_redis"
)

func GetCityCode(city string) (int, error) {
	conn := ads_redis.RedisConn.Get()
	defer conn.Close()
	redisKey := "ads_city_" + city
	rsp, err := conn.Do("GET", redisKey)
	if err != nil {
		return 0, err
	}
	if rsp == nil {
		return 0, nil
	}

	cityCode, err := redis.Int(rsp, err)
	return cityCode, nil
}
