1
0
mirror of https://github.com/FloatTech/zbpdata.git synced 2024-11-17 17:47:14 +09:00
This commit is contained in:
源文雨 2022-04-17 21:17:33 +08:00
parent 6d4212b19d
commit b3d25c45fd

29
main.go
View File

@ -14,6 +14,7 @@ import (
"unicode" "unicode"
"unsafe" "unsafe"
"github.com/FloatTech/zbputils/process"
"github.com/fumiama/go-registry" "github.com/fumiama/go-registry"
"github.com/wdvxdr1123/ZeroBot/utils/helper" "github.com/wdvxdr1123/ZeroBot/utils/helper"
) )
@ -46,26 +47,24 @@ func main() {
panic(err) panic(err)
} }
defer r.Close() defer r.Close()
do1024 := func(k, v string) (err error) {
for i := 0; i < 1024; i++ {
err = r.Set(k, v)
if err == nil {
break
}
fmt.Println("accqiring set lock, retry times:", i)
}
return
}
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(len(files)) wg.Add(len(files))
for i, fn := range files { for i, fn := range files {
go func(i int, fn string) { go func(i int, fn string) {
err := do1024("data/"+fn, md5s[i]) defer wg.Done()
if err != nil { for c := 0; c < 5; c++ {
panic(err) err = r.Set("data/"+fn, md5s[i])
}
fmt.Println("set", "data/"+fn, "=", hex.EncodeToString(helper.StringToBytes(md5s[i]))) fmt.Println("set", "data/"+fn, "=", hex.EncodeToString(helper.StringToBytes(md5s[i])))
wg.Done() if err == nil {
break
}
if c >= 4 {
panic("ERROR:" + err.Error() + "max retry times exceeded")
} else {
fmt.Println("ERROR:", err, ", retry times:", c)
}
process.SleepAbout1sTo2s()
}
}(i, fn) }(i, fn)
} }
wg.Wait() wg.Wait()