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