fix(backend): don't use redis GETDEL

This commit is contained in:
Sam 2023-04-20 01:30:33 +02:00
parent 661f0254fd
commit 86a1841f4f
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
2 changed files with 6 additions and 25 deletions

View file

@ -137,30 +137,6 @@ func (db *DB) GetJSON(ctx context.Context, key string, v any) error {
return nil
}
// GetDelJSON gets the given key as a JSON object and deletes it.
func (db *DB) GetDelJSON(ctx context.Context, key string, v any) error {
var b []byte
err := db.Redis.Do(ctx, radix.Cmd(&b, "GETDEL", key))
if err != nil {
return errors.Wrap(err, "reading from Redis")
}
if b == nil {
return nil
}
if v == nil {
return fmt.Errorf("nil pointer passed into GetDelJSON")
}
err = json.Unmarshal(b, v)
if err != nil {
return errors.Wrap(err, "unmarshaling json")
}
return nil
}
// NotNull is a little helper that returns an *empty slice* when the slice's length is 0.
// This is to prevent nil slices from being marshaled as JSON null
func NotNull[T any](slice []T) []T {