// Put gets a randSoruce idx to ensure some thread safety func Put(randSource int) { var d *disque.Disque var err error d, err = p.Get(context.Background()) // get a connection from the pool if err != nil { log.Println(err) } _, err = d.Push(queueName, RandStringBytesMaskImprSrc(randSource, msgLength), time.Second*20) if err != nil { log.Fatal(err) } p.Put(d) // return a connection to the pool }
// Get gets from given queue func Get() { var d *disque.Disque var err error d, err = p.Get(context.Background()) // get a connection from the pool if err != nil { log.Println(err) } _, err = d.Fetch(queueName, time.Second*1) if err != nil { log.Fatal(err) } p.Put(d) // return a connection to the pool }