File tree Expand file tree Collapse file tree 4 files changed +37
-7
lines changed
main/java/org/springframework/data/redis/core
test/java/org/springframework/data/redis/core Expand file tree Collapse file tree 4 files changed +37
-7
lines changed Original file line number Diff line number Diff line change @@ -605,9 +605,9 @@ public Long doInRedis(RedisConnection connection) throws DataAccessException {
605
605
}
606
606
});
607
607
608
- if (timeout != null || ( timeout == null && !ttlProperty .getType ().isPrimitive () )) {
608
+ if (timeout != null || !ttlProperty .getType ().isPrimitive ()) {
609
609
entity .getPropertyAccessor (target ).setProperty (ttlProperty ,
610
- NumberUtils . convertNumberToTargetClass ( timeout , ( Class ) ttlProperty .getType ()));
610
+ converter . getConversionService (). convert ( timeout , ttlProperty .getType ()));
611
611
}
612
612
}
613
613
Original file line number Diff line number Diff line change @@ -282,9 +282,9 @@ public Long getTimeToLive(final Object source) {
282
282
} else if (ttlProperty != null ) {
283
283
284
284
RedisPersistentEntity entity = mappingContext .getPersistentEntity (type );
285
- Long timeout = (Long ) entity .getPropertyAccessor (source ).getProperty (ttlProperty );
285
+ Number timeout = (Number ) entity .getPropertyAccessor (source ).getProperty (ttlProperty );
286
286
if (timeout != null ) {
287
- return TimeUnit .SECONDS .convert (timeout , unit );
287
+ return TimeUnit .SECONDS .convert (timeout . longValue () , unit );
288
288
}
289
289
290
290
} else {
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2015 the original author or authors.
2
+ * Copyright 2015-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ public interface RedisPersistentEntity<T> extends KeyValuePersistentEntity<T> {
43
43
boolean hasExplictTimeToLiveProperty ();
44
44
45
45
/**
46
- * Get the {@link PersistentProperty}
46
+ * Get the {@link PersistentProperty} that is annotated with {@link org.springframework.data.redis.core.TimeToLive}.
47
47
*
48
48
* @return can be {@null}.
49
49
* @since 1.8
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2015 the original author or authors.
2
+ * Copyright 2015-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
48
48
import lombok .EqualsAndHashCode ;
49
49
50
50
/**
51
+ * Integration tests for {@link RedisKeyValueTemplate}.
52
+ *
51
53
* @author Christoph Strobl
54
+ * @author Mark Paluch
52
55
*/
53
56
@ RunWith (Parameterized .class )
54
57
public class RedisKeyValueTemplateTests {
@@ -887,6 +890,25 @@ public void shouldReadBackExplicitTimeToLive() throws InterruptedException {
887
890
assertThat (target .ttl .doubleValue (), is (closeTo (3D , 1D )));
888
891
}
889
892
893
+ /**
894
+ * @see DATAREDIS-523
895
+ */
896
+ @ Test
897
+ public void shouldReadBackExplicitTimeToLiveToPrimitiveField () throws InterruptedException {
898
+
899
+ WithPrimitiveTtl source = new WithPrimitiveTtl ();
900
+ source .id = "ttl-1" ;
901
+ source .ttl = 5 ;
902
+ source .value = "5 seconds" ;
903
+
904
+ template .insert (source );
905
+
906
+ Thread .sleep (1100 );
907
+
908
+ WithPrimitiveTtl target = template .findById (source .id , WithPrimitiveTtl .class );
909
+ assertThat ((double ) target .ttl , is (closeTo (3D , 1D )));
910
+ }
911
+
890
912
/**
891
913
* @see DATAREDIS-523
892
914
*/
@@ -1049,4 +1071,12 @@ static class WithTtl {
1049
1071
String value ;
1050
1072
@ TimeToLive Long ttl ;
1051
1073
}
1074
+
1075
+ @ Data
1076
+ static class WithPrimitiveTtl {
1077
+
1078
+ @ Id String id ;
1079
+ String value ;
1080
+ @ TimeToLive int ttl ;
1081
+ }
1052
1082
}
You can’t perform that action at this time.
0 commit comments