Why Redis List Works Well for Search History in SmartNote
Practical reasons for using Redis List for recent search history, with key design and operation strategy.
In SmartNote, search history is a high-frequency, short-lifecycle data pattern.
Characteristics of search history#
It usually has these properties:
- frequent writes
- fast read expectations
- no complex relational query requirement
- mostly recent N entries only
MySQL can store this, but it is often unnecessary overhead for this pattern.
Why Redis List is a good fit#
List naturally models ordered recent history.
Typical key design:
search:history:user:{userId}
Common operations:
LPUSHto insert newest queryLTRIMto keep recent N entries- optional dedup logic before insert
This keeps retrieval simple and fast.
Handling duplicates#
A practical approach:
- remove existing same query
- push new query to the head
- trim to fixed size
This preserves recency while avoiding noisy repeats.
Expiration strategy#
Depending on product need, set TTL for automatic cleanup if long-term history is not required.
Closing#
Redis List is not universal, but for recent search history it is usually a clean and cost-effective choice: simple data model, fast operations, and predictable maintenance.
Related posts
View all