redis.go 690 B

12345678910111213141516171819202122232425262728293031
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/pkg/errors"
  6. )
  7. func assetRelationKey(mid int64) string {
  8. return fmt.Sprintf("up_ar_%d", mid)
  9. }
  10. func assetRelationField(oid int64, otype string) string {
  11. return fmt.Sprintf("%s_%d", otype, oid)
  12. }
  13. // DelCacheAssetRelationState delete asset relation state.
  14. func (d *Dao) DelCacheAssetRelationState(c context.Context, oid int64, otype string, mid int64) (err error) {
  15. var (
  16. key = assetRelationKey(mid)
  17. field = assetRelationField(oid, otype)
  18. conn = d.redis.Get(c)
  19. )
  20. defer conn.Close()
  21. if _, err = conn.Do("HDEL", key, field); err != nil {
  22. err = errors.Wrapf(err, "conn.Do(HDEL, %s, %s)", key, field)
  23. return
  24. }
  25. return
  26. }