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.
46 lines
637 B
46 lines
637 B
package internal |
|
|
|
import ( |
|
"context" |
|
"time" |
|
|
|
"github.com/go-redis/redis/v8/internal/util" |
|
) |
|
|
|
func Sleep(ctx context.Context, dur time.Duration) error { |
|
t := time.NewTimer(dur) |
|
defer t.Stop() |
|
|
|
select { |
|
case <-t.C: |
|
return nil |
|
case <-ctx.Done(): |
|
return ctx.Err() |
|
} |
|
} |
|
|
|
func ToLower(s string) string { |
|
if isLower(s) { |
|
return s |
|
} |
|
|
|
b := make([]byte, len(s)) |
|
for i := range b { |
|
c := s[i] |
|
if c >= 'A' && c <= 'Z' { |
|
c += 'a' - 'A' |
|
} |
|
b[i] = c |
|
} |
|
return util.BytesToString(b) |
|
} |
|
|
|
func isLower(s string) bool { |
|
for i := 0; i < len(s); i++ { |
|
c := s[i] |
|
if c >= 'A' && c <= 'Z' { |
|
return false |
|
} |
|
} |
|
return true |
|
}
|
|
|