16
16
package org .springframework .data .redis .connection .jedis ;
17
17
18
18
import redis .clients .jedis .Jedis ;
19
+ import redis .clients .jedis .params .RestoreParams ;
19
20
import redis .clients .jedis .params .ScanParams ;
20
21
import redis .clients .jedis .resps .ScanResult ;
21
22
@@ -366,33 +367,35 @@ public Long pTtl(byte[] key) {
366
367
367
368
Assert .notNull (key , "Key must not be null" );
368
369
369
- return connection .getClusterCommandExecutor ()
370
- .executeCommandOnSingleNode ((JedisClusterCommandCallback <Long >) client -> client .pttl (key ),
371
- connection .clusterGetNodeForKey (key ))
372
- .getValue ();
370
+ try {
371
+ return connection .getCluster ().pttl (key );
372
+ } catch (Exception ex ) {
373
+ throw convertJedisAccessException (ex );
374
+ }
373
375
}
374
376
375
377
@ Override
376
378
public Long pTtl (byte [] key , TimeUnit timeUnit ) {
377
379
378
380
Assert .notNull (key , "Key must not be null" );
379
381
380
- return connection . getClusterCommandExecutor ()
381
- . executeCommandOnSingleNode (
382
- ( JedisClusterCommandCallback < Long >) client -> Converters . millisecondsToTimeUnit ( client . pttl ( key ), timeUnit ),
383
- connection . clusterGetNodeForKey ( key ))
384
- . getValue ();
382
+ try {
383
+ return Converters . millisecondsToTimeUnit ( connection . getCluster (). pttl ( key ), timeUnit );
384
+ } catch ( Exception ex ) {
385
+ throw convertJedisAccessException ( ex );
386
+ }
385
387
}
386
388
387
389
@ Override
388
390
public byte [] dump (byte [] key ) {
389
391
390
392
Assert .notNull (key , "Key must not be null" );
391
393
392
- return connection .getClusterCommandExecutor ()
393
- .executeCommandOnSingleNode ((JedisClusterCommandCallback <byte []>) client -> client .dump (key ),
394
- connection .clusterGetNodeForKey (key ))
395
- .getValue ();
394
+ try {
395
+ return connection .getCluster ().dump (key );
396
+ } catch (Exception ex ) {
397
+ throw convertJedisAccessException (ex );
398
+ }
396
399
}
397
400
398
401
@ Override
@@ -401,16 +404,16 @@ public void restore(byte[] key, long ttlInMillis, byte[] serializedValue, boolea
401
404
Assert .notNull (key , "Key must not be null" );
402
405
Assert .notNull (serializedValue , "Serialized value must not be null" );
403
406
404
- connection .getClusterCommandExecutor ().executeCommandOnSingleNode ((JedisClusterCommandCallback <String >) client -> {
405
-
406
- if (!replace ) {
407
- return client .restore (key , ttlInMillis , serializedValue );
408
- }
409
-
410
- return JedisConverters .toString (this .connection .execute ("RESTORE" , key ,
411
- Arrays .asList (JedisConverters .toBytes (ttlInMillis ), serializedValue , JedisConverters .toBytes ("REPLACE" ))));
407
+ RestoreParams restoreParams = RestoreParams .restoreParams ();
412
408
413
- }, connection .clusterGetNodeForKey (key ));
409
+ if (replace ) {
410
+ restoreParams = restoreParams .replace ();
411
+ }
412
+ try {
413
+ connection .getCluster ().restore (key , ttlInMillis , serializedValue , restoreParams );
414
+ } catch (Exception ex ) {
415
+ throw convertJedisAccessException (ex );
416
+ }
414
417
}
415
418
416
419
@ Override
@@ -471,10 +474,11 @@ public ValueEncoding encodingOf(byte[] key) {
471
474
472
475
Assert .notNull (key , "Key must not be null" );
473
476
474
- return connection .getClusterCommandExecutor ()
475
- .executeCommandOnSingleNode ((JedisClusterCommandCallback <byte []>) client -> client .objectEncoding (key ),
476
- connection .clusterGetNodeForKey (key ))
477
- .mapValue (JedisConverters ::toEncoding );
477
+ try {
478
+ return JedisConverters .toEncoding (connection .getCluster ().objectEncoding (key ));
479
+ } catch (Exception ex ) {
480
+ throw convertJedisAccessException (ex );
481
+ }
478
482
}
479
483
480
484
@ Nullable
@@ -483,10 +487,11 @@ public Duration idletime(byte[] key) {
483
487
484
488
Assert .notNull (key , "Key must not be null" );
485
489
486
- return connection .getClusterCommandExecutor ()
487
- .executeCommandOnSingleNode ((JedisClusterCommandCallback <Long >) client -> client .objectIdletime (key ),
488
- connection .clusterGetNodeForKey (key ))
489
- .mapValue (Converters ::secondsToDuration );
490
+ try {
491
+ return Converters .secondsToDuration (connection .getCluster ().objectIdletime (key ));
492
+ } catch (Exception ex ) {
493
+ throw convertJedisAccessException (ex );
494
+ }
490
495
}
491
496
492
497
@ Nullable
@@ -495,10 +500,11 @@ public Long refcount(byte[] key) {
495
500
496
501
Assert .notNull (key , "Key must not be null" );
497
502
498
- return connection .getClusterCommandExecutor ()
499
- .executeCommandOnSingleNode ((JedisClusterCommandCallback <Long >) client -> client .objectRefcount (key ),
500
- connection .clusterGetNodeForKey (key ))
501
- .getValue ();
503
+ try {
504
+ return connection .getCluster ().objectRefcount (key );
505
+ } catch (Exception ex ) {
506
+ throw convertJedisAccessException (ex );
507
+ }
502
508
503
509
}
504
510
0 commit comments