Skip to content

Commit

Permalink
add expiration data to database object
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Sep 18, 2020
1 parent 4dd6e6c commit 0416849
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redis
import (
"context"
"encoding/json"
"time"

"github.com/Pantani/errors"
"github.com/go-redis/redis/v8"
Expand Down Expand Up @@ -43,12 +44,12 @@ func (db *Redis) GetObject(ctx context.Context, key string, value interface{}) e

// AddObject add object for a key.
// It returns an error if occurs.
func (db *Redis) AddObject(ctx context.Context, key string, value interface{}) error {
func (db *Redis) AddObject(ctx context.Context, key string, value interface{}, duration time.Duration) error {
j, err := json.Marshal(value)
if err != nil {
return errors.E("fail to marshal value", err, errors.Params{"key": key})
}
cmd := db.client.Set(ctx, key, j, 0)
cmd := db.client.Set(ctx, key, j, duration)
if err := cmd.Err(); err != nil {
return errors.E("not stored", err, errors.Params{"key": key})
}
Expand Down

0 comments on commit 0416849

Please sign in to comment.