Skip to content

Instantly share code, notes, and snippets.

@brandonros
Created April 29, 2018 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonros/7cf2b7d7f44e09ecff7bf7aecb3b1041 to your computer and use it in GitHub Desktop.
Save brandonros/7cf2b7d7f44e09ecff7bf7aecb3b1041 to your computer and use it in GitHub Desktop.
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