MCPcopy Create free account
hub / github.com/beeker1121/goque / Example_prefixQueue

Function Example_prefixQueue

example_prefix_queue_test.go:10–51  ·  view source on GitHub ↗

ExamplePrefixQueue demonstrates the implementation of a Goque queue.

()

Source from the content-addressed store, hash-verified

8
9// ExamplePrefixQueue demonstrates the implementation of a Goque queue.
10func Example_prefixQueue() {
11 // Open/create a prefix queue.
12 pq, err := goque.OpenPrefixQueue("data_dir")
13 if err != nil {
14 fmt.Println(err)
15 return
16 }
17 defer pq.Close()
18
19 // Enqueue an item.
20 item, err := pq.Enqueue([]byte("prefix"), []byte("item value"))
21 if err != nil {
22 fmt.Println(err)
23 return
24 }
25
26 fmt.Println(item.ID) // 1
27 fmt.Println(item.Key) // [112 114 101 102 105 120 0 0 0 0 0 0 0 0 1]
28 fmt.Println(item.Value) // [105 116 101 109 32 118 97 108 117 101]
29 fmt.Println(item.ToString()) // item value
30
31 // Change the item value in the queue.
32 item, err = pq.Update([]byte("prefix"), item.ID, []byte("new item value"))
33 if err != nil {
34 fmt.Println(err)
35 return
36 }
37
38 fmt.Println(item.ToString()) // new item value
39
40 // Dequeue the next item.
41 deqItem, err := pq.Dequeue([]byte("prefix"))
42 if err != nil {
43 fmt.Println(err)
44 return
45 }
46
47 fmt.Println(deqItem.ToString()) // new item value
48
49 // Delete the queue and its database.
50 pq.Drop()
51}

Callers

nothing calls this directly

Calls 7

OpenPrefixQueueFunction · 0.92
CloseMethod · 0.45
EnqueueMethod · 0.45
ToStringMethod · 0.45
UpdateMethod · 0.45
DequeueMethod · 0.45
DropMethod · 0.45

Tested by

no test coverage detected