add redis recorder expiry time

This commit is contained in:
yuzuki999 2022-11-18 10:18:26 +08:00
parent 465f5d5bf1
commit 717a8d1d24
3 changed files with 4 additions and 2 deletions

View File

@ -33,13 +33,13 @@ func (r *Redis) SyncOnlineIp(Ips []dispatcher.UserIpList) ([]dispatcher.UserIpLi
if err != nil {
return nil, fmt.Errorf("add user failed: %s", err)
}
r.client.Expire(ctx, "UserList", 2*time.Minute)
r.client.Expire(ctx, "UserList", time.Second*time.Duration(r.Expiry))
for _, ip := range Ips[i].IpList {
err := r.client.SAdd(ctx, strconv.Itoa(Ips[i].Uid), ip).Err()
if err != nil {
return nil, fmt.Errorf("add ip failed: %s", err)
}
r.client.Expire(ctx, strconv.Itoa(Ips[i].Uid), 2*time.Minute)
r.client.Expire(ctx, strconv.Itoa(Ips[i].Uid), time.Second*time.Duration(r.Expiry))
}
}
c := r.client.SMembers(ctx, "UserList")

View File

@ -29,6 +29,7 @@ type RedisConfig struct {
Address string `yaml:"Address"`
Password string `yaml:"Password"`
Db int `yaml:"Db"`
Expiry int `json:"Expiry"`
}
type IpReportConfig struct {

View File

@ -51,6 +51,7 @@ Nodes:
Address: "127.0.0.1:6379" # Redis address
Password: "" # Redis password
DB: 0 # Redis DB
Expiry: 60 # redis expiry time, sec.
Periodic: 60 # Report interval, sec.
EnableIpSync: false # Enable online ip sync
EnableDynamicSpeedLimit: false # Enable dynamic speed limit