-
Notifications
You must be signed in to change notification settings - Fork 999
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] support redis cluster and sentinel mode in real time data (#…
…2324) Co-authored-by: tomsun28 <tomsun28@outlook.com>
- Loading branch information
Showing
12 changed files
with
450 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,6 @@ public interface SignConstants { | |
String CARRIAGE_RETURN = "\r"; | ||
|
||
String RIGHT_DASH = "/"; | ||
|
||
String COMMA = ","; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...java/org/apache/hertzbeat/warehouse/store/realtime/redis/client/RedisClientOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hertzbeat.warehouse.store.realtime.redis.client; | ||
|
||
import io.lettuce.core.RedisFuture; | ||
import io.lettuce.core.codec.RedisCodec; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import org.apache.hertzbeat.warehouse.store.realtime.redis.RedisProperties; | ||
|
||
/** | ||
* Redis Client Operation | ||
*/ | ||
public interface RedisClientOperation<K, V> extends AutoCloseable { | ||
RedisClientOperation<K, V> connect(RedisProperties redisProperties, RedisCodec<K, V> redisCodec); | ||
|
||
V hget(K key, K field); | ||
|
||
Map<K, V> hgetAll(K key); | ||
|
||
void hset(K key, K field, V value, Consumer<RedisFuture<Boolean>> redisFutureConsumer); | ||
} |
75 changes: 75 additions & 0 deletions
75
...java/org/apache/hertzbeat/warehouse/store/realtime/redis/client/RedisCommandDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hertzbeat.warehouse.store.realtime.redis.client; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.hertzbeat.common.entity.message.CollectRep; | ||
import org.apache.hertzbeat.warehouse.store.realtime.redis.MetricsDataRedisCodec; | ||
import org.apache.hertzbeat.warehouse.store.realtime.redis.RedisProperties; | ||
import org.apache.hertzbeat.warehouse.store.realtime.redis.client.impl.RedisClusterClientImpl; | ||
import org.apache.hertzbeat.warehouse.store.realtime.redis.client.impl.RedisSentinelClientImpl; | ||
import org.apache.hertzbeat.warehouse.store.realtime.redis.client.impl.RedisSimpleClientImpl; | ||
|
||
/** | ||
* Redis command delegate | ||
*/ | ||
@Slf4j | ||
public class RedisCommandDelegate { | ||
private static final String SINGLE_MODE = "single"; | ||
private static final String SENTINEL_MODE = "sentinel"; | ||
private static final String CLUSTER_MODE = "cluster"; | ||
private static final RedisCommandDelegate INSTANCE = new RedisCommandDelegate(); | ||
private RedisClientOperation<String, CollectRep.MetricsData> operation; | ||
|
||
public static RedisCommandDelegate getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
public RedisClientOperation<String, CollectRep.MetricsData> operate() { | ||
return operation; | ||
} | ||
|
||
public void destroy() throws Exception { | ||
operation.close(); | ||
} | ||
|
||
public boolean initRedisClient(RedisProperties redisProperties) { | ||
if (redisProperties == null) { | ||
log.error("init error, please config Warehouse redis props in application.yml"); | ||
return false; | ||
} | ||
|
||
try { | ||
operation = switch (redisProperties.mode()) { | ||
case SINGLE_MODE -> new RedisSimpleClientImpl().connect(redisProperties, new MetricsDataRedisCodec()); | ||
case SENTINEL_MODE -> new RedisSentinelClientImpl().connect(redisProperties, new MetricsDataRedisCodec()); | ||
case CLUSTER_MODE -> new RedisClusterClientImpl().connect(redisProperties, new MetricsDataRedisCodec()); | ||
default -> throw new UnsupportedOperationException("Incorrect redis mode: " + redisProperties.mode()); | ||
}; | ||
|
||
return true; | ||
} catch (Exception e) { | ||
log.error("init redis error {}", e.getMessage(), e); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private RedisCommandDelegate() { | ||
} | ||
} |
Oops, something went wrong.