4545import org .springframework .dao .InvalidDataAccessApiUsageException ;
4646import org .springframework .data .redis .ConnectionFactoryTracker ;
4747import org .springframework .data .redis .ObjectFactory ;
48+ import org .springframework .data .redis .Person ;
4849import org .springframework .data .redis .RedisTestProfileValueSource ;
4950import org .springframework .data .redis .SettingsUtils ;
5051import org .springframework .data .redis .TestCondition ;
5152import org .springframework .data .redis .connection .DataType ;
5253import org .springframework .data .redis .connection .RedisConnection ;
5354import org .springframework .data .redis .connection .StringRedisConnection ;
54- import org .springframework .data .redis .connection .jedis .JedisClusterConnection ;
5555import org .springframework .data .redis .connection .jedis .JedisConnectionFactory ;
5656import org .springframework .data .redis .connection .jredis .JredisConnectionFactory ;
5757import org .springframework .data .redis .connection .srp .SrpConnectionFactory ;
5858import org .springframework .data .redis .core .ZSetOperations .TypedTuple ;
5959import org .springframework .data .redis .core .query .SortQueryBuilder ;
6060import org .springframework .data .redis .core .script .DefaultRedisScript ;
6161import org .springframework .data .redis .serializer .GenericToStringSerializer ;
62+ import org .springframework .data .redis .serializer .Jackson2JsonRedisSerializer ;
6263import org .springframework .data .redis .serializer .RedisSerializer ;
6364import org .springframework .data .redis .serializer .StringRedisSerializer ;
6465
6768 *
6869 * @author Jennifer Hickey
6970 * @author Christoph Strobl
71+ * @author Anqing Shao
7072 */
7173@ RunWith (Parameterized .class )
7274public class RedisTemplateTests <K , V > {
@@ -300,7 +302,9 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
300302@ SuppressWarnings ("rawtypes" )
301303@ Test
302304public void testExecutePipelinedCustomSerializer () {
305+
303306assumeTrue (redisTemplate instanceof StringRedisTemplate );
307+
304308List <Object > results = redisTemplate .executePipelined (new RedisCallback () {
305309public Object doInRedis (RedisConnection connection ) throws DataAccessException {
306310StringRedisConnection stringRedisConn = (StringRedisConnection ) connection ;
@@ -312,23 +316,34 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
312316return null ;
313317}
314318}, new GenericToStringSerializer <Long >(Long .class ));
319+
315320assertEquals (Arrays .asList (new Object [] { 5l , 1l , 2l , Arrays .asList (new Long [] { 10l , 11l }) }), results );
316321}
317322
323+ /**
324+ * @see DATAREDIS-500
325+ */
318326@ Test
319327public void testExecutePipelinedWidthDifferentHashKeySerializerAndHashValueSerializer () {
328+
320329assumeTrue (redisTemplate instanceof StringRedisTemplate );
330+
321331redisTemplate .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+
325339List <Object > results = redisTemplate .executePipelined (new RedisCallback () {
326340public Object doInRedis (RedisConnection connection ) throws DataAccessException {
327341connection .hGetAll (((StringRedisSerializer ) redisTemplate .getKeySerializer ()).serialize ("foo" ));
328342return 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