Exemple #1
0
func newQueue(redisHost, redisPort, redisPassword string, redisDB int64, name string) *Queue {
	q := &Queue{Name: name}
	q.redisClient = redis.NewTCPClient(redisHost+":"+redisPort, redisPassword, redisDB)
	q.redisClient.SAdd(masterQueueKey(), name)
	q.startStatsWriter()
	return q
}
Exemple #2
0
func NewQueue(goenv *goenv.Goenv, name string) *Queue {
	q := &Queue{Name: name}
	host, port, db := goenv.GetRedis()
	q.redisClient = redis.NewTCPClient(host+":"+port, "", int64(db))
	q.redisClient.SAdd(MasterQueueKey(), name)
	return q
}
Exemple #3
0
//TODO Test this?
func NewOverseer(goenv *goenv.Goenv) *Overseer {
	q := &Overseer{goenv: goenv, Stats: make(map[string]*QueueStat)}
	host, port, db := goenv.GetRedis()
	q.redisClient = redis.NewTCPClient(host+":"+port, "", int64(db))

	for _, queue := range q.GetAllQueues() {
		q.WatchQueue(queue)
	}
	return q
}
Exemple #4
0
func newObserver(redisURL, redisPassword string, redisDb int64) *observer {
	q := &observer{
		RedisURL:      redisURL,
		RedisPassword: redisPassword,
		RedisDb:       redisDb,
		Stats:         make(map[string]*queueStat),
	}
	q.redisClient = redis.NewTCPClient(redisURL, redisPassword, redisDb)
	return q
}
Exemple #5
0
// NewObserver returns an Oberserver to monitor different statistics from redis
func NewObserver(redisHost, redisPort, redisPassword string, redisDb int64) *Observer {
	q := &Observer{
		redisHost:     redisHost,
		redisPort:     redisPort,
		redisPassword: redisPassword,
		redisDb:       redisDb,
		Stats:         make(map[string]*QueueStat),
	}
	q.redisClient = redis.NewTCPClient(redisHost+":"+redisPort, redisPassword, redisDb)
	return q
}
Exemple #6
0
// NewBufferedQueue returns BufferedQueue.
// To start writing the buffer to redis use Start().
// Optimal BufferSize seems to be around 200.
func NewBufferedQueue(redisURL, redisPassword string, redisDB int64, name string, bufferSize int) (q *BufferedQueue) {
	q = &BufferedQueue{
		Queue:        &Queue{Name: name},
		BufferSize:   bufferSize,
		Buffer:       make(chan *Package, bufferSize*2),
		flushStatus:  make(chan chan bool, 1),
		flushCommand: make(chan bool, bufferSize*2),
	}
	q.redisClient = redis.NewTCPClient(redisURL, redisPassword, redisDB)
	return q
}
Exemple #7
0
// SelectQueue returns a Queue if a queue with the name exists
func SelectQueue(redisHost, redisPort, redisPassword string, redisDB int64, name string) (queue *Queue, err error) {

	redisClient := redis.NewTCPClient(redisHost+":"+redisPort, redisPassword, redisDB)
	answer := redisClient.SIsMember(masterQueueKey(), name)
	defer redisClient.Close()

	if answer.Val() == false {
		return nil, fmt.Errorf("queue with this name doesn't exist")
	}

	return newQueue(redisHost, redisPort, redisPassword, redisDB, name), nil
}
Exemple #8
0
func (suite *TestSuite) SetUpSuite(c *C) {
	runtime.GOMAXPROCS(8)
	rand.Seed(time.Now().UTC().UnixNano())
	suite.redisClient = redis.NewTCPClient(redisHost+":"+redisPort, redisPassword, redisDB)
}
Exemple #9
0
// NewQueue return a queue that you can Put() or AddConsumer() to
func NewQueue(redisURL, redisPassword string, redisDB int64, name string) *Queue {
	q := &Queue{Name: name}
	q.redisClient = redis.NewTCPClient(redisURL, redisPassword, redisDB)
	q.redisClient.SAdd(masterQueueKey(), name)
	return q
}