@@ -131,8 +131,8 @@ public RedisKeyValueAdapter(RedisOperations<?, ?> redisOps, RedisMappingContext
131
131
Assert .notNull (redisOps , "RedisOperations must not be null!" );
132
132
Assert .notNull (mappingContext , "RedisMappingContext must not be null!" );
133
133
134
- MappingRedisConverter mappingConverter = new MappingRedisConverter (mappingContext ,
135
- new PathIndexResolver ( mappingContext ), new ReferenceResolverImpl (this ));
134
+ MappingRedisConverter mappingConverter = new MappingRedisConverter (mappingContext , new PathIndexResolver (
135
+ mappingContext ), new ReferenceResolverImpl (this ));
136
136
mappingConverter .setCustomConversions (customConversions == null ? new CustomConversions () : customConversions );
137
137
mappingConverter .afterPropertiesSet ();
138
138
@@ -173,7 +173,7 @@ public Object put(final Serializable id, final Object item, final Serializable k
173
173
174
174
if (rdo .getId () == null ) {
175
175
176
- rdo .setId (id );
176
+ rdo .setId (converter . getConversionService (). convert ( id , String . class ) );
177
177
178
178
if (!(item instanceof RedisData )) {
179
179
KeyValuePersistentProperty idProperty = converter .getMappingContext ().getPersistentEntity (item .getClass ())
@@ -249,7 +249,10 @@ public Object get(Serializable id, Serializable keyspace) {
249
249
*/
250
250
public <T > T get (Serializable id , Serializable keyspace , Class <T > type ) {
251
251
252
- final byte [] binId = createKey (keyspace , id );
252
+ String stringId = asString (id );
253
+ String stringKeyspace = asString (keyspace );
254
+
255
+ final byte [] binId = createKey (stringKeyspace , stringId );
253
256
254
257
Map <byte [], byte []> raw = redisOps .execute (new RedisCallback <Map <byte [], byte []>>() {
255
258
@@ -260,8 +263,8 @@ public Map<byte[], byte[]> doInRedis(RedisConnection connection) throws DataAcce
260
263
});
261
264
262
265
RedisData data = new RedisData (raw );
263
- data .setId (id );
264
- data .setKeyspace (keyspace . toString () );
266
+ data .setId (stringId );
267
+ data .setKeyspace (stringKeyspace );
265
268
266
269
return converter .read (type , data );
267
270
}
@@ -287,15 +290,17 @@ public <T> T delete(final Serializable id, final Serializable keyspace, final Cl
287
290
288
291
if (o != null ) {
289
292
293
+ final byte [] keyToDelete = createKey (asString (keyspace ), asString (id ));
294
+
290
295
redisOps .execute (new RedisCallback <Void >() {
291
296
292
297
@ Override
293
298
public Void doInRedis (RedisConnection connection ) throws DataAccessException {
294
299
295
- connection .del (createKey ( keyspace , id ) );
300
+ connection .del (keyToDelete );
296
301
connection .sRem (binKeyspace , binId );
297
302
298
- new IndexWriter (connection , converter ).removeKeyFromIndexes (keyspace . toString ( ), binId );
303
+ new IndexWriter (connection , converter ).removeKeyFromIndexes (asString ( keyspace ), binId );
299
304
return null ;
300
305
}
301
306
});
@@ -322,7 +327,8 @@ public List<Map<byte[], byte[]>> doInRedis(RedisConnection connection) throws Da
322
327
Set <byte []> members = connection .sMembers (binKeyspace );
323
328
324
329
for (byte [] id : members ) {
325
- rawData .add (connection .hGetAll (createKey (binKeyspace , id )));
330
+ rawData .add (connection .hGetAll (createKey (asString (keyspace ),
331
+ getConverter ().getConversionService ().convert (id , String .class ))));
326
332
}
327
333
328
334
return rawData ;
@@ -349,7 +355,7 @@ public void deleteAllOf(final Serializable keyspace) {
349
355
public Void doInRedis (RedisConnection connection ) throws DataAccessException {
350
356
351
357
connection .del (toBytes (keyspace ));
352
- new IndexWriter (connection , converter ).removeAllIndexes (keyspace . toString ( ));
358
+ new IndexWriter (connection , converter ).removeAllIndexes (asString ( keyspace ));
353
359
return null ;
354
360
}
355
361
});
@@ -404,7 +410,12 @@ public void clear() {
404
410
// nothing to do
405
411
}
406
412
407
- public byte [] createKey (Serializable keyspace , Serializable id ) {
413
+ private String asString (Serializable value ) {
414
+ return value instanceof String ? (String ) value : getConverter ().getConversionService ()
415
+ .convert (value , String .class );
416
+ }
417
+
418
+ public byte [] createKey (String keyspace , String id ) {
408
419
return toBytes (keyspace + ":" + id );
409
420
}
410
421
@@ -600,7 +611,7 @@ public void setAdapter(RedisKeyValueAdapter adapter) {
600
611
* @see org.springframework.data.redis.core.convert.ReferenceResolver#resolveReference(java.io.Serializable, java.io.Serializable, java.lang.Class)
601
612
*/
602
613
@ Override
603
- public <T > T resolveReference (Serializable id , Serializable keyspace , Class <T > type ) {
614
+ public <T > T resolveReference (Serializable id , String keyspace , Class <T > type ) {
604
615
return (T ) adapter .get (id , keyspace , type );
605
616
}
606
617
}
0 commit comments