-
-
Save brandonros/7cf2b7d7f44e09ecff7bf7aecb3b1041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"time" | |
"os" | |
"github.com/go-redis/redis" | |
) | |
func makeTimestamp() int64 { | |
return time.Now().UnixNano() / (int64(time.Millisecond)/int64(time.Nanosecond)) | |
} | |
func main() { | |
index := os.Args[1] | |
queueKey := "fjq:jobs:" + index | |
client := redis.NewClient(&redis.Options{ | |
Addr: "localhost:6379", | |
Password: "", // no password set | |
DB: 0, // use default DB | |
}) | |
defer client.Close() | |
handled := 0 | |
start := makeTimestamp() | |
for { | |
_, err := client.BLPop(0, queueKey).Result() | |
if err != nil { | |
log.Fatal(err) | |
} | |
handled += 1 | |
if (handled % 1000 == 0) { | |
now := makeTimestamp() | |
elapsed := now - start | |
log.Println(handled, elapsed, float64(handled) / float64(elapsed) * 1000.0) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment