本文整理汇总了Golang中github.com/bogdanovich/siberite/queue.Queue类的典型用法代码示例。如果您正苦于以下问题:Golang Queue类的具体用法?Golang Queue怎么用?Golang Queue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Queue类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CloseAllQueues
// CloseAllQueues closes all queues
func (repo *QueueRepository) CloseAllQueues() error {
var err error
var q *queue.Queue
for pair := range repo.storage.IterBuffered() {
q, err = repo.GetQueue(pair.Key)
if err != nil {
return err
}
q.Close()
}
return nil
}
示例2: CloseAllQueues
func (self *QueueRepository) CloseAllQueues() error {
var err error
var q *queue.Queue
for pair := range self.storage.Iter() {
q, err = self.GetQueue(pair.Key)
if err != nil {
return err
}
q.Close()
}
return nil
}
示例3: FullStats
// FullStats gets repository stats
func (repo *QueueRepository) FullStats() []StatItem {
stats := []StatItem{}
currentTime := time.Now().Unix()
stats = append(stats, StatItem{"uptime", fmt.Sprintf("%d", currentTime-repo.Stats.StartTime)})
stats = append(stats, StatItem{"time", fmt.Sprintf("%d", currentTime)})
stats = append(stats, StatItem{"version", fmt.Sprintf("%s", repo.Stats.Version)})
stats = append(stats, StatItem{"curr_connections", fmt.Sprintf("%d", repo.Stats.CurrentConnections)})
stats = append(stats, StatItem{"total_connections", fmt.Sprintf("%d", repo.Stats.TotalConnections)})
stats = append(stats, StatItem{"cmd_get", fmt.Sprintf("%d", repo.Stats.CmdGet)})
stats = append(stats, StatItem{"cmd_set", fmt.Sprintf("%d", repo.Stats.CmdSet)})
var q *queue.Queue
for pair := range repo.storage.IterBuffered() {
q = pair.Val.(*queue.Queue)
stats = append(stats, StatItem{"queue_" + q.Name + "_items", fmt.Sprintf("%d", q.Length())})
stats = append(stats, StatItem{"queue_" + q.Name + "_open_transactions", fmt.Sprintf("%d", q.Stats.OpenTransactions)})
}
return stats
}
示例4: Test_Initialize
func Test_Initialize(t *testing.T) {
repo, err := Initialize(dir)
assert.Nil(t, err)
// Create 3 queues and push some data
queueNames := []string{"test1", "test2", "test3"}
var q *queue.Queue
totalItems := 3
for i := 0; i < len(queueNames); i++ {
q, _ = repo.GetQueue(queueNames[i])
for j := 0; j < totalItems; j++ {
q.Enqueue([]byte("value"))
}
// Get one element out
_, _ = q.Dequeue()
}
// Close all queues and destroy repo
repo.CloseAllQueues()
repo = nil
// Initialize repo again and check loaded queues
repo, err = Initialize(dir)
assert.Nil(t, err)
assert.Equal(t, repo.Count(), 3, "Invalid repo count after initialization")
for i := 0; i < len(queueNames); i++ {
q, _ = repo.GetQueue(queueNames[i])
assert.Equal(t, q.Head(), uint64(1), "Invalid queue initialization")
assert.Equal(t, q.Tail(), uint64(totalItems), "Invalid queue initialization")
assert.Equal(t, q.Length(), uint64(totalItems-1), "Invalid queue initialization")
}
repo.DeleteAllQueues()
}