mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 18:08:14 -05:00
optimization redis recorder
This commit is contained in:
parent
e76ec30c92
commit
b946283696
@ -29,19 +29,17 @@ func NewRedis(c *conf.RedisConfig) *Redis {
|
||||
func (r *Redis) SyncOnlineIp(Ips []dispatcher.UserIpList) ([]dispatcher.UserIpList, error) {
|
||||
ctx := context.Background()
|
||||
for i := range Ips {
|
||||
if !r.client.SIsMember(ctx, "UserList", strconv.Itoa(Ips[i].Uid)).Val() {
|
||||
err := r.client.SAdd(ctx, "UserList", Ips[i].Uid).Err()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("add user failed: %s", err)
|
||||
}
|
||||
err := r.client.SAdd(ctx, "UserList", Ips[i].Uid).Err()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("add user failed: %s", err)
|
||||
}
|
||||
r.client.Expire(ctx, "UserList", time.Duration(2)*time.Minute)
|
||||
r.client.Expire(ctx, "UserList", 2*time.Minute)
|
||||
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), time.Duration(2)*time.Minute)
|
||||
r.client.Expire(ctx, strconv.Itoa(Ips[i].Uid), 2*time.Minute)
|
||||
}
|
||||
}
|
||||
c := r.client.SMembers(ctx, "UserList")
|
||||
|
@ -14,7 +14,7 @@ func TestRedis_SyncOnlineIp(t *testing.T) {
|
||||
Db: 0,
|
||||
})
|
||||
users, err := r.SyncOnlineIp([]dispatcher.UserIpList{
|
||||
{2, []string{"3.3.3.3", "4.4.4.4"}},
|
||||
{1, []string{"5.5.5.5", "4.4.4.4"}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user