Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Adding flush command #42

Merged
merged 5 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Tile38 Client
# Tile38 Client for Go
[![Go](https://github.com/xjem/t38c/workflows/Go/badge.svg)](https://github.com/xjem/t38c/actions)
[![Documentation](https://pkg.go.dev/badge/github.com/xjem/t38c)](https://pkg.go.dev/github.com/xjem/t38c?tab=doc)
[![Go Report Card](https://goreportcard.com/badge/github.com/xjem/t38c)](https://goreportcard.com/report/github.com/xjem/t38c)
[![codecov](https://codecov.io/gh/xjem/t38c/branch/master/graph/badge.svg)](https://codecov.io/gh/xjem/t38c)
[![license](https://img.shields.io/github/license/xjem/t38c.svg)](https://github.com/xjem/t38c/blob/master/LICENSE)

Supported features: [click](TODO.md)
See what [Tile38](https://tile38.com/) is all about.

- [Supported features](TODO.md)
- [Examples](examples)

### Installation

```
go get github.com/xjem/t38c
Expand Down Expand Up @@ -54,4 +59,3 @@ func main() {
fmt.Println(response.Points[0].ID, response.Points[0].Point)
}
```
More examples: [click](examples)
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@

# Group 'server'
- [ ] CONFIG GET
- [ ] FLUSHDB
- [x] FLUSHDB
- [ ] SERVER
- [ ] READONLY
- [ ] CONFIG REWRITE
Expand Down
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Client struct {
Channels *Channels
Scripting *Scripting
Geofence *Geofence
Server *Server
}

type clientParams struct {
Expand Down Expand Up @@ -91,6 +92,7 @@ func NewWithExecutor(exec Executor, debug bool) (*Client, error) {
client.Search = &Search{client}
client.Scripting = &Scripting{client}
client.Channels = &Channels{client}
client.Server = &Server{client}

return client, nil
}
Expand Down
61 changes: 61 additions & 0 deletions examples/flush_db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// +build ignore

package main

import (
"log"

"github.com/xjem/t38c"
)

/*
* FLUSHDB Example
*
* Shows how to erase all data in Tile38
* database using the FLUSHDB command.
*
*/

func main() {
// Variables to be used along the way.
var (
err error
tile38 *t38c.Client
)

// Create a Tile38 client.
tile38, err = t38c.New("localhost:9851", t38c.Debug)
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(); 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(); err != nil {
log.Fatal(err)
}

// Get all keys.
// Returns ["first fleet","second fleet"].
_, err = tile38.Keys.Keys("*")
if err != nil {
log.Fatal(err)
}

// Flush ALL data in Tile38 database.
if err = tile38.Server.FlushDB(); err != nil {
log.Fatal(err)
}

// Get all keys again.
// Returns [].
_, err = tile38.Keys.Keys("*")
if err != nil {
log.Fatal(err)
}
}
19 changes: 19 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package t38c

type Server struct {
client tile38Client
}

// WARNING: This erases all data in Tile38 DB!
func (sv *Server) FlushDB() error {
var resp struct{}

err := sv.client.jExecute(&resp, "FLUSHDB")

// Explicit is better than implicit.
if err != nil {
return err
}

return nil
}