forked from shadowspore/t38c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflush_db.go
60 lines (50 loc) · 1.17 KB
/
flush_db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//go:build ignore
// +build ignore
package main
import (
"context"
"log"
"github.com/xjem/t38c"
)
/*
* FLUSHDB Example
*
* Shows how to erase all data in Tile38
* database using the FLUSHDB command.
*
*/
func main() {
// Create a Tile38 client.
tile38, err := t38c.New(t38c.Config{
Address: "localhost:9851",
Debug: true,
})
if err != nil {
log.Fatal(err)
}
defer tile38.Close()
// Add a point named 'truck1' to a collection named 'first fleet'.
if err = tile38.Keys.Set("first fleet", "truck1").Point(33.5123, -112.2693).Do(context.TODO()); err != nil {
log.Fatal(err)
}
// Add a point named 'truck2' to a collection named 'second fleet'.
if err = tile38.Keys.Set("second fleet", "truck2").Point(23.6951, -92.3581).Do(context.TODO()); err != nil {
log.Fatal(err)
}
// Get all keys.
// Returns ["first fleet","second fleet"].
_, err = tile38.Keys.Keys(context.TODO(), "*")
if err != nil {
log.Fatal(err)
}
// Flush ALL data in Tile38 database.
if err = tile38.Server.FlushDB(context.TODO()); err != nil {
log.Fatal(err)
}
// Get all keys again.
// Returns [].
_, err = tile38.Keys.Keys(context.TODO(), "*")
if err != nil {
log.Fatal(err)
}
}