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