Skip to content

Commit 45b0170

Browse files
committed
DATAREDIS-500 - Polishing.
Apply formatting rules. Use differing serializers in test. Original pull request: #190.
1 parent 6f07ecf commit 45b0170

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
@@ -73,6 +73,7 @@
7373
* @author Costin Leau
7474
* @author Christoph Strobl
7575
* @author Ninad Divadkar
76+
* @author Anqing Shao
7677
* @param <K> the Redis key type against which the template works (usually a String)
7778
* @param <V> the Redis value type against which the template works
7879
* @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
@@ -45,20 +45,21 @@
4545
import org.springframework.dao.InvalidDataAccessApiUsageException;
4646
import org.springframework.data.redis.ConnectionFactoryTracker;
4747
import org.springframework.data.redis.ObjectFactory;
48+
import org.springframework.data.redis.Person;
4849
import org.springframework.data.redis.RedisTestProfileValueSource;
4950
import org.springframework.data.redis.SettingsUtils;
5051
import org.springframework.data.redis.TestCondition;
5152
import org.springframework.data.redis.connection.DataType;
5253
import org.springframework.data.redis.connection.RedisConnection;
5354
import org.springframework.data.redis.connection.StringRedisConnection;
54-
import org.springframework.data.redis.connection.jedis.JedisClusterConnection;
5555
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
5656
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
5757
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
5858
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
5959
import org.springframework.data.redis.core.query.SortQueryBuilder;
6060
import org.springframework.data.redis.core.script.DefaultRedisScript;
6161
import org.springframework.data.redis.serializer.GenericToStringSerializer;
62+
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
6263
import org.springframework.data.redis.serializer.RedisSerializer;
6364
import org.springframework.data.redis.serializer.StringRedisSerializer;
6465

@@ -67,6 +68,7 @@
6768
*
6869
* @author Jennifer Hickey
6970
* @author Christoph Strobl
71+
* @author Anqing Shao
7072
*/
7173
@RunWith(Parameterized.class)
7274
public class RedisTemplateTests<K, V> {
@@ -300,7 +302,9 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
300302
@SuppressWarnings("rawtypes")
301303
@Test
302304
public void testExecutePipelinedCustomSerializer() {
305+
303306
assumeTrue(redisTemplate instanceof StringRedisTemplate);
307+
304308
List<Object> results = redisTemplate.executePipelined(new RedisCallback() {
305309
public Object doInRedis(RedisConnection connection) throws DataAccessException {
306310
StringRedisConnection stringRedisConn = (StringRedisConnection) connection;
@@ -312,23 +316,34 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
312316
return null;
313317
}
314318
}, new GenericToStringSerializer<Long>(Long.class));
319+
315320
assertEquals(Arrays.asList(new Object[] { 5l, 1l, 2l, Arrays.asList(new Long[] { 10l, 11l }) }), results);
316321
}
317322

323+
/**
324+
* @see DATAREDIS-500
325+
*/
318326
@Test
319327
public void testExecutePipelinedWidthDifferentHashKeySerializerAndHashValueSerializer() {
328+
320329
assumeTrue(redisTemplate instanceof StringRedisTemplate);
330+
321331
redisTemplate.setKeySerializer(new StringRedisSerializer());
322-
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
323-
redisTemplate.setHashValueSerializer(new GenericToStringSerializer<Long>(Long.class));
324-
redisTemplate.opsForHash().put((K) "foo", "key", 1L);
332+
redisTemplate.setHashKeySerializer(new GenericToStringSerializer<Long>(Long.class));
333+
redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<Person>(Person.class));
334+
335+
Person person = new Person("Homer", "Simpson", 38);
336+
337+
redisTemplate.opsForHash().put((K) "foo", 1L, person);
338+
325339
List<Object> results = redisTemplate.executePipelined(new RedisCallback() {
326340
public Object doInRedis(RedisConnection connection) throws DataAccessException {
327341
connection.hGetAll(((StringRedisSerializer) redisTemplate.getKeySerializer()).serialize("foo"));
328342
return null;
329343
}
330344
});
331-
assertEquals(((Map) results.get(0)).get("key"), 1L);
345+
346+
assertEquals(((Map) results.get(0)).get(1L), person);
332347
}
333348

334349
@Test(expected = InvalidDataAccessApiUsageException.class)

0 commit comments

Comments
 (0)