Business Scenarios
These scenarios use annotation Mappers to execute Redis commands. Choose a data structure for the business need, then read a scalar, a JSON object or multiple result rows.
| Scenario | Redis structure | Java result |
|---|---|---|
| Product Cache | String / JSON | ProductCache |
| Login State | String / JSON | LoginState |
| Shopping Cart | Hash | List<CartItem> |
| View Counter | String / integer | Long |
| User Likes | Set | List<String> |
| Points Ranking | Sorted Set | List<RankEntry> |
Create a Session
Configure dataSource using JDBC Redis. Run each page's calling code inside a Session:
import java.util.List;
import java.util.UUID;
import net.hasor.dbvisitor.session.Configuration;
import net.hasor.dbvisitor.session.Session;
try (Session session = new Configuration().newSession(dataSource)) {
// Run the scenario's calling code here.
}
Place the example models and Mappers in the com.example.redis package. Examples use demo: keys and assume empty test keys. Repeating them may overwrite data or increase counts; do not use business keys.