cover.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package archive
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "go-common/app/job/main/videoup/model/archive"
  7. "go-common/library/cache/redis"
  8. "go-common/library/log"
  9. )
  10. func vcoverKey(filename string) string {
  11. return fmt.Sprintf("%s_%s", "vcover_", filename)
  12. }
  13. // AddRdsCovers fn.
  14. func (d *Dao) AddRdsCovers(c context.Context, covers []*archive.Cover) (ok bool, err error) {
  15. var conn = d.coverRds.Get(c)
  16. defer conn.Close()
  17. var key string
  18. log.Info("AddRdsCovers info:(%+v)", covers)
  19. for _, c := range covers {
  20. if key == "" {
  21. key = vcoverKey(c.Filename)
  22. }
  23. if err = conn.Send("SADD", key, c.BFSPath); err != nil {
  24. log.Error("conn.Do(SETEX, %s, %s, %d, %d) error(%v)", c.Filename, c.BFSPath, d.coverExpire, time.Now().Unix(), err)
  25. }
  26. }
  27. if err = conn.Send("EXPIRE", key, d.coverExpire); err != nil {
  28. log.Error("conn.Send(EXPIRE, %s, %d) error(%v)", key, d.coverExpire, err)
  29. return
  30. }
  31. if err = conn.Flush(); err != nil {
  32. log.Error("conn.Flush error(%v)", err)
  33. return
  34. }
  35. for i := 0; i < len(covers); i++ {
  36. if ok, err = redis.Bool(conn.Receive()); err != nil {
  37. log.Error("conn.Receive error(%v)", err)
  38. }
  39. }
  40. return
  41. }