Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:APIJSON APIJSON Demo RedisDataSource

From Leeroopedia
Knowledge Sources
Domains Database, Redis, Connection_Pooling
Last Updated 2026-10-14 00:00 GMT

Overview

Concrete tool for managing Jedis connection pools (single, sentinel, cluster) for Redis data source access in the APIJSON Redis demo.

Description

The RedisDataSource class manages three Jedis connection pool types: JedisPool (single node), JedisSentinelPool (sentinel mode), and JedisCluster (cluster mode). It configures pool parameters (maxTotal, maxIdle, maxWaitMillis, testOnBorrow, etc.) and provides factory methods (createSingle, createSentinel, createCluster) to initialize each pool type. It uses Lombok @Data for getters/setters.

Usage

Use this class when you need to initialize and manage Redis connections (single, sentinel, or cluster) in the APIJSON Redis multi-datasource demo.

Code Reference

Source Location

Signature

@Data
@Slf4j
public class RedisDataSource {
    private JedisCluster jedisCluster;
    private JedisPool jedisPool;
    private JedisSentinelPool sentinelPool;

    public void createSingle();      // single node pool
    public void createSentinel();    // sentinel pool
    public void createCluster();     // cluster pool
}

Import

import apijson.demo.redis.RedisDataSource;

I/O Contract

Inputs

Name Type Required Description
MAX_TOTAL Integer No Max connections (default 1024)
MAX_IDLE Integer No Max idle connections (default 200)
TIMEOUT Integer No Connection timeout ms (default 10000)

Outputs

Name Type Description
jedisPool JedisPool Single-node connection pool
sentinelPool JedisSentinelPool Sentinel-mode pool
jedisCluster JedisCluster Cluster-mode pool

Usage Examples

Create Single Node Pool

import apijson.demo.redis.RedisDataSource;

RedisDataSource ds = new RedisDataSource();
ds.createSingle();  // initializes jedisPool on localhost:6379

// Use pool
try (var jedis = ds.getJedisPool().getResource()) {
    jedis.set("key", "value");
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment