![Screenshot 2023-06-03 at 1 55 31 PM](https://private-user-images.githubusercontent.com/75189508/243120101-f884f643-00af-405d-900d-a636d119cf74.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyNDgwNzUsIm5iZiI6MTcyNDI0Nzc3NSwicGF0aCI6Ii83NTE4OTUwOC8yNDMxMjAxMDEtZjg4NGY2NDMtMDBhZi00MDVkLTkwMGQtYTYzNmQxMTljZjc0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIxVDEzNDI1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJhMjY1MWEwNmU3YTRkMjUwY2YwMmZkYTNmN2ViNGFlZDIwMDBjODY3YmMxZDY4NzlmNDkzNzY2MjAyODI0NTYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.jggA2QPJ1Xpf6ToM5cfptteEr9jYDdWuiKDgmPk1MEc)
Hermes is still in a developmental phase. Helping with test cases, benchmarks, speed, and memory usage are a great way to contribute to the project.
Direct access to the hermes cache/nocache functions.
go get github.com/realTristan/hermes
Access the hermes cache functions via websocket.
pip install hermescloud
Hermes is an extremely fast full-text search and caching framework written in Go. Hermes has a cache algorithm where you can set, get, store, etc. keys and values into the cache, and a no-cache algorithm that reads data from an array or json file and uses an array to store data. Both of these algorithms provide full-text search query speeds from 10µs to 300µs.
If you want to use only the full-text-search features, then import hermes/nocache. Load the data using a .json file or array of maps. No Cache is much faster than the With-Cache algorithm, but you can't update the data.
package main
import (
"fmt"
"time"
hermes "github.com/realTristan/hermes/nocache"
)
func main() {
// Initialize the full-text cache
var ft, _ = hermes.InitWithJson("data.json")
// Search for a word in the cache
var res, _ = ft.Search(hermes.SearchParams{
Query: "tristan",
Limit: 100,
Strict: false,
})
fmt.Println(res)
}
Dataset Map Entries: 4,115
Dataset Total Words: 208,092
Dataset Map Size: ≈ 2.3MB
Query: Computer, Limit: 100, Strict: False => 36.5µs
Query: Computer, Limit: 100, Strict: True => 12.102µs
Used with hermes.InitWithJson()
[
{
"id": 1,
"name": {
"$hermes.full_text": true,
"$hermes.value": "Tristan Simpson"
},
},
]
The with-cache algorithm is notably slower than the no-cache algorithm. Why? Because the with-cache algorithm uses maps to store data and not an array. Import hermes directly to use the with-cache features.
package main
import (
"fmt"
"time"
hermes "github.com/realTristan/hermes"
)
func main() {
// Initialize the cache
cache := hermes.InitCache()
// MaxSize: 10, MaxBytes: -1 (no limit), MinWordLength: 3
cache.FTInit(10, -1, 3)
// Set the value in the cache
cache.Set("user_id", map[string]any{
"name": cache.WithFT("tristan"),
"age": 17,
})
// Search for a word in the cache and print the result
result, err := cache.Search(hermes.SearchParams{
Query: "tristan",
Limit: 100,
Strict: false,
})
fmt.Println(result)
}
Dataset Map Entries: 4,115
Dataset Total Words: 208,092
Dataset Map Size: ≈ 2.3MB
Query: Computer, Limit: 100, Strict: False => 263.7µs
Query: Computer, Limit: 100, Strict: True => 40.84µs
Used with cache.FTInitWithJson()
{
"user_id": {
"age": 17,
"name": {
"$hermes.full_text": true,
"$hermes.value": "Tristan Simpson"
},
},
}
Coming Soon
import (
"github.com/gofiber/fiber/v2"
hermes "github.com/realTristan/hermes"
socket "github.com/realTristan/hermes/cloud/socket"
)
func main() {
// Cache and fiber app
cache := hermes.InitCache()
app := fiber.New()
// Set the router
socket.SetRouter(app, cache)
// Listen on port 3000
app.Listen(":3000")
}
Set a value in the cache with the corresponding key.
{
"function": "cache.set",
"key": "user_id",
"value": base64{
"name": "tristan"
}
}
{
"success": true/false,
"data": nil
}
Delete the provided key, and the data correlated to it from the cache.
{
"function": "cache.delete",
"key": "user_id"
}
{
"success": true/false,
"data": nil
}
Get data from the cache using a key.
{
"function": "cache.get",
"key": "user_id"
}
{
"success": true/false,
"data": map[string]any
}
Get all of the keys in the cache.
{
"function": "cache.keys"
}
{
"success": true/false,
"data": []string
}
Get all of the values in the cache.
{
"function": "cache.values"
}
{
"success": true/false,
"data": []map[string]any
}
Get the amount of keys stored in the cache.
{
"function": "cache.length"
}
{
"success": true/false,
"data": int
}
Clean all the data in the cache, and full-text storage.
{
"function": "cache.clean"
}
{
"success": true/false,
"data": nil
}
Get the cache and full-text storage statistics.
{
"function": "cache.info"
}
{
"success": true/false,
"data": string
}
Get whether a key exists in the cache.
{
"function": "cache.exists",
"key": "user_id"
}
{
"success": true/false,
"data": bool
}
Intialize the full text cache.
{
"function": "ft.init",
"maxbytes": -1,
"maxsize": -1,
"minwordlength": 3
}
{
"success": true/false,
"data": nil
}
Clean all of the data in the full-text storage.
{
"function": "ft.clean"
}
{
"success": true/false,
"data": nil
}
Search for a query in the full-text storage.
{
"function": "ft.search",
"query": "tristan",
"strict": false,
"limit": 10
}
{
"success": true/false,
"data": []map[string]any
}
Search for a single word in the full-text storage.
{
"function": "ft.search.oneword",
"query": "tristan",
"strict": false,
"limit": 10
}
{
"success": true/false,
"data": []map[string]any
}
Search in the cache data values. (Slower)
{
"function": "ft.search.values",
"query": "tristan",
"limit": 10,
"schema": {
"key": true
}
}
{
"success": true/false,
"data": []map[string]any
}
Search in the cache data values for a specific key.
{
"function": "ft.search.withkey",
"query": "tristan",
"key": "user_id",
"limit": 10
}
{
"success": true/false,
"data": []map[string]any
}
Set the maximum full-text storage size in bytes.
{
"function": "ft.maxbytes.set",
"maxbytes": -1
}
{
"success": true/false,
"data": nil
}
Set the maximum full-text storage words allowed to be stored.
{
"function": "ft.maxsize.set",
"maxsize": -1
}
{
"success": true/false,
"data": nil
}
Get the current full-text storage.
{
"function": "ft.storage"
}
{
"success": true/false,
"data": map[string][]int
}
Get the current full-text storage size in bytes.
{
"function": "ft.storage.size"
}
{
"success": true/false,
"data": int
}
Get the current full-text storage length.
{
"function": "ft.storage.length"
}
{
"success": true/false,
"data": int
}
Get whether the full-text storage has been initialized.
{
"function": "ft.isinitialized"
}
{
"success": true/false,
"data": bool
}
Sequence the full-text storage indices.
{
"function": "ft.indices.sequence"
}
{
"success": true/false,
"data": nil
}
- Testing Files
- More Documentation
- More Examples
- Wrappers for other languages
MIT License
Copyright (c) 2023 Tristan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.