2222import java .util .List ;
2323import java .util .Map ;
2424import java .util .concurrent .TimeUnit ;
25+
2526import org .springframework .data .redis .connection .BitFieldSubCommands ;
26- import org .springframework .data .redis .connection .RedisConnection ;
27+ import org .springframework .data .redis .connection .DefaultedRedisConnection ;
2728import org .springframework .data .redis .connection .RedisStringCommands .SetOption ;
2829import org .springframework .data .redis .core .types .Expiration ;
2930import org .springframework .lang .Nullable ;
@@ -45,79 +46,39 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
4546
4647 @ Override
4748 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 ));
5650 }
5751
5852 @ Nullable
5953 @ Override
6054 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 ));
6956 }
7057
7158 @ Nullable
7259 @ Override
7360 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 ))));
8263 }
8364
8465 @ Nullable
8566 @ Override
8667 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 ))));
9569 }
9670
9771 @ Nullable
9872 @ Override
9973 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 ())));
10875 }
10976
11077 @ Override
11178 public V getAndSet (K key , V newValue ) {
11279
11380 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 )));
12182 }
12283
12384 @ Override
@@ -232,15 +193,10 @@ public Boolean multiSetIfAbsent(Map<? extends K, ? extends V> m) {
232193 @ Override
233194 public void set (K key , V value ) {
234195
196+ byte [] rawKey = rawKey (key );
235197 byte [] rawValue = rawValue (value );
236- execute (new ValueDeserializingRedisCallback (key ) {
237198
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 ));
244200 }
245201
246202 @ Override
0 commit comments