This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from CaioDallaqua/patch-1
Adding flush command
- Loading branch information
Showing
5 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |