Aho-Corasick automaton working On Redis — distributed multi-pattern matching for Go.
ACOR keeps one Aho-Corasick dictionary in Redis and reaches it from a Go library, a CLI, and an experimental server module. Every application instance shares that dictionary, updates it at runtime, and matches against a local copy with no Redis I/O on the hot path.
Typical uses: content filtering, keyword extraction, intrusion detection, search highlighting, real-time text classification.
- Shared state — every instance reads the same Redis-backed dictionary
- < 8000 strong>Runtime updates — Pub/Sub invalidation, with optional polling for missed messages
- Fast reads — preset engines match locally, 0 round trips
- Topologies — standalone Redis, Sentinel, Cluster, Ring, and Valkey
- Full matching API — occurrences, positions, sets, streams, batches, parallel scans
Requires Go 1.25+ and Redis 3.0+ or Valkey 7.2+.
go get github.com/skyoo2003/acor/pkg/acor@latestStart Redis locally, then:
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/skyoo2003/acor/pkg/acor"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
ac, err := acor.CreateContext(ctx, &acor.AhoCorasickArgs{
Addr: "localhost:6379",
Name: "sample",
Preset: acor.PresetBalanced,
})
if err != nil {
return fmt.Errorf("create collection: %w", err)
}
defer func() { _ = ac.Close() }()
if _, err := ac.AddManyContext(ctx, []string{"he", "her", "him"}, nil); err != nil {
return fmt.Errorf("add keywords: %w", err)
}
matches, err := ac.FindMatchesContext(ctx, "he is him", nil)
if err != nil {
return fmt.Errorf("find matches: %w", err)
}
fmt.Println(matches)
return nil
}New collections use the optimized V2 Redis schema.
| Goal | Preset |
|---|---|
| General-purpose speed and memory | PresetBalanced |
| Highest matching throughput | PresetSpeed |
| Lowest memory usage | PresetMemoryEfficient |
Redis stays the source of truth for every preset. Trade-offs are in the preset guide; multi-instance invalidation is in the Redis-backed engine guide.
OpenVersioned opens a separate V3 collection with leased snapshots, expected-version
writes, and background engine replacement. V1/V2 APIs are unaffected. See the
V3 guide, its
performance report, and
bounded text processing for Scan,
MaskText, and ReplaceText.
For a new V3 dictionary, VersionedOptions.ShardCount selects a fixed storage and
engine shard count (powers of two, up to 256); zero or one preserves legacy V3.
Existing dictionaries keep their stored layout until an explicit Reshard commit.
Sharded storage uses separate Redis hash tags, while each serving replica still holds
the complete searchable dictionary in RAM. Searches make no Redis calls. Plan for
the previous engine and replacement shards to coexist during refresh; shard count
alone does not establish a memory or latency improvement. The sharded release still
requires controlled scale and live multi-node Cluster qualification.
The documentation site covers Redis topologies, the
matching and streaming API, batch and parallel guides, the V2 schema and benchmarks,
deployment and troubleshooting, the acor CLI, the experimental server module, and what
the v1 line promises. Package signatures are on
pkg.go.dev.
Contributing · Support · Security · Code of Conduct · Governance · Changelog
Apache License 2.0 — Copyright 2016-2026 Sungkyu Yoo