Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017-2024 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.data.redis.connection.jedis;
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.connection.ClusterCommandExecutor.MultiNodeResult;
import org.springframework.data.redis.connection.ClusterCommandExecutor.NodeResult;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisClusterServerCommands;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.connection.jedis.JedisClusterConnection.JedisClusterCommandCallback;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* @author Mark Paluch
* @author Dennis Neufeld
* @since 2.0
*/
class JedisClusterServerCommands implements RedisClusterServerCommands {
private final JedisClusterConnection connection;
JedisClusterServerCommands(JedisClusterConnection connection) {
this.connection = connection;
}
@Override
public void bgReWriteAof(RedisClusterNode node) {
executeCommandOnSingleNode(Jedis::bgrewriteaof, node);
}
@Override
public void bgReWriteAof() {
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterCommandCallback) Jedis::bgrewriteaof);
}
@Override
public void bgSave() {
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterCommandCallback) Jedis::bgsave);
}
@Override
public void bgSave(RedisClusterNode node) {
executeCommandOnSingleNode(Jedis::bgsave, node);
}
@Override
public Long lastSave() {
List result = new ArrayList<>(executeCommandOnAllNodes(Jedis::lastsave).resultsAsList());
if (CollectionUtils.isEmpty(result)) {
return null;
}
Collections.sort(result, Collections.reverseOrder());
return result.get(0);
}
@Override
public Long lastSave(RedisClusterNode node) {
return executeCommandOnSingleNode(Jedis::lastsave, node).getValue();
}
@Override
public void save() {
executeCommandOnAllNodes(Jedis::save);
}
@Override
public void save(RedisClusterNode node) {
executeCommandOnSingleNode(Jedis::save, node);
}
@Override
public Long dbSize() {
Collection dbSizes = executeCommandOnAllNodes(Jedis::dbSize).resultsAsList();
if (CollectionUtils.isEmpty(dbSizes)) {
return 0L;
}
Long size = 0L;
for (Long value : dbSizes) {
size += value;
}
return size;
}
@Override
public Long dbSize(RedisClusterNode node) {
return executeCommandOnSingleNode(Jedis::dbSize, node).getValue();
}
@Override
public void flushDb() {
executeCommandOnAllNodes(Jedis::flushDB);
}
@Override
public void flushDb(FlushOption option) {
executeCommandOnAllNodes(it -> it.flushDB(JedisConverters.toFlushMode(option)));
}
@Override
public void flushDb(RedisClusterNode node) {
executeCommandOnSingleNode(Jedis::flushDB, node);
}
@Override
public void flushDb(RedisClusterNode node, FlushOption option) {
executeCommandOnSingleNode(it -> it.flushDB(JedisConverters.toFlushMode(option)), node);
}
@Override
public void flushAll() {
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterCommandCallback) Jedis::flushAll);
}
@Override
public void flushAll(FlushOption option) {
connection.getClusterCommandExecutor().executeCommandOnAllNodes(
(JedisClusterCommandCallback) it -> it.flushAll(JedisConverters.toFlushMode(option)));
}
@Override
public void flushAll(RedisClusterNode node) {
executeCommandOnSingleNode(Jedis::flushAll, node);
}
@Override
public void flushAll(RedisClusterNode node, FlushOption option) {
executeCommandOnSingleNode(it -> it.flushAll(JedisConverters.toFlushMode(option)), node);
}
@Override
public Properties info() {
Properties infos = new Properties();
List> nodeResults = connection.getClusterCommandExecutor()
.executeCommandOnAllNodes(
(JedisClusterCommandCallback) client -> JedisConverters.toProperties(client.info()))
.getResults();
for (NodeResult nodeProperties : nodeResults) {
for (Entry