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 ...@@ -2,8 +2,9 @@ package main
import ( import (
"fmt" "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 // DatabaseHost defines the host of the AntidoteDB instance to connect to is running
...@@ -16,7 +17,8 @@ func main() { ...@@ -16,7 +17,8 @@ func main() {
var buckName = "test-bucket" var buckName = "test-bucket"
var rgName = "test-register" 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) // Write to a register (LWW)
AntidoteSetRegisterInBucket(buckName, rgName, "aaa") AntidoteSetRegisterInBucket(buckName, rgName, "aaa")
...@@ -31,26 +33,47 @@ func main() { ...@@ -31,26 +33,47 @@ func main() {
fmt.Println(AntidoteReadRegisterInBucket(buckName, "test-register")) fmt.Println(AntidoteReadRegisterInBucket(buckName, "test-register"))
// So far, so good. Now let's try sets. // So far, so good. Now let's try sets.
fmt.Println("")
// Add items to a set // 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(AntidoteReadItemsFromSetInBucket(buckName, stName))
fmt.Println("")
// Add a second item // 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(AntidoteReadItemsFromSetInBucket(buckName, stName))
fmt.Println("")
// Add a third item // 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(AntidoteReadItemsFromSetInBucket(buckName, stName))
fmt.Println("")
// Remove the second item // 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(AntidoteReadItemsFromSetInBucket(buckName, stName))
fmt.Println("")
// Add a fourth item // 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(AntidoteReadItemsFromSetInBucket(buckName, stName))
fmt.Println("")
} }
// AntidoteAddItemToSetInBucket save an item to a set in a bucket // AntidoteAddItemToSetInBucket save an item to a set in a bucket
...@@ -208,6 +231,12 @@ func AntidoteRemoveItemFromSetInBucket(bucketName string, setName string, itemVa ...@@ -208,6 +231,12 @@ func AntidoteRemoveItemFromSetInBucket(bucketName string, setName string, itemVa
err = bucket.Update(tx, antidoteclient.SetRemove(key, []byte(itemValue))) err = bucket.Update(tx, antidoteclient.SetRemove(key, []byte(itemValue)))
errCheck(err, "") errCheck(err, "")
err = tx.Commit()
errCheck(err, "")
tx, err = client.StartTransaction()
errCheck(err, "")
setVal, err := bucket.ReadSet(tx, key) setVal, err := bucket.ReadSet(tx, key)
errCheck(err, "") errCheck(err, "")
...@@ -216,11 +245,12 @@ func AntidoteRemoveItemFromSetInBucket(bucketName string, setName string, itemVa ...@@ -216,11 +245,12 @@ func AntidoteRemoveItemFromSetInBucket(bucketName string, setName string, itemVa
for _, v := range setVal { for _, v := range setVal {
if string(v) == itemValue { if string(v) == itemValue {
fmt.Println(false)
return false return false
} }
} }
fmt.Println(true)
return false return true
} }
// Panic on error // 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