2021-02-10 22:28:32 +01:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-redis/redis/v8/internal/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Sleep(ctx context.Context, dur time.Duration) error {
|
2021-04-23 02:08:53 +02:00
|
|
|
t := time.NewTimer(dur)
|
|
|
|
defer t.Stop()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-t.C:
|
|
|
|
return nil
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
}
|
2021-02-10 22:28:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|