You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The hash maps behaves like hash maps, but are not backed by actual hashmaps, unlike with simpleredis. This is for keeping compatibility with simpleredis. If performance when scaling up is a concern, simpleredis combined with redis or Valkey might be a better choice.
MariaDB/MySQL normally has issues with variable size UTF-8 strings, even for for some combinations of characters. This package avoids these problems by compressing and hex encoding the data before storing in the database. This may slow down or speed up the time it takes to access the data, depending on your setup, but it's a safe way to encode any string. This behavior is optional and can be disabled with host.SetRawUTF8(true), (to just use utf8mb4).
Sample usage
package main
import (
"log""github.com/xyproto/simplemaria"
)
funcmain() {
// Check if the simplemaria service is upiferr:=db.TestConnection(); err!=nil {
log.Fatalln("Could not connect to local database. Is the service up and running?")
}
// Create a Host, connect to the local db serverhost:=db.New()
// Connecting to a different host/port//host := db.NewHost("server:3306/db")// Connect to a different db host/port, with a username and password// host := db.NewHost("username:password@server:port/db")// Close the connection when the function returnsdeferhost.Close()
// Create a list named "greetings"list, err:=db.NewList(host, "greetings")
iferr!=nil {
log.Fatalln("Could not create list!")
}
// Add "hello" to the list, check if there are errorsiflist.Add("hello") !=nil {
log.Fatalln("Could not add an item to list!")
}
// Get the last item of the listifitem, err:=list.GetLast(); err!=nil {
log.Fatalln("Could not fetch the last item from the list!")
} else {
log.Println("The value of the stored item is:", item)
}
// Remove the listiflist.Remove() !=nil {
log.Fatalln("Could not remove the list!")
}
}
Testing
A MariaDB/MySQL Database must be up and running locally for go test to work.