chore: add more tests (#3338)

This commit is contained in:
Kevin Wan
2023-06-12 01:22:20 +08:00
committed by GitHub
parent efa6940001
commit f6bdb6e1de
11 changed files with 99 additions and 46 deletions

View File

@@ -97,6 +97,9 @@ func (cc CachedConn) Exec(exec ExecFn, keys ...string) (sql.Result, error) {
}
// ExecCtx runs given exec on given keys, and returns execution result.
// If DB operation succeeds, it will delete cache with given keys,
// if DB operation fails, it will return nil result and non-nil error,
// if DB operation succeeds but cache deletion fails, it will return result and non-nil error.
func (cc CachedConn) ExecCtx(ctx context.Context, exec ExecCtxFn, keys ...string) (
sql.Result, error) {
res, err := exec(ctx, cc.db)
@@ -104,11 +107,7 @@ func (cc CachedConn) ExecCtx(ctx context.Context, exec ExecCtxFn, keys ...string
return nil, err
}
if err := cc.DelCacheCtx(ctx, keys...); err != nil {
return nil, err
}
return res, nil
return res, cc.DelCacheCtx(ctx, keys...)
}
// ExecNoCache runs exec with given sql statement, without affecting cache.