Developing lightweight computation at the DSG edge

Commit f9c66144 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[demo] Use the official Antidote Go client repository



Also make the demo a little bit more verbose
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 2e1c3500
......@@ -2,8 +2,9 @@ package main
import (
"fmt"
"time"
"github.com/mweberUKL/go-antidote"
"github.com/AntidoteDB/antidote-go-client"
)
// DatabaseHost defines the host of the AntidoteDB instance to connect to is running
......@@ -16,7 +17,8 @@ func main() {
var buckName = "test-bucket"
var rgName = "test-register"
var stName = "test-set-00"
var timestamp = time.Now().Unix()
var stName = fmt.Sprintf("bucket%d", timestamp)
// Write to a register (LWW)
AntidoteSetRegisterInBucket(buckName, rgName, "aaa")
......@@ -31,26 +33,47 @@ func main() {
fmt.Println(AntidoteReadRegisterInBucket(buckName, "test-register"))
// So far, so good. Now let's try sets.
fmt.Println("")
// Add items to a set
AntidoteAddItemToSetInBucket(buckName, stName, "test01")
var currString = "test01"
fmt.Println("Saving string", currString, "to a set.")
AntidoteAddItemToSetInBucket(buckName, stName, currString)
fmt.Println("Reading the set:")
fmt.Println(AntidoteReadItemsFromSetInBucket(buckName, stName))
fmt.Println("")
// Add a second item
AntidoteAddItemToSetInBucket(buckName, stName, "test02")
currString = "test02"
fmt.Println("Saving string", currString, "to the set.")
AntidoteAddItemToSetInBucket(buckName, stName, currString)
fmt.Println("Reading the set:")
fmt.Println(AntidoteReadItemsFromSetInBucket(buckName, stName))
fmt.Println("")
// Add a third item
AntidoteAddItemToSetInBucket(buckName, stName, "test03")
currString = "test03"
fmt.Println("Saving string", currString, "to the set.")
AntidoteAddItemToSetInBucket(buckName, stName, currString)
fmt.Println("Reading the set:")
fmt.Println(AntidoteReadItemsFromSetInBucket(buckName, stName))
fmt.Println("")
// Remove the second item
AntidoteRemoveItemFromSetInBucket(buckName, stName, "test02")
currString = "test02"
fmt.Println("Removing string", currString, "from the set.")
AntidoteRemoveItemFromSetInBucket(buckName, stName, currString)
fmt.Println("Reading the set:")
fmt.Println(AntidoteReadItemsFromSetInBucket(buckName, stName))
fmt.Println("")
// Add a fourth item
AntidoteAddItemToSetInBucket(buckName, stName, "test04")
currString = "test04"
fmt.Println("Saving string", currString, "to the set.")
AntidoteAddItemToSetInBucket(buckName, stName, currString)
fmt.Println("Reading the set:")
fmt.Println(AntidoteReadItemsFromSetInBucket(buckName, stName))
fmt.Println("")
}
// AntidoteAddItemToSetInBucket save an item to a set in a bucket
......@@ -208,6 +231,12 @@ func AntidoteRemoveItemFromSetInBucket(bucketName string, setName string, itemVa
err = bucket.Update(tx, antidoteclient.SetRemove(key, []byte(itemValue)))
errCheck(err, "")
err = tx.Commit()
errCheck(err, "")
tx, err = client.StartTransaction()
errCheck(err, "")
setVal, err := bucket.ReadSet(tx, key)
errCheck(err, "")
......@@ -216,11 +245,12 @@ func AntidoteRemoveItemFromSetInBucket(bucketName string, setName string, itemVa
for _, v := range setVal {
if string(v) == itemValue {
fmt.Println(false)
return false
}
}
return false
fmt.Println(true)
return true
}
// Panic on error
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment