@@ -562,6 +562,23 @@ public Boolean copy(K source, K target, boolean replace) {
562562 return doWithKeys (connection -> connection .copy (sourceKey , targetKey , replace ));
563563 }
564564
565+ @ Override
566+ public Boolean hasKey (K key ) {
567+
568+ byte [] rawKey = rawKey (key );
569+
570+ return doWithKeys (connection -> connection .exists (rawKey ));
571+ }
572+
573+ @ Override
574+ public Long countExistingKeys (Collection <K > keys ) {
575+
576+ Assert .notNull (keys , "Keys must not be null!" );
577+
578+ byte [][] rawKeys = rawKeys (keys );
579+ return doWithKeys (connection -> connection .exists (rawKeys ));
580+ }
581+
565582 @ Override
566583 public Boolean delete (K key ) {
567584
@@ -606,20 +623,56 @@ public Long unlink(Collection<K> keys) {
606623 }
607624
608625 @ Override
609- public Boolean hasKey (K key ) {
626+ public DataType type (K key ) {
610627
611628 byte [] rawKey = rawKey (key );
629+ return doWithKeys (connection -> connection .type (rawKey ));
630+ }
612631
613- return doWithKeys (connection -> connection .exists (rawKey ));
632+ @ Override
633+ @ SuppressWarnings ("unchecked" )
634+ public Set <K > keys (K pattern ) {
635+
636+ byte [] rawKey = rawKey (pattern );
637+ Set <byte []> rawKeys = doWithKeys (connection -> connection .keys (rawKey ));
638+
639+ return keySerializer != null ? SerializationUtils .deserialize (rawKeys , keySerializer ) : (Set <K >) rawKeys ;
614640 }
615641
616642 @ Override
617- public Long countExistingKeys (Collection <K > keys ) {
643+ public Cursor <K > scan (ScanOptions options ) {
644+ Assert .notNull (options , "ScanOptions must not be null!" );
618645
619- Assert .notNull (keys , "Keys must not be null!" );
646+ return executeWithStickyConnection (
647+ (RedisCallback <Cursor <K >>) connection -> new ConvertingCursor <>(connection .scan (options ),
648+ this ::deserializeKey ));
649+ }
620650
621- byte [][] rawKeys = rawKeys (keys );
622- return doWithKeys (connection -> connection .exists (rawKeys ));
651+ @ Override
652+ public K randomKey () {
653+
654+ byte [] rawKey = doWithKeys (RedisKeyCommands ::randomKey );
655+ return deserializeKey (rawKey );
656+ }
657+
658+ @ Override
659+ public void rename (K oldKey , K newKey ) {
660+
661+ byte [] rawOldKey = rawKey (oldKey );
662+ byte [] rawNewKey = rawKey (newKey );
663+
664+ doWithKeys (connection -> {
665+ connection .rename (rawOldKey , rawNewKey );
666+ return null ;
667+ });
668+ }
669+
670+ @ Override
671+ public Boolean renameIfAbsent (K oldKey , K newKey ) {
672+
673+ byte [] rawOldKey = rawKey (oldKey );
674+ byte [] rawNewKey = rawKey (newKey );
675+ return doWithKeys (connection -> connection .renameNX (rawOldKey , rawNewKey ));
623676 }
624677
625678 @ Override
@@ -652,9 +705,12 @@ public Boolean expireAt(K key, final Date date) {
652705 });
653706 }
654707
655- // -------------------------------------------------------------------------
656- // Methods dealing with value operations
657- // -------------------------------------------------------------------------
708+ @ Override
709+ public Boolean persist (K key ) {
710+
711+ byte [] rawKey = rawKey (key );
712+ return doWithKeys (connection -> connection .persist (rawKey ));
713+ }
658714
659715 @ Override
660716 public Long getExpire (K key ) {
@@ -664,7 +720,7 @@ public Long getExpire(K key) {
664720 }
665721
666722 @ Override
667- public Long getExpire (K key , final TimeUnit timeUnit ) {
723+ public Long getExpire (K key , TimeUnit timeUnit ) {
668724
669725 byte [] rawKey = rawKey (key );
670726 return doWithKeys (connection -> {
@@ -677,73 +733,13 @@ public Long getExpire(K key, final TimeUnit timeUnit) {
677733 });
678734 }
679735
680- @ Override
681- @ SuppressWarnings ("unchecked" )
682- public Set <K > keys (K pattern ) {
683-
684- byte [] rawKey = rawKey (pattern );
685- Set <byte []> rawKeys = doWithKeys (connection -> connection .keys (rawKey ));
686-
687- return keySerializer != null ? SerializationUtils .deserialize (rawKeys , keySerializer ) : (Set <K >) rawKeys ;
688- }
689-
690- @ Override
691- public Cursor <K > scan (ScanOptions options ) {
692- Assert .notNull (options , "ScanOptions must not be null!" );
693-
694- return executeWithStickyConnection (
695- (RedisCallback <Cursor <K >>) connection -> new ConvertingCursor <>(connection .scan (options ),
696- this ::deserializeKey ));
697- }
698-
699- @ Override
700- public Boolean persist (K key ) {
701-
702- byte [] rawKey = rawKey (key );
703- return doWithKeys (connection -> connection .persist (rawKey ));
704- }
705-
706736 @ Override
707737 public Boolean move (K key , final int dbIndex ) {
708738
709739 byte [] rawKey = rawKey (key );
710740 return doWithKeys (connection -> connection .move (rawKey , dbIndex ));
711741 }
712742
713- @ Override
714- public K randomKey () {
715-
716- byte [] rawKey = doWithKeys (RedisKeyCommands ::randomKey );
717- return deserializeKey (rawKey );
718- }
719-
720- @ Override
721- public void rename (K oldKey , K newKey ) {
722-
723- byte [] rawOldKey = rawKey (oldKey );
724- byte [] rawNewKey = rawKey (newKey );
725-
726- doWithKeys (connection -> {
727- connection .rename (rawOldKey , rawNewKey );
728- return null ;
729- });
730- }
731-
732- @ Override
733- public Boolean renameIfAbsent (K oldKey , K newKey ) {
734-
735- byte [] rawOldKey = rawKey (oldKey );
736- byte [] rawNewKey = rawKey (newKey );
737- return doWithKeys (connection -> connection .renameNX (rawOldKey , rawNewKey ));
738- }
739-
740- @ Override
741- public DataType type (K key ) {
742-
743- byte [] rawKey = rawKey (key );
744- return doWithKeys (connection -> connection .type (rawKey ));
745- }
746-
747743 /**
748744 * Executes the Redis dump command and returns the results. Redis uses a non-standard serialization mechanism and
749745 * includes checksum information, thus the raw bytes are returned as opposed to deserializing with valueSerializer.
0 commit comments