Skip to content

Commit

Permalink
bugfix: Add keep-alive to prevent target Redis close conn due to timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
suxb201 committed Mar 5, 2024
1 parent 906a5b9 commit 256dd64
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions cmd/redis-shake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/signal"
"syscall"
"time"

"RedisShake/internal/config"
"RedisShake/internal/entry"
Expand Down Expand Up @@ -120,20 +121,37 @@ func main() {
ch := theReader.StartRead(ctx)
go waitShutdown(cancel)

for e := range ch {
// calc arguments
e.Parse()
status.AddReadCount(e.CmdName)

// filter
log.Debugf("function before: %v", e)
entries := luaRuntime.RunFunction(e)
log.Debugf("function after: %v", entries)

for _, entry := range entries {
entry.Parse()
theWriter.Write(entry)
status.AddWriteCount(entry.CmdName)
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
Loop:
for {
select {
case e, ok := <-ch:
if !ok {
// ch has been closed, exit the loop
break Loop
}
// calc arguments
e.Parse()
status.AddReadCount(e.CmdName)

// filter
log.Debugf("function before: %v", e)
entries := luaRuntime.RunFunction(e)
log.Debugf("function after: %v", entries)

for _, theEntry := range entries {
theEntry.Parse()
theWriter.Write(theEntry)
status.AddWriteCount(theEntry.CmdName)
}
case <-ticker.C:
pingEntry := entry.NewEntry()
pingEntry.DbId = 0
pingEntry.CmdName = "PING"
pingEntry.Argv = []string{"PING"}
pingEntry.Group = "connection"
theWriter.Write(pingEntry)
}
}

Expand Down

0 comments on commit 256dd64

Please sign in to comment.