Getting Started
ACOR requires Go 1.23 or newer and Redis 3.0 or newer.
go get -u github.com/skyoo2003/acor
package main
import (
"fmt"
"github.com/skyoo2003/acor/pkg/acor"
)
func main() {
ac, err := acor.Create(&acor.AhoCorasickArgs{
Addr: "localhost:6379",
Name: "sample",
})
if err != nil {
panic(err)
}
defer ac.Close()
_, _ = ac.Add("he")
_, _ = ac.Add("her")
matched, _ := ac.Find("he is her")
fmt.Println(matched)
}
Redis Topologies
- Standalone: use
Addrfor a single Redis server. - Sentinel: use
AddrswithMasterNamefor failover-aware access. - Cluster: use
AddrswithDBleft at0. - Ring: use
RingAddrswith shard-to-address mappings.
sentinelArgs := &acor.AhoCorasickArgs{
Addrs: []string{"localhost:26379", "localhost:26380"},
MasterName: "mymaster",
Name: "sample",
}
clusterArgs := &acor.AhoCorasickArgs{
Addrs: []string{"localhost:7000", "localhost:7001", "localhost:7002"},
Name: "sample",
}
ringArgs := &acor.AhoCorasickArgs{
RingAddrs: map[string]string{
"shard-1": "localhost:7000",
"shard-2": "localhost:7001",
},
Name: "sample",
}
CLI Commands
add <keyword>inserts a keyword into the collection.remove <keyword>removes a keyword and prunes related trie state.find <input>andfind-index <input>return matches or match offsets.suggest <input>andsuggest-index <input>return prefix suggestions and their offsets.inforeturns keyword and node counts.flushclears stored trie state.
| Flag | Purpose |
|---|---|
-addr | Standalone Redis server address |
-addrs | Sentinel or Cluster seed addresses |
-master-name | Redis Sentinel master name |
-ring-addrs | Comma-separated shard=addr pairs |
-password | Redis password |
-db | Redis DB number |
-name | Pattern collection name, default default |
-debug | Enable debug logging |
HTTP and gRPC Adapters
The HTTP handler exposes JSON endpoints on /v1/* plus /healthz.
POST /v1/addPOST /v1/removePOST /v1/findPOST /v1/find-indexPOST /v1/suggestPOST /v1/suggest-indexGET /v1/infoPOST /v1/flush
The gRPC service name is acor.server.v1.Acor and mirrors the same operations.
Development Workflow
Run local checks with:
make test
make build
CI runs on pushes and pull requests against master. Releases are tag-based, and the GitHub Pages site is built from the Hugo source in docs/.
Source code is MIT licensed. Contributions should include tests when behavior changes.