Configs2026年7月13日·1 分钟阅读

Jedis — Battle-Tested Java Client for Redis

Jedis is a lightweight, synchronous Java client library for Redis, offering straightforward APIs for commands, pipelines, transactions, and Lua scripting.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 29/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Single
信任
信任等级:Established
入口
Jedis Overview
安全暂存命令
npx -y tokrepo@latest install f3c6ef0f-7eb8-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

Introduction

Jedis is a synchronous, blocking Java client for Redis maintained under the official redis organization on GitHub. It provides a direct mapping of Redis commands to Java methods, making it simple to adopt. Jedis is one of the two recommended Java clients alongside Lettuce.

What Jedis Does

  • Executes all Redis commands via a clean, method-per-command Java API
  • Supports connection pooling through JedisPool and the newer JedisPooled wrapper
  • Provides pipelining to batch multiple commands into a single network round trip
  • Handles Redis transactions (MULTI/EXEC) and Lua script evaluation (EVAL)
  • Connects to Redis Cluster and Redis Sentinel for high-availability setups

Architecture Overview

Jedis uses a simple blocking I/O model: each Jedis instance wraps a single TCP socket to a Redis server. For concurrent applications, JedisPool manages a pool of these instances backed by Apache Commons Pool 2. The newer JedisPooled class simplifies usage by auto-borrowing and returning connections per call. For Redis Cluster, JedisCluster discovers the slot-to-node mapping and routes commands accordingly.

Self-Hosting & Configuration

  • Add the Jedis Maven or Gradle dependency to your Java project
  • Create a JedisPooled instance pointing to your Redis host and port
  • Configure pool size via GenericObjectPoolConfig (maxTotal, maxIdle, minIdle)
  • For Redis Cluster, use JedisCluster with a set of seed HostAndPort entries
  • For Sentinel, use JedisSentinelPool with the master name and sentinel addresses

Key Features

  • Full coverage of Redis commands including Streams, JSON, and Search modules
  • Built-in connection pooling with configurable eviction and validation policies
  • Pipeline mode for batching commands and reducing network round trips
  • Support for Redis Cluster automatic slot discovery and failover
  • Lightweight dependency chain: only Apache Commons Pool 2 and SLF4J

Comparison with Similar Tools

  • Lettuce — async and reactive; Jedis is simpler but synchronous only
  • Redisson — higher-level distributed objects and locks; Jedis is lower-level
  • Spring Data Redis — abstracts over Jedis or Lettuce with Spring integration
  • ioredis (Node.js) — similar philosophy but for the JavaScript ecosystem
  • redis-py (Python) — the Python equivalent of Jedis

FAQ

Q: Jedis vs Lettuce — which should I pick? A: Use Jedis for simple, blocking workloads. Use Lettuce if you need non-blocking I/O, reactive streams, or shared connections across threads.

Q: Is Jedis thread-safe? A: A single Jedis instance is not thread-safe. Use JedisPool or JedisPooled for concurrent access.

Q: Does Jedis support Redis modules like RedisJSON? A: Yes. Jedis 4.x+ includes APIs for RedisJSON, RediSearch, RedisBloom, and RedisTimeSeries.

Q: Can I use Jedis with Spring Boot? A: Yes. Spring Data Redis supports Jedis as an alternative to its default Lettuce driver.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产