InfraPlatform

Redis vs HazleCast 개발 소스 비교

IT오이시이 2025. 7. 21. 13:21
728x90

 

[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 라이브러리)

 
java 
// 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)

 
java 
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)

 
java
 
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 사용)

 
java
 
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.

위 예제는 각각의 기본 기능을 빠르게 활용할 수 있는 가장 단순한 형태입니다.
실서비스 적용 시에는 네트워크, 보안, 예외처리, 클러스터링 등 추가 고려가 필요합니다.

  1. https://1gbits.com/blog/redis-vs-hazelcast/
  2. https://docs.dapr.io/getting-started/tutorials/configure-state-pubsub/
  3. https://docs.spring.io/spring-integration/reference/redis.html
  4. https://couplewith.tistory.com/821
  5. https://www.geeksforgeeks.org/computer-networks/difference-between-hazelcast-vs-redis/
  6. https://nebulaisme.tistory.com/149
  7. https://stackoverflow.com/questions/4109366/redis-vs-hazelcast
  8. https://cloudinfrastructureservices.co.uk/redis-vs-hazelcast-whats-the-difference/
728x90
반응형