Databases 20 min read

Comprehensive Redis Deployment, Jedis Integration, Performance Testing, Persistence, and Replication Guide

This article provides a detailed guide on installing Redis on Linux, configuring protected mode, using Java's Jedis client with Maven, performing message‑queue performance tests, comparing RDB and AOF persistence, and explaining master‑slave replication with configuration tips and code examples.

Architecture Digest
Architecture Digest
Architecture Digest
Comprehensive Redis Deployment, Jedis Integration, Performance Testing, Persistence, and Replication Guide

Redis is an open‑source, in‑memory data‑structure server that can serve as a database, cache, and message‑queue broker, supporting strings, hashes, lists, sets, sorted sets, bitmaps, hyperloglogs, replication, Lua scripting, LRU eviction, transactions, and various persistence levels.

Installation on Linux – download the latest stable tarball, extract it, run make, then start the server with ./redis-server (default config) or ./redis-server redis.conf. The compiled binaries redis-server and redis-cli appear in the source directory.

Protected mode – by default Redis only accepts local connections. To allow remote access, comment out the bind 127.0.0.1 line in redis.conf and optionally set a password with CONFIG SET requirepass your_password followed by AUTH your_password. The change takes effect immediately; CONFIG REWRITE persists it.

Client SDKs – Java uses Jedis , C uses hiredis , and PHP has Predis and the phpredis extension. More clients are listed at http://redis.io/clients.

Using Jedis – add the Maven dependency:

<dependency>
  <groupId>redis.clients</groupId>
  <artifactId>jedis</artifactId>
  <version>2.2.0</version>
</dependency>

Then create a JedisPool and use try‑with‑resources to obtain a Jedis instance, e.g.:

JedisPool pool = new JedisPool(new JedisPoolConfig(), "10.3.17.148", 6379, 2000, "ucsoftware");
try (Jedis jedis = pool.getResource()) {
    jedis.set("foo", "bar");
    String foobar = jedis.get("foo");
    System.out.println("get foo:" + foobar);
    jedis.zadd("sose", 0, "car");
    jedis.zadd("sose", 0, "bike");
    Set<String> sose = jedis.zrange("sose", 0, -1);
    System.out.println("zrange foo:" + Arrays.toString(sose.toArray()));
}
pool.destroy();

For publish/subscribe, two classes are provided – JedisSubscriberMain (starts a JedisPubSub listener) and JedisPublisherMain (publishes ten messages to the same channel). The subscriber must run before the publisher.

Message‑queue performance testing – the article measures send and receive latency under high load, showing that Redis pipelines achieve the highest throughput, while the native pub/sub mechanism has the lowest performance but offers flexible subscription patterns.

Persistence – Redis supports RDB snapshots and AOF append‑only logs. RDB creates point‑in‑time snapshots based on configurable save intervals; AOF records every write command and can be configured with appendfsync policies (always, everysec, no). The pros and cons of each method are discussed, including durability, file size, and recovery speed.

Master‑Slave Replication – after a slave connects, it issues SYNC, the master sends a snapshot (RDB) and then streams subsequent write commands. Configuration options such as slaveof, masterauth, slave-read-only, repl-ping-slave-period, and slave-priority are explained, along with advantages (read‑write separation, scalability) and potential issues (full snapshot transfer on reconnection, lack of incremental sync).

The guide concludes with references to further documentation and notes that the content originates from a CSDN blog post.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaJedisReplication
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.