func init() {
pwd_path, _ := os.Getwd()
file_path := pwd_path + "/config"
log_file_path = pwd_path + "/push_log.log"
url := share_api.Get_config_info("mysql", "mysql_url", file_path)
err := dbvisit.Connect_db(url)
share_api.Check_err("connect mysql err:", err)
//连接ald_services数据库中app_token_info表
//redis
redis_url := share_api.Get_config_info("redis", "redis_url", file_path)
passwd := share_api.Get_config_info("redis", "passwd", file_path)
num_str := share_api.Get_config_info("redis", "redis_num", file_path)
num, _ := strconv.Atoi(num_str)
c = redis.NewClient(&redis.Options{
Addr: redis_url,
Password: passwd, // no password set
DB: num, // use default DB
})
}
func add(){
temp := make(map[string]interface{})
temp["app_key"] = "asdf"
temp["msg_key"] = "gc123"
temp["form_id"] = "123456"
redis_key := "push_api!" + app_key + "@" + msg_key + "#" + form_id
log.Println("==============redis_key================\n", redis_key)
temp_json, _ := json.Marshal(temp)
res := c.Set(redis_key, temp_json, 0)
log.Println("=============redis set res===========:", res)
}
有疑问加站长微信联系(非本文作者)