45
45
import org .springframework .dao .InvalidDataAccessApiUsageException ;
46
46
import org .springframework .data .redis .ConnectionFactoryTracker ;
47
47
import org .springframework .data .redis .ObjectFactory ;
48
+ import org .springframework .data .redis .Person ;
48
49
import org .springframework .data .redis .RedisTestProfileValueSource ;
49
50
import org .springframework .data .redis .SettingsUtils ;
50
51
import org .springframework .data .redis .TestCondition ;
51
52
import org .springframework .data .redis .connection .DataType ;
52
53
import org .springframework .data .redis .connection .RedisConnection ;
53
54
import org .springframework .data .redis .connection .StringRedisConnection ;
54
- import org .springframework .data .redis .connection .jedis .JedisClusterConnection ;
55
55
import org .springframework .data .redis .connection .jedis .JedisConnectionFactory ;
56
56
import org .springframework .data .redis .connection .jredis .JredisConnectionFactory ;
57
57
import org .springframework .data .redis .connection .srp .SrpConnectionFactory ;
58
58
import org .springframework .data .redis .core .ZSetOperations .TypedTuple ;
59
59
import org .springframework .data .redis .core .query .SortQueryBuilder ;
60
60
import org .springframework .data .redis .core .script .DefaultRedisScript ;
61
61
import org .springframework .data .redis .serializer .GenericToStringSerializer ;
62
+ import org .springframework .data .redis .serializer .Jackson2JsonRedisSerializer ;
62
63
import org .springframework .data .redis .serializer .RedisSerializer ;
63
64
import org .springframework .data .redis .serializer .StringRedisSerializer ;
64
65
67
68
*
68
69
* @author Jennifer Hickey
69
70
* @author Christoph Strobl
71
+ * @author Anqing Shao
70
72
*/
71
73
@ RunWith (Parameterized .class )
72
74
public class RedisTemplateTests <K , V > {
@@ -300,7 +302,9 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
300
302
@ SuppressWarnings ("rawtypes" )
301
303
@ Test
302
304
public void testExecutePipelinedCustomSerializer () {
305
+
303
306
assumeTrue (redisTemplate instanceof StringRedisTemplate );
307
+
304
308
List <Object > results = redisTemplate .executePipelined (new RedisCallback () {
305
309
public Object doInRedis (RedisConnection connection ) throws DataAccessException {
306
310
StringRedisConnection stringRedisConn = (StringRedisConnection ) connection ;
@@ -312,23 +316,34 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
312
316
return null ;
313
317
}
314
318
}, new GenericToStringSerializer <Long >(Long .class ));
319
+
315
320
assertEquals (Arrays .asList (new Object [] { 5l , 1l , 2l , Arrays .asList (new Long [] { 10l , 11l }) }), results );
316
321
}
317
322
323
+ /**
324
+ * @see DATAREDIS-500
325
+ */
318
326
@ Test
319
327
public void testExecutePipelinedWidthDifferentHashKeySerializerAndHashValueSerializer () {
328
+
320
329
assumeTrue (redisTemplate instanceof StringRedisTemplate );
330
+
321
331
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
+
325
339
List <Object > results = redisTemplate .executePipelined (new RedisCallback () {
326
340
public Object doInRedis (RedisConnection connection ) throws DataAccessException {
327
341
connection .hGetAll (((StringRedisSerializer ) redisTemplate .getKeySerializer ()).serialize ("foo" ));
328
342
return null ;
329
343
}
330
344
});
331
- assertEquals (((Map ) results .get (0 )).get ("key" ), 1L );
345
+
346
+ assertEquals (((Map ) results .get (0 )).get (1L ), person );
332
347
}
333
348
334
349
@ Test (expected = InvalidDataAccessApiUsageException .class )
0 commit comments