
[Redis Architecture]
- Redis Architect : https://couplewith.tistory.com/819
- Redis Enterprise 기능 비교 : https://couplewith.tistory.com/817
- Redis 버전별 라이선스 와 기능 비교 : https://couplewith.tistory.com/815
- Redis 8 - 새로운 기능 과 성능 개선 : https://couplewith.tistory.com/818
- Redis Install : https://couplewith.tistory.com/822
- Redis with TLS : https://couplewith.tistory.com/824
- Redis 보안 접근제어 ACL 적용-클라이언트IP제어 : https://couplewith.tistory.com/816
- Redis install 유의 사항 : https://couplewith.tistory.com/825
- Redis Benchmark : https://couplewith.tistory.com/823
- Redis vs HazleCast : https://couplewith.tistory.com/821
- Redis vs HazleCast 개발 소스 비교 : https://couplewith.tistory.com/827
Redis vs HazleCast 개발 소스 비교
Redis와 Hazelcast 모두 Pub/Sub 및 캐시 기능을 지원하며, Java에서는 대표적으로 아래와 같이 구현할 수 있습니다. 여기서는 각 플랫폼별 기본 Java 샘플(Pub/Sub, Cache) 코드를 제공합니다.
1. Redis Java (Jedis 또는 Lettuce 클라이언트 예시)
▶️ Pub/Sub (Jedis 라이브러리)
// Pub/Sub Publisher
import redis.clients.jedis.Jedis;
public class RedisPublisher {
public static void main(String[] args) {
try (Jedis jedis = new Jedis("localhost", 6379)) {
jedis.publish("sample-channel", "Hello, Redis Pub/Sub!");
}
}
}
// Pub/Sub Subscriber
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;
public class RedisSubscriber {
public static void main(String[] args) {
Jedis jedis = new Jedis("localhost", 6379);
jedis.subscribe(new JedisPubSub() {
@Override
public void onMessage(String channel, String message) {
System.out.println("Received: " + message);
}
}, "sample-channel");
}
}
▶️ Cache (일반 Key/Value)
import redis.clients.jedis.Jedis;
public class RedisCacheExample {
public static void main(String[] args) {
try (Jedis jedis = new Jedis("localhost", 6379)) {
jedis.set("cache-key", "redis-cache-value");
String value = jedis.get("cache-key");
System.out.println("Cached value: " + value);
}
}
}
2. Hazelcast Java
Hazelcast는 분산 환경 지원이 강점입니다.
▶️ Pub/Sub (Topic)
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.topic.ITopic;
import com.hazelcast.topic.Message;
import com.hazelcast.topic.MessageListener;
// Publisher
public class HazelcastPublisher {
public static void main(String[] args) {
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
ITopic<String> topic = hz.getTopic("hz-topic");
topic.publish("Hello, Hazelcast Pub/Sub!");
hz.shutdown();
}
}
// Subscriber
public class HazelcastSubscriber {
public static void main(String[] args) {
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
ITopic<String> topic = hz.getTopic("hz-topic");
topic.addMessageListener(new MessageListener<String>() {
public void onMessage(Message<String> message) {
System.out.println("Received: " + message.getMessageObject());
}
});
}
}
▶️ Cache (IMap 사용)
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
public class HazelcastCacheExample {
public static void main(String[] args) {
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
IMap<String, String> cache = hz.getMap("my-cache");
cache.put("cache-key", "hazelcast-cache-value");
String value = cache.get("cache-key");
System.out.println("Cached value: " + value);
hz.shutdown();
}
}
Redis vs Hazelcast 특징 비교
| Pub/Sub 구현 | publish/subscribe 명령어, 매우 단순 | Topic API(분산 메시징), 엔터프라이즈급 Scale 가능 |
| Cache 구현 | Key/Value 중심, TTL 등 다양한 구조 지원 | IMap 등 복잡한 자료구조 지원, 분산 캐시와 지역 캐시 지원 |
| 확장성/분산 지원 | Cluster 이용(External), 기본 구조는 단일 노드 | 분산(내장), 여러 노드로 Scale-out 기본 |
- [Redis Pub/Sub은 간단하고 낮은 지연, Hazelcast의 Pub/Sub은 더 복잡한 분산 메시징 지원]1.
- [캐시는 Redis와 Hazelcast 모두 다양한 구조와 용도를 지원. Hazelcast는 분산 기본]47.
위 예제는 각각의 기본 기능을 빠르게 활용할 수 있는 가장 단순한 형태입니다.
실서비스 적용 시에는 네트워크, 보안, 예외처리, 클러스터링 등 추가 고려가 필요합니다.
- https://1gbits.com/blog/redis-vs-hazelcast/
- https://docs.dapr.io/getting-started/tutorials/configure-state-pubsub/
- https://docs.spring.io/spring-integration/reference/redis.html
- https://couplewith.tistory.com/821
- https://www.geeksforgeeks.org/computer-networks/difference-between-hazelcast-vs-redis/
- https://nebulaisme.tistory.com/149
- https://stackoverflow.com/questions/4109366/redis-vs-hazelcast
- https://cloudinfrastructureservices.co.uk/redis-vs-hazelcast-whats-the-difference/
'InfraPlatform' 카테고리의 다른 글
| 금융산업에서 ITIL과 ISMS 관련 전략과 관리 방안 (0) | 2025.08.11 |
|---|---|
| 통합 파일시스템 관리 ZFS LVM RAID (0) | 2025.08.06 |
| 웹서버 Apache 설치 보안 유의사항 - 시스템 서비스 계정 생성 관련 (0) | 2025.07.25 |
| APT(Advanced Persistent Threat) 공격 과 NTP 취약점 공격 (3) | 2025.07.02 |
| [리눅스] Local YUM Repository 구성 - RHEL, CentOS : cdrom 마운트 yum dnf 명령 사용 (2) | 2025.06.19 |
| RHEL과 SUSE Multi-Linux Support로 전환하여 비용절감 (10) | 2025.05.17 |
| SKT해킹 BPF도어 악성코드의 원리와 기능 특징 (7) | 2025.04.28 |