Environment:APIJSON APIJSON Demo Redis
| Knowledge Sources | |
|---|---|
| Domains | Caching, Infrastructure, Performance |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Redis server with Jedis 5.1.2 client and Spring Data Redis 3.2.5, providing query result caching and multi-datasource coordination for the APIJSON Demo server.
Description
This environment provides a Redis cache layer for SQL query results and distributed state. The DemoSQLExecutor uses a static RedisTemplate configured with JedisConnectionFactory pointing to 127.0.0.1:6379. Keys are serialized with StringRedisSerializer and values with GenericToStringSerializer. Cache TTLs are differentiated: 60 seconds for normal tables, 10 minutes for User/Privacy and EXPLAIN/HEAD queries.
Usage
Use this environment for implementations that require SQL query result caching or Redis-based distributed state: DemoSQLExecutor and DynamicDataSource. Redis must be running and reachable at the configured host and port before the APIJSON server starts.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux / macOS / Windows | Any OS supporting Redis |
| Hardware | 512MB RAM minimum | Redis is in-memory; 1GB recommended for production cache |
| Disk | 100MB | For Redis persistence (if enabled) |
Dependencies
System Packages
- Redis Server 6.0+ (7.0+ recommended)
Java Packages
- `jedis` = 5.1.2
- `spring-data-redis` = 3.2.5
Credentials
No password configured by default (local development). For production:
- `REDIS_HOST` — Redis server hostname (hardcoded as `127.0.0.1` in `DemoSQLExecutor.java`)
- `REDIS_PORT` — Redis server port (hardcoded as `6379`)
Quick Install
# Install and start Redis (Ubuntu/Debian)
sudo apt install redis-server
sudo systemctl start redis-server
# Verify connection
redis-cli ping # Should return PONG
Code Evidence
RedisTemplate static initialization from `DemoSQLExecutor.java:63-76`:
public static final RedisTemplate<String, String> REDIS_TEMPLATE;
static {
REDIS_TEMPLATE = new RedisTemplate<>();
REDIS_TEMPLATE.setConnectionFactory(
new JedisConnectionFactory(new RedisStandaloneConfiguration("127.0.0.1", 6379))
);
REDIS_TEMPLATE.setKeySerializer(new StringRedisSerializer());
REDIS_TEMPLATE.setHashValueSerializer(new GenericToStringSerializer<>(Serializable.class));
REDIS_TEMPLATE.setValueSerializer(new GenericToStringSerializer<>(Serializable.class));
REDIS_TEMPLATE.afterPropertiesSet();
}
Redis dependency from `pom.xml:371-387`:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>5.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>3.2.5</version>
</dependency>
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `Connection refused: 127.0.0.1:6379` | Redis not running | Start Redis: `sudo systemctl start redis-server` |
| `Cannot get Jedis connection` | Redis down or network issue | Check Redis process and firewall rules |
| `ClassCastException on cache get` | Serializer mismatch | Ensure `StringRedisSerializer` for keys, `GenericToStringSerializer` for values |
Compatibility Notes
- Local-only by default: Redis connection is hardcoded to `127.0.0.1:6379`. For remote Redis, modify the static initializer in `DemoSQLExecutor.java`.
- No auth by default: The demo does not configure Redis password. Production deployments must add `RedisStandaloneConfiguration.setPassword()`.
- Jedis exclusion: `spring-data-redis` excludes its bundled Jedis to use the explicit 5.1.2 version.