22
22
import java .util .List ;
23
23
import java .util .Map ;
24
24
import java .util .concurrent .TimeUnit ;
25
+
25
26
import org .springframework .data .redis .connection .BitFieldSubCommands ;
26
- import org .springframework .data .redis .connection .RedisConnection ;
27
+ import org .springframework .data .redis .connection .DefaultedRedisConnection ;
27
28
import org .springframework .data .redis .connection .RedisStringCommands .SetOption ;
28
29
import org .springframework .data .redis .core .types .Expiration ;
29
30
import org .springframework .lang .Nullable ;
@@ -45,79 +46,39 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
45
46
46
47
@ Override
47
48
public V get (Object key ) {
48
-
49
- return execute (new ValueDeserializingRedisCallback (key ) {
50
-
51
- @ Override
52
- protected byte [] inRedis (byte [] rawKey , RedisConnection connection ) {
53
- return connection .get (rawKey );
54
- }
55
- });
49
+ return execute (valueCallbackFor (key , DefaultedRedisConnection ::get ));
56
50
}
57
51
58
52
@ Nullable
59
53
@ Override
60
54
public V getAndDelete (K key ) {
61
-
62
- return execute (new ValueDeserializingRedisCallback (key ) {
63
-
64
- @ Override
65
- protected byte [] inRedis (byte [] rawKey , RedisConnection connection ) {
66
- return connection .getDel (rawKey );
67
- }
68
- });
55
+ return execute (valueCallbackFor (key , DefaultedRedisConnection ::getDel ));
69
56
}
70
57
71
58
@ Nullable
72
59
@ Override
73
60
public V getAndExpire (K key , long timeout , TimeUnit unit ) {
74
-
75
- return execute (new ValueDeserializingRedisCallback (key ) {
76
-
77
- @ Override
78
- protected byte [] inRedis (byte [] rawKey , RedisConnection connection ) {
79
- return connection .getEx (rawKey , Expiration .from (timeout , unit ));
80
- }
81
- });
61
+ return execute (
62
+ valueCallbackFor (key , (connection , rawKey ) -> connection .getEx (rawKey , Expiration .from (timeout , unit ))));
82
63
}
83
64
84
65
@ Nullable
85
66
@ Override
86
67
public V getAndExpire (K key , Duration timeout ) {
87
-
88
- return execute (new ValueDeserializingRedisCallback (key ) {
89
-
90
- @ Override
91
- protected byte [] inRedis (byte [] rawKey , RedisConnection connection ) {
92
- return connection .getEx (rawKey , Expiration .from (timeout ));
93
- }
94
- });
68
+ return execute (valueCallbackFor (key , (connection , rawKey ) -> connection .getEx (rawKey , Expiration .from (timeout ))));
95
69
}
96
70
97
71
@ Nullable
98
72
@ Override
99
73
public V getAndPersist (K key ) {
100
-
101
- return execute (new ValueDeserializingRedisCallback (key ) {
102
-
103
- @ Override
104
- protected byte [] inRedis (byte [] rawKey , RedisConnection connection ) {
105
- return connection .getEx (rawKey , Expiration .persistent ());
106
- }
107
- });
74
+ return execute (valueCallbackFor (key , (connection , rawKey ) -> connection .getEx (rawKey , Expiration .persistent ())));
108
75
}
109
76
110
77
@ Override
111
78
public V getAndSet (K key , V newValue ) {
112
79
113
80
byte [] rawValue = rawValue (newValue );
114
- return execute (new ValueDeserializingRedisCallback (key ) {
115
-
116
- @ Override
117
- protected byte [] inRedis (byte [] rawKey , RedisConnection connection ) {
118
- return connection .getSet (rawKey , rawValue );
119
- }
120
- });
81
+ return execute (valueCallbackFor (key , (connection , rawKey ) -> connection .getSet (rawKey , rawValue )));
121
82
}
122
83
123
84
@ Override
@@ -232,15 +193,10 @@ public Boolean multiSetIfAbsent(Map<? extends K, ? extends V> m) {
232
193
@ Override
233
194
public void set (K key , V value ) {
234
195
196
+ byte [] rawKey = rawKey (key );
235
197
byte [] rawValue = rawValue (value );
236
- execute (new ValueDeserializingRedisCallback (key ) {
237
198
238
- @ Override
239
- protected byte [] inRedis (byte [] rawKey , RedisConnection connection ) {
240
- connection .set (rawKey , rawValue );
241
- return null ;
242
- }
243
- });
199
+ execute (connection -> connection .set (rawKey , rawValue ));
244
200
}
245
201
246
202
@ Override
0 commit comments