Skip to content

DATAREDIS-661 - Refactor RedisServerCommands.getConfig(…) output to Properties. #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAREDIS-661-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2011-2016 the original author or authors.
*
* Copyright 2011-2017 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
*
*
* 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.
Expand All @@ -15,17 +15,8 @@
*/
package org.springframework.data.redis.connection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.apache.commons.logging.Log;
Expand All @@ -52,7 +43,7 @@

/**
* Default implementation of {@link StringRedisConnection}.
*
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Christoph Strobl
Expand Down Expand Up @@ -122,7 +113,7 @@ public List<Object> convert(List<Object> execResults) {
/**
* Constructs a new <code>DefaultStringRedisConnection</code> instance. Uses {@link StringRedisSerializer} as
* underlying serializer.
*
*
* @param connection Redis connection
*/
public DefaultStringRedisConnection(RedisConnection connection) {
Expand All @@ -131,7 +122,7 @@ public DefaultStringRedisConnection(RedisConnection connection) {

/**
* Constructs a new <code>DefaultStringRedisConnection</code> instance.
*
*
* @param connection Redis connection
* @param serializer String serializer
*/
Expand Down Expand Up @@ -308,8 +299,8 @@ public Boolean getBit(byte[] key, long offset) {
return result;
}

public List<String> getConfig(String pattern) {
List<String> results = delegate.getConfig(pattern);
public Properties getConfig(String pattern) {
Properties results = delegate.getConfig(pattern);
if (isFutureConversion()) {
addResultConverter(identityConverter);
}
Expand Down Expand Up @@ -939,7 +930,7 @@ public Long sUnionStore(byte[] destKey, byte[]... keys) {
return result;
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#ttl(byte[])
*/
Expand All @@ -953,7 +944,7 @@ public Long ttl(byte[] key) {
return result;
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#ttl(byte[], java.util.concurrent.TimeUnit)
*/
Expand Down Expand Up @@ -1351,7 +1342,7 @@ public Boolean pExpireAt(byte[] key, long unixTimeInMillis) {
return result;
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#pTtl(byte[])
*/
Expand All @@ -1366,7 +1357,7 @@ public Long pTtl(byte[] key) {
return result;
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisKeyCommands#pTtl(byte[], java.util.concurrent.TimeUnit)
*/
Expand Down Expand Up @@ -2103,7 +2094,7 @@ public Long sUnionStore(String destKey, String... keys) {
return result;
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#ttl(java.lang.String)
*/
Expand All @@ -2112,7 +2103,7 @@ public Long ttl(String key) {
return ttl(serialize(key));
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#ttl(java.lang.String, java.util.concurrent.TimeUnit)
*/
Expand Down Expand Up @@ -2743,7 +2734,7 @@ public Boolean pExpireAt(String key, long unixTimeInMillis) {
return pExpireAt(serialize(key), unixTimeInMillis);
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#pTtl(java.lang.String)
*/
Expand All @@ -2752,7 +2743,7 @@ public Long pTtl(String key) {
return pTtl(serialize(key));
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#pTtl(java.lang.String, java.util.concurrent.TimeUnit)
*/
Expand Down Expand Up @@ -2835,7 +2826,7 @@ public Cursor<byte[]> scan(ScanOptions options) {
}

/*
*
*
*/
@Override
public Cursor<Tuple> zScan(byte[] key, ScanOptions options) {
Expand Down Expand Up @@ -2863,7 +2854,7 @@ public Cursor<Entry<byte[], byte[]>> hScan(byte[] key, ScanOptions options) {
/**
* Specifies if pipelined and tx results should be deserialized to Strings. If false, results of
* {@link #closePipeline()} and {@link #exec()} will be of the type returned by the underlying connection
*
*
* @param deserializePipelineAndTxResults Whether or not to deserialize pipeline and tx results
*/
public void setDeserializePipelineAndTxResults(boolean deserializePipelineAndTxResults) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ default void shutdown(RedisClusterNode node) {
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
@Override
@Deprecated
default List<String> getConfig(RedisClusterNode node, String pattern) {
default Properties getConfig(RedisClusterNode node, String pattern) {
return serverCommands().getConfig(node, pattern);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ default void shutdown(ShutdownOption option) {
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
@Override
@Deprecated
default List<String> getConfig(String pattern) {
default Properties getConfig(String pattern) {
return serverCommands().getConfig(pattern);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public interface RedisClusterServerCommands extends RedisServerCommands {
* @return
* @see RedisServerCommands#getConfig(String)
*/
List<String> getConfig(RedisClusterNode node, String pattern);
Properties getConfig(RedisClusterNode node, String pattern);

/**
* @param node must not be {@literal null}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ default void bgWriteAof() {
* @return
* @see <a href="http://redis.io/commands/config-get">Redis Documentation: CONFIG GET</a>
*/
List<String> getConfig(String pattern);
Properties getConfig(String pattern);

/**
* Set server configuration for {@code param} to {@code value}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2017 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.
Expand All @@ -15,16 +15,9 @@
*/
package org.springframework.data.redis.connection.convert;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import lombok.RequiredArgsConstructor;

import java.util.*;
import java.util.concurrent.TimeUnit;

import org.springframework.core.convert.converter.Converter;
Expand All @@ -50,8 +43,6 @@
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import lombok.RequiredArgsConstructor;

/**
* Common type converters
*
Expand All @@ -70,6 +61,7 @@ abstract public class Converters {
private static final Converter<String, DataType> STRING_TO_DATA_TYPE = new StringToDataTypeConverter();
private static final Converter<Map<?, ?>, Properties> MAP_TO_PROPERTIES = MapToPropertiesConverter.INSTANCE;
private static final Converter<String, RedisClusterNode> STRING_TO_CLUSTER_NODE_CONVERTER;
private static final Converter<List<String>, Properties> STRING_LIST_TO_PROPERTIES_CONVERTER;
private static final Map<String, Flag> flagLookupMap;

static {
Expand Down Expand Up @@ -172,6 +164,21 @@ private SlotRange parseSlotRange(String[] args) {
}

};

STRING_LIST_TO_PROPERTIES_CONVERTER = input -> {

Assert.notNull(input, "Input list must not be null!");
Assert.isTrue(input.size() % 2 == 0, "Input list must contain an even number of entries!");

Properties properties = new Properties();

for (int i = 0; i < input.size(); i += 2) {

properties.setProperty(input.get(i), input.get(i + 1));
}

return properties;
};
}

public static Boolean stringToBoolean(String s) {
Expand Down Expand Up @@ -224,7 +231,7 @@ protected static RedisClusterNode toClusterNode(String clusterNodesLine) {
/**
* Converts lines from the result of {@code CLUSTER NODES} into {@link RedisClusterNode}s.
*
* @param clusterNodes
* @param lines
* @return
* @since 1.7
*/
Expand Down Expand Up @@ -302,7 +309,7 @@ public static long secondsToTimeUnit(long seconds, TimeUnit targetUnit) {

/**
* Creates a new {@link Converter} to convert from seconds to the given {@link TimeUnit}.
*
*
* @param timeUnit muist not be {@literal null}.
* @return
* @since 1.8
Expand Down Expand Up @@ -378,6 +385,29 @@ public static Converter<Double, Distance> distanceConverterForMetric(Metric metr
return DistanceConverterFactory.INSTANCE.forMetric(metric);
}

/**
* Converts array outputs with key-value sequences (such as produced by {@code CONFIG GET}) from a {@link List} to
* {@link Properties}.
*
* @param input must not be {@literal null}.
* @return the mapped result.
* @since 2.0
*/
public static Properties toProperties(List<String> input) {
return STRING_LIST_TO_PROPERTIES_CONVERTER.convert(input);
}

/**
* Returns a converter to convert array outputs with key-value sequences (such as produced by {@code CONFIG GET}) from
* a {@link List} to {@link Properties}.
*
* @return the converter.
* @since 2.0
*/
public static Converter<List<String>, Properties> listToPropertiesConverter() {
return STRING_LIST_TO_PROPERTIES_CONVERTER;
}

/**
* @author Christoph Strobl
* @since 1.8
Expand Down Expand Up @@ -436,5 +466,4 @@ public GeoResults<GeoLocation<V>> convert(GeoResults<GeoLocation<byte[]>> source
return new GeoResults<GeoLocation<V>>(values, source.getAverageDistance().getMetric());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public void shutdown(ShutdownOption option) {
* @see org.springframework.data.redis.connection.RedisServerCommands#getConfig(java.lang.String)
*/
@Override
public List<String> getConfig(final String pattern) {
public Properties getConfig(final String pattern) {

List<NodeResult<List<String>>> mapResult = connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterCommandCallback<List<String>>) client -> client.configGet(pattern))
Expand All @@ -316,18 +316,19 @@ public List<String> getConfig(final String pattern) {
}
}

return result;
return Converters.toProperties(result);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#getConfig(org.springframework.data.redis.connection.RedisClusterNode, java.lang.String)
*/
@Override
public List<String> getConfig(RedisClusterNode node, final String pattern) {
public Properties getConfig(RedisClusterNode node, final String pattern) {

return connection.getClusterCommandExecutor().executeCommandOnSingleNode(
(JedisClusterCommandCallback<List<String>>) client -> client.configGet(pattern), node).getValue();
(JedisClusterCommandCallback<Properties>) client -> Converters.toProperties(client.configGet(pattern)), node)
.getValue();
}

/*
Expand Down
Loading