package reminder import ( "fmt" "git.getensh.com/common/gopkgs/cache" ) func getGardenInfoKey(timestamp int64) string { return fmt.Sprintf("propety-urge-garden-info-%d", timestamp) } func getObjUsersOpenidKey(timestamp, gardenId int64) string { return fmt.Sprintf("propety-urge-openid-%d-%d", timestamp, gardenId) } func getObjUsersPhoneKey(timestamp, gardenId int64) string { return fmt.Sprintf("propety-urge-phone-%d-%d", timestamp, gardenId) } func cacheGardenInfo(timestamp int64, info string) { key := getGardenInfoKey(timestamp) _, _ =cache.Redis().SetEx(key, 3600*6, info) } func getGardenInfo(timestamp int64) string { key := getGardenInfoKey(timestamp) str, _ := cache.Redis().Get(key) return str } func cacheAllObjUsersPhone(timestamp, gardenId int64, phones []interface{}) { key := getObjUsersPhoneKey(timestamp, gardenId) cache.Redis().SAdd(key, phones ...) } func cacheAllObjUsersOpenid(timestamp, gardenId int64, openIds []interface{}) { key := getObjUsersOpenidKey(timestamp, gardenId) cache.Redis().SAdd(key, openIds ...) } func popAllObjUsersPhones(timestamp, gardenId int64) []string { key := getObjUsersPhoneKey(timestamp, gardenId) ret, _ := cache.Redis().SMembers(key) _,_ = cache.Redis().Del(key) return ret } func popAllObjUsersOpenids(timestamp, gardenId int64) []string { key := getObjUsersOpenidKey(timestamp, gardenId) ret, _ := cache.Redis().SMembers(key) _,_ = cache.Redis().Del(key) return ret } func delOldObjUsers(timestamp, gardenId int64) { count := 1 // 清空之前7天的缓存,不管有没有 for count < 8 { timestamp -= 3600*24 key := getObjUsersPhoneKey(timestamp, gardenId) _, _ = cache.Redis().Del(key) key = getObjUsersOpenidKey(timestamp, gardenId) _, _ = cache.Redis().Del(key) count++ } }