Files
selfcare/proxy/Nredis/plan_expiry.go
2025-03-25 09:46:16 +08:00

34 lines
779 B
Go

package Nredis
import (
l4g "proxy/logger"
"strconv"
"time"
)
func CheckIfBundleLimitSent(planId uint32, rate int) bool {
n, err := rdb.Exists(ctx, "BundleLimit:"+strconv.Itoa(int(planId))+":"+strconv.Itoa(rate)).Result()
if err != nil {
l4g.RedisLog.Errorf("Check Exists PlanExpiry:%d, err: %v", planId, err)
return false
} else {
if n >= 1 {
return true
} else {
return false
}
}
}
func SetPlanExpire(planId uint32, rate int) error {
key := "BundleLimit:"+strconv.Itoa(int(planId))+":"+strconv.Itoa(rate)
err := rdb.Set(ctx, key, "1", time.Hour * 24 * 15).Err()
if err != nil {
l4g.RedisLog.Errorf("Set BundleLimit:%d:%d, err: %v", planId, rate, err)
} else {
l4g.RedisLog.Debugf("Set BundleLimit:%d:%d, succ", planId, rate)
}
return err
}