I am trying to push data in redis queue from my Go Consumer.
The package I am using is "github.com/kavu/go-resque"
The redis Driver I am using is "github.com/kavu/go-resque/go-redis" and "github.com/go-redis/redis"
My code looks like this :
"github.com/kavu/go-resque"
_"github.com/kavu/go-resque/go-redis"
"github.com/go-redis/redis"
"time"
"strings"
redisClient := redis.NewClient(&redis.Options{
Addr: myRedisIp,
Password: "", // no password set
DB: 0, // use default DB
DialTimeout: 10 * time.Second,
})
enqueuer := resque.NewRedisEnqueuer("go-redis", redisClient,"test-redis")
_, err := enqueuer.Enqueue("resque:queue:myQueueName", "Demo::Job", 1, 2, "test")
if err != nil {
fmt.Println("putting into queue failed error="+err.Error())
}else{
fmt.Println("putting into queue success")
}
I was finally able to implement this. Sharing steps :
Install Packages
Resque Package : "github.com/kavu/go-resque"
Also, install the driver package i.e. redis package you want the resque to use.
There are multiple options for that eg: Go-redis, Godis, hoisie,redisGo etc
In my case, I was am Go-Redis.
So, I installed
"github.com/kavu/go-resque/go-redis"
"github.com/go-redis/redis"
Then set Up the redis Client
rc := redisQueue.New("Your redis server IP")
Set Up resque struct
enqueuer := resque.NewRedisEnqueuer("redis-go", rc,"resque:")
Here, first parameter is driver name like godis,redis-go etc. Second parameter is redis Client i.e. Go-redis client or godis client etc. Third parameter is namespace. That is what you want to append in your queueName.
Then enqueue the packet into queue
NumPacketsInQueue, err = enqueuer.Enqueue(queueName,"",args1,args2...)
The second empty parameter in above code line is job Class.I have kept it empty.
Here, the final queuename will be resque:queue:queueName
Links: