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
@@ -300,7 +301,9 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
300
301
@ SuppressWarnings ("rawtypes" )
301
302
@ Test
302
303
public void testExecutePipelinedCustomSerializer () {
304
+
303
305
assumeTrue (redisTemplate instanceof StringRedisTemplate );
306
+
304
307
List <Object > results = redisTemplate .executePipelined (new RedisCallback () {
305
308
public Object doInRedis (RedisConnection connection ) throws DataAccessException {
306
309
StringRedisConnection stringRedisConn = (StringRedisConnection ) connection ;
@@ -312,23 +315,34 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
312
315
return null ;
313
316
}
314
317
}, new GenericToStringSerializer <Long >(Long .class ));
318
+
315
319
assertEquals (Arrays .asList (new Object [] { 5l , 1l , 2l , Arrays .asList (new Long [] { 10l , 11l }) }), results );
316
320
}
317
321
322
+ /**
323
+ * @see DATAREDIS-500
324
+ */
318
325
@ Test
319
326
public void testExecutePipelinedWidthDifferentHashKeySerializerAndHashValueSerializer () {
327
+
320
328
assumeTrue (redisTemplate instanceof StringRedisTemplate );
329
+
321
330
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 );
331
+ redisTemplate .setHashKeySerializer (new GenericToStringSerializer <Long >(Long .class ));
332
+ redisTemplate .setHashValueSerializer (new Jackson2JsonRedisSerializer <Person >(Person .class ));
333
+
334
+ Person person = new Person ("Homer" , "Simpson" , 38 );
335
+
336
+ redisTemplate .opsForHash ().put ((K ) "foo" , 1L , person );
337
+
325
338
List <Object > results = redisTemplate .executePipelined (new RedisCallback () {
326
339
public Object doInRedis (RedisConnection connection ) throws DataAccessException {
327
340
connection .hGetAll (((StringRedisSerializer ) redisTemplate .getKeySerializer ()).serialize ("foo" ));
328
341
return null ;
329
342
}
330
343
});
331
- assertEquals (((Map ) results .get (0 )).get ("key" ), 1L );
344
+
345
+ assertEquals (((Map ) results .get (0 )).get (1L ), person );
332
346
}
333
347
334
348
@ Test (expected = InvalidDataAccessApiUsageException .class )
0 commit comments