You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
637 B

  1. package internal
  2. import (
  3. "context"
  4. "time"
  5. "github.com/go-redis/redis/v8/internal/util"
  6. )
  7. func Sleep(ctx context.Context, dur time.Duration) error {
  8. t := time.NewTimer(dur)
  9. defer t.Stop()
  10. select {
  11. case <-t.C:
  12. return nil
  13. case <-ctx.Done():
  14. return ctx.Err()
  15. }
  16. }
  17. func ToLower(s string) string {
  18. if isLower(s) {
  19. return s
  20. }
  21. b := make([]byte, len(s))
  22. for i := range b {
  23. c := s[i]
  24. if c >= 'A' && c <= 'Z' {
  25. c += 'a' - 'A'
  26. }
  27. b[i] = c
  28. }
  29. return util.BytesToString(b)
  30. }
  31. func isLower(s string) bool {
  32. for i := 0; i < len(s); i++ {
  33. c := s[i]
  34. if c >= 'A' && c <= 'Z' {
  35. return false
  36. }
  37. }
  38. return true
  39. }