Introduction
ACOR v1.3.0 introduces two significant Redis-related improvements. First, it now supports various Redis topologies (Sentinel, Cluster, Ring). Second, the API has been improved to explicitly handle errors during Redis communication.
Redis Topology Support
The Problem
Prior to v1.3.0, ACOR only supported a single Redis instance (Addr). In production environments, Redis Sentinel is often used for high availability, or Redis Cluster for handling large-scale data. Using ACOR in these environments required additional work.
The Solution
v1.3.0 adds topology-specific fields to the AhoCorasickArgs struct to support various Redis deployment modes:
| |
Usage Examples
Standalone (existing approach)
| |
Redis Sentinel
| |
Redis Cluster
| |
Redis Ring
| |
Cluster-Safe Key Design
Redis Cluster distributes keys across multiple shards. ACOR uses hash tags to ensure all keys belonging to a single collection are stored on the same shard:
This guarantees that all data for a single Aho-Corasick automaton is stored on the same shard, ensuring transaction support and read consistency.
Redis Error Handling
The Problem
Before v1.3.0, errors during Redis communication were silently ignored. For example, if the network disconnected, Find would return an empty result, making it impossible to distinguish between “no keywords matched” and “Redis connection failed.”
The Solution
In v1.3.0, all Redis-related APIs now explicitly return errors:
| |
Partial Write Rollback
The Add method stores keywords as a trie structure in Redis, requiring multiple Redis commands. If it fails midway, partially stored data would remain. v1.3.0 performs rollback on failure to ensure data consistency:
| |
Usage Example
| |
Conclusion
With v1.3.0’s Redis improvements, ACOR can now be used more safely in production environments. Redis Sentinel/Cluster/Ring support provides high availability and scalability, while explicit error handling enables appropriate responses to failure scenarios.
For more details, visit the ACOR GitHub repository and official documentation.