Skip to content

Commit

Permalink
设置有效过期时长
Browse files Browse the repository at this point in the history
  • Loading branch information
mingye.fan authored and mingye.fan committed Nov 24, 2021
1 parent 2833592 commit b4dc60d
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions xredis_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ func (c *Client) setListValue(ctx context.Context, key string, valValue reflect.
if err != nil {
return err
}
if options.Expiration != -1 {
return c.Expire(ctx, key, options.Expiration).Err()
err = c.expireKeyTTl(ctx, key, options.Expiration)
if err != nil {
return err
}
return nil
}
Expand All @@ -165,8 +166,9 @@ func (c *Client) setSetValue(ctx context.Context, key string, valValue reflect.V
if err != nil {
return err
}
if options.Expiration != -1 {
return c.Expire(ctx, key, options.Expiration).Err()
err = c.expireKeyTTl(ctx, key, options.Expiration)
if err != nil {
return err
}
return nil
}
Expand All @@ -186,8 +188,9 @@ func (c *Client) setStructValue(ctx context.Context, key string, valValue reflec
if err != nil {
return err
}
if options.Expiration != -1 {
return c.Expire(ctx, key, options.Expiration).Err()
err = c.expireKeyTTl(ctx, key, options.Expiration)
if err != nil {
return err
}
return nil
}
Expand All @@ -207,8 +210,17 @@ func (c *Client) setMapValue(ctx context.Context, key string, valValue reflect.V
if err != nil {
return err
}
if options.Expiration != -1 {
return c.Expire(ctx, key, options.Expiration).Err()
err = c.expireKeyTTl(ctx, key, options.Expiration)
if err != nil {
return err
}
return nil
}

// 设置有效过期时长
func (c *Client) expireKeyTTl(ctx context.Context, key string, expiration time.Duration) error {
if expiration > 0 {
return c.Expire(ctx, key, expiration).Err()
}
return nil
}

0 comments on commit b4dc60d

Please sign in to comment.