Skip to content

Commit d3c2420

Browse files
committed
DATAREDIS-500 - Polishing.
Apply formatting rules. Use differing serializers in test. Original pull request: #190.
1 parent 0a918c5 commit d3c2420

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/main/java/org/springframework/data/redis/core/RedisTemplate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
*
7272
* @author Costin Leau
7373
* @author Christoph Strobl
74+
* @author Anqing Shao
7475
* @param <K> the Redis key type against which the template works (usually a String)
7576
* @param <V> the Redis value type against which the template works
7677
* @see StringRedisTemplate

src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,21 @@
4343
import org.springframework.dao.DataAccessException;
4444
import org.springframework.dao.InvalidDataAccessApiUsageException;
4545
import org.springframework.data.redis.ObjectFactory;
46+
import org.springframework.data.redis.Person;
4647
import org.springframework.data.redis.RedisTestProfileValueSource;
4748
import org.springframework.data.redis.SettingsUtils;
4849
import org.springframework.data.redis.TestCondition;
4950
import org.springframework.data.redis.connection.DataType;
5051
import org.springframework.data.redis.connection.RedisConnection;
5152
import org.springframework.data.redis.connection.StringRedisConnection;
52-
import org.springframework.data.redis.connection.jedis.JedisClusterConnection;
5353
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
5454
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
5555
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
5656
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
5757
import org.springframework.data.redis.core.query.SortQueryBuilder;
5858
import org.springframework.data.redis.core.script.DefaultRedisScript;
5959
import org.springframework.data.redis.serializer.GenericToStringSerializer;
60+
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
6061
import org.springframework.data.redis.serializer.RedisSerializer;
6162
import org.springframework.data.redis.serializer.StringRedisSerializer;
6263

@@ -65,6 +66,7 @@
6566
*
6667
* @author Jennifer Hickey
6768
* @author Christoph Strobl
69+
* @author Anqing Shao
6870
*/
6971
@RunWith(Parameterized.class)
7072
public class RedisTemplateTests<K, V> {
@@ -291,7 +293,9 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
291293
@SuppressWarnings("rawtypes")
292294
@Test
293295
public void testExecutePipelinedCustomSerializer() {
296+
294297
assumeTrue(redisTemplate instanceof StringRedisTemplate);
298+
295299
List<Object> results = redisTemplate.executePipelined(new RedisCallback() {
296300
public Object doInRedis(RedisConnection connection) throws DataAccessException {
297301
StringRedisConnection stringRedisConn = (StringRedisConnection) connection;
@@ -303,23 +307,34 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
303307
return null;
304308
}
305309
}, new GenericToStringSerializer<Long>(Long.class));
310+
306311
assertEquals(Arrays.asList(new Object[] { 5l, 1l, 2l, Arrays.asList(new Long[] { 10l, 11l }) }), results);
307312
}
308313

314+
/**
315+
* @see DATAREDIS-500
316+
*/
309317
@Test
310318
public void testExecutePipelinedWidthDifferentHashKeySerializerAndHashValueSerializer() {
319+
311320
assumeTrue(redisTemplate instanceof StringRedisTemplate);
321+
312322
redisTemplate.setKeySerializer(new StringRedisSerializer());
313-
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
314-
redisTemplate.setHashValueSerializer(new GenericToStringSerializer<Long>(Long.class));
315-
redisTemplate.opsForHash().put((K) "foo", "key", 1L);
323+
redisTemplate.setHashKeySerializer(new GenericToStringSerializer<Long>(Long.class));
324+
redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<Person>(Person.class));
325+
326+
Person person = new Person("Homer", "Simpson", 38);
327+
328+
redisTemplate.opsForHash().put((K) "foo", 1L, person);
329+
316330
List<Object> results = redisTemplate.executePipelined(new RedisCallback() {
317331
public Object doInRedis(RedisConnection connection) throws DataAccessException {
318332
connection.hGetAll(((StringRedisSerializer) redisTemplate.getKeySerializer()).serialize("foo"));
319333
return null;
320334
}
321335
});
322-
assertEquals(((Map) results.get(0)).get("key"), 1L);
336+
337+
assertEquals(((Map) results.get(0)).get(1L), person);
323338
}
324339

325340
@Test(expected = InvalidDataAccessApiUsageException.class)

0 commit comments

Comments
 (0)