fcbc25e789
We are replacing the very outdated redigo Go module with the official redis Go module, go-redis. Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
46 lines
637 B
Go
46 lines
637 B
Go
package internal
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/redis/go-redis/v9/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
|
|
}
|