Skip to main content

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.

ScenarioRedis structureJava result
Product CacheString / JSONProductCache
Login StateString / JSONLoginState
Shopping CartHashList<CartItem>
View CounterString / integerLong
User LikesSetList<String>
Points RankingSorted SetList<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.