expiry can be taken from options or record (#1928)
This commit is contained in:
parent
b6e1c7ac99
commit
69a53e8070
@ -422,13 +422,14 @@ func (s *sqlStore) Write(r *store.Record, opts ...store.WriteOption) error {
|
|||||||
metadata[k] = v
|
metadata[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Expiry != 0 {
|
var expiry time.Time
|
||||||
_, err = st.Exec(r.Key, r.Value, metadata, time.Now().Add(r.Expiry))
|
// expiry from options takes precedence
|
||||||
} else {
|
if !options.Expiry.IsZero() {
|
||||||
_, err = st.Exec(r.Key, r.Value, metadata, nil)
|
expiry = options.Expiry
|
||||||
|
} else if r.Expiry != 0 {
|
||||||
|
expiry = time.Now().Add(r.Expiry)
|
||||||
}
|
}
|
||||||
|
if _, err := st.Exec(r.Key, r.Value, metadata, expiry); err != nil {
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "Couldn't insert record "+r.Key)
|
return errors.Wrap(err, "Couldn't insert record "+r.Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user