本文整理汇总了Golang中github.com/bogdanovich/siberite/queue.Queue.Length方法的典型用法代码示例。如果您正苦于以下问题:Golang Queue.Length方法的具体用法?Golang Queue.Length怎么用?Golang Queue.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bogdanovich/siberite/queue.Queue
的用法示例。
在下文中一共展示了Queue.Length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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()
}
示例2: 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
}