Package org.redisson

Class RedissonKeys

  • All Implemented Interfaces:
    RKeys, RKeysAsync

    public class RedissonKeys
    extends 
    implements RKeys
    Author:
    Nikita Koksharov
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean  name)
      Clear an expire timeout or expire date for object.
      >  name)
      Clear an expire timeout or expire date for object.
      void  name,  host, int port, int database, long timeout)
      Copy object from source Redis instance to destination Redis instance
      >  name,  host, int port, int database, long timeout)
      Copy object from source Redis instance to destination Redis instance in async mode
      long count()
      Returns the number of keys in the currently-selected database
      > countAsync()
      Returns the number of keys in the currently-selected database in async mode
      long ... names)
      Checks if provided keys exist
      > ... names)
      Checks if provided keys exist
      long ... keys)
      Delete multiple objects by name
      long delete​(RObject... objects)
      Delete multiple objects
      > ... keys)
      Delete multiple objects by name
      > deleteAsync​(RObject... objects)
      Delete multiple objects
      long  pattern)
      Delete multiple objects by a key pattern.
      >  pattern)
      Delete multiple objects by a key pattern.
      boolean  name, long timeToLive,  timeUnit)
      Set a timeout for object.
      >  name, long timeToLive,  timeUnit)
      Set a timeout for object.
      boolean  name, long timestamp)
      Set an expire date for object.
      >  name, long timestamp)
      Set an expire date for object.
      void flushall()
      Delete all keys of all existing databases
      > flushallAsync()
      Delete all keys of all existing databases
      void flushallParallel()
      Delete all keys of all existing databases in background without blocking server.
      > flushallParallelAsync()
      Delete all keys of all existing databases in background without blocking server.
      void flushdb()
      Delete all keys of currently selected database
      > flushdbAsync()
      Delete all keys of currently selected database
      void flushdbParallel()
      Delete all keys of currently selected database in background without blocking server.
      > flushdbParallelAsync()
      Delete all keys of currently selected database in background without blocking server.
      CommandAsyncExecutor getCommandExecutor()  
      ConnectionManager getConnectionManager()  
      <> getKeys()
      Get all keys using iterator.
      <> getKeys​(int count)
      Get all keys using iterator.
      <>  pattern)
      Get all keys by pattern using iterator.
      <>  pattern, int count)
      Get all keys by pattern using iterator.
      <T> <T> getKeysByPattern​(RedisCommand<?> command,  pattern, int limit, int count)  
      <> getKeysStream()
      Get all keys using Stream.
      <> getKeysStream​(int count)
      Get all keys using Stream.
      <>  pattern)
      Get all keys by pattern using Stream.
      <>  pattern, int count)
      Get all keys by pattern using Stream.
      <> getKeysWithLimit​(int limit)
      Get keys using iterator with defined limit.
      <>  pattern, int limit)
      Get keys using iterator with defined limit.
      int  key)
      Get hash slot identifier for key.
      >  key)
      Get hash slot identifier for key in async mode.
      RType  key)
      Get Redis object type by key
      RFuture<RType>  key)
      Get Redis object type by key
      void  name,  host, int port, int database, long timeout)
      Transfer object from source Redis instance to destination Redis instance
      >  name,  host, int port, int database, long timeout)
      Transfer object from source Redis instance to destination Redis instance
      boolean  name, int database)
      Move object to another database
      >  name, int database)
      Move object to another database
      randomKey()
      Get random key
      > randomKeyAsync()
      Get random key in async mode
      long  name)
      Remaining time to live of Redisson object that has a timeout
      >  name)
      Remaining time to live of Redisson object that has a timeout
      void  currentName,  newName)
      Rename current object key to newName
      >  currentName,  newName)
      Rename current object key to newName
      boolean  oldName,  newName)
      Rename object with oldName to newName only if new key is not exists
      >  oldName,  newName)
      Rename object with oldName to newName only if new key is not exists
      >> scanIteratorAsync​(RedisClient client, MasterSlaveEntry entry, long startPos,  pattern, int count)  
      >> scanIteratorAsync​(RedisClient client, MasterSlaveEntry entry, RedisCommand<?> command, long startPos,  pattern, int count)  
      void swapdb​(int db1, int db2)
      Swap two databases.
      > swapdbAsync​(int db1, int db2)
      Swap two databases.
      protected <T> <T> <T> iterator)  
      long ... names)
      Update the last access time of an object.
      > ... names)
      Update the last access time of an object.
      long ... keys)
      Delete multiple objects by name.
      > ... keys)
      Delete multiple objects by name.
      • Methods inherited from class java.lang.

        , , , , , , , , , ,
    • Method Detail

      • getType

        public  key)
        Description copied from interface: RKeys
        Get Redis object type by key
        Specified by:
        getType in interface RKeys
        Parameters:
        key - - name of key
        Returns:
        type of key
      • getTypeAsync

        public  key)
        Description copied from interface: RKeysAsync
        Get Redis object type by key
        Specified by:
        getTypeAsync in interface RKeysAsync
        Parameters:
        key - - name of key
        Returns:
        type of key
      • getSlot

        public int getSlot​( key)
        Description copied from interface: RKeys
        Get hash slot identifier for key. Available for cluster nodes only
        Specified by:
        getSlot in interface RKeys
        Parameters:
        key - - name of key
        Returns:
        slot number
      • getSlotAsync

        public > getSlotAsync​( key)
        Description copied from interface: RKeysAsync
        Get hash slot identifier for key in async mode. Available for cluster nodes only
        Specified by:
        getSlotAsync in interface RKeysAsync
        Parameters:
        key - - name of key
        Returns:
        slot
      • getKeysByPattern

        public <> getKeysByPattern​( pattern)
        Description copied from interface: RKeys
        Get all keys by pattern using iterator. Keys traversed with SCAN operation. Each SCAN operation loads up to 10 keys per request.

        Supported glob-style patterns:

        h?llo subscribes to hello, hallo and hxllo

        h*llo subscribes to hllo and heeeello

        h[ae]llo subscribes to hello and hallo, but not hillo

        Specified by:
        getKeysByPattern in interface RKeys
        Parameters:
        pattern - - match pattern
        Returns:
        Iterable object
      • getKeysByPattern

        public <> getKeysByPattern​( pattern,
                                                 int count)
        Description copied from interface: RKeys
        Get all keys by pattern using iterator. Keys traversed with SCAN operation. Each SCAN operation loads up to count keys per request.

        Supported glob-style patterns:

        h?llo subscribes to hello, hallo and hxllo

        h*llo subscribes to hllo and heeeello

        h[ae]llo subscribes to hello and hallo, but not hillo

        Specified by:
        getKeysByPattern in interface RKeys
        Parameters:
        pattern - - match pattern
        count - - keys loaded per request to Redis
        Returns:
        Iterable object
      • getKeysByPattern

        public <T> <T> getKeysByPattern​(RedisCommand<?> command,
                                                 pattern,
                                                int limit,
                                                int count)
      • getKeysWithLimit

        public <> getKeysWithLimit​(int limit)
        Description copied from interface: RKeys
        Get keys using iterator with defined limit. Keys are traversed with SCAN operation.
        Specified by:
        getKeysWithLimit in interface RKeys
        Parameters:
        limit - - limit of keys amount
        Returns:
        Iterable object
      • getKeysWithLimit

        public <> getKeysWithLimit​( pattern,
                                                 int limit)
        Description copied from interface: RKeys
        Get keys using iterator with defined limit. Keys are traversed with SCAN operation.

        Supported glob-style patterns:

        h?llo subscribes to hello, hallo and hxllo

        h*llo subscribes to hllo and heeeello

        h[ae]llo subscribes to hello and hallo, but not hillo

        Specified by:
        getKeysWithLimit in interface RKeys
        Parameters:
        pattern - - match pattern
        limit - - limit of keys amount
        Returns:
        Iterable object
      • getKeys

        public <> getKeys()
        Description copied from interface: RKeys
        Get all keys using iterator. Keys traversing with SCAN operation. Each SCAN operation loads up to 10 keys per request.
        Specified by:
        getKeys in interface RKeys
        Returns:
        Iterable object
      • getKeys

        public <> getKeys​(int count)
        Description copied from interface: RKeys
        Get all keys using iterator. Keys traversing with SCAN operation. Each SCAN operation loads up to count keys per request.
        Specified by:
        getKeys in interface RKeys
        Parameters:
        count - - keys loaded per request to Redis
        Returns:
        Iterable object
      • scanIteratorAsync

        public >> scanIteratorAsync​(RedisClient client,
                                                             MasterSlaveEntry entry,
                                                             long startPos,
                                                              pattern,
                                                             int count)
      • touch

        public long touch​(... names)
        Description copied from interface: RKeys
        Update the last access time of an object.
        Specified by:
        touch in interface RKeys
        Parameters:
        names - of keys
        Returns:
        count of objects were touched
      • touchAsync

        public > touchAsync​(... names)
        Description copied from interface: RKeysAsync
        Update the last access time of an object.
        Specified by:
        touchAsync in interface RKeysAsync
        Parameters:
        names - of keys
        Returns:
        count of objects were touched
      • countExists

        public long countExists​(... names)
        Description copied from interface: RKeys
        Checks if provided keys exist
        Specified by:
        countExists in interface RKeys
        Parameters:
        names - of keys
        Returns:
        amount of existing keys
      • countExistsAsync

        public > countExistsAsync​(... names)
        Description copied from interface: RKeysAsync
        Checks if provided keys exist
        Specified by:
        countExistsAsync in interface RKeysAsync
        Parameters:
        names - of keys
        Returns:
        amount of existing keys
      • randomKey

        public  randomKey()
        Description copied from interface: RKeys
        Get random key
        Specified by:
        randomKey in interface RKeys
        Returns:
        random key
      • randomKeyAsync

        public > randomKeyAsync()
        Description copied from interface: RKeysAsync
        Get random key in async mode
        Specified by:
        randomKeyAsync in interface RKeysAsync
        Returns:
        random key
      • deleteByPattern

        public long deleteByPattern​( pattern)
        Description copied from interface: RKeys
        Delete multiple objects by a key pattern.

        Method executes in NON atomic way in cluster mode due to lua script limitations.

        Supported glob-style patterns: h?llo subscribes to hello, hallo and hxllo h*llo subscribes to hllo and heeeello h[ae]llo subscribes to hello and hallo, but not hillo

        Specified by:
        deleteByPattern in interface RKeys
        Parameters:
        pattern - - match pattern
        Returns:
        number of removed keys
      • deleteByPatternAsync

        public > deleteByPatternAsync​( pattern)
        Description copied from interface: RKeysAsync
        Delete multiple objects by a key pattern.

        Method executes in NON atomic way in cluster mode due to lua script limitations.

        Supported glob-style patterns: h?llo subscribes to hello, hallo and hxllo h*llo subscribes to hllo and heeeello h[ae]llo subscribes to hello and hallo, but not hillo

        Specified by:
        deleteByPatternAsync in interface RKeysAsync
        Parameters:
        pattern - - match pattern
        Returns:
        number of removed keys
      • delete

        public long delete​(... keys)
        Description copied from interface: RKeys
        Delete multiple objects by name
        Specified by:
        delete in interface RKeys
        Parameters:
        keys - - object names
        Returns:
        number of removed keys
      • delete

        public long delete​(RObject... objects)
        Description copied from interface: RKeys
        Delete multiple objects
        Specified by:
        delete in interface RKeys
        Parameters:
        objects - of Redisson
        Returns:
        number of removed keys
      • deleteAsync

        public > deleteAsync​(RObject... objects)
        Description copied from interface: RKeysAsync
        Delete multiple objects
        Specified by:
        deleteAsync in interface RKeysAsync
        Parameters:
        objects - of Redisson
        Returns:
        number of removed keys
      • unlink

        public long unlink​(... keys)
        Description copied from interface: RKeys
        Delete multiple objects by name. Actual removal will happen later asynchronously.

        Requires Redis 4.0+

        Specified by:
        unlink in interface RKeys
        Parameters:
        keys - of objects
        Returns:
        number of removed keys
      • unlinkAsync

        public > unlinkAsync​(... keys)
        Description copied from interface: RKeysAsync
        Delete multiple objects by name. Actual removal will happen later asynchronously.

        Requires Redis 4.0+

        Specified by:
        unlinkAsync in interface RKeysAsync
        Parameters:
        keys - - object names
        Returns:
        number of removed keys
      • deleteAsync

        public > deleteAsync​(... keys)
        Description copied from interface: RKeysAsync
        Delete multiple objects by name
        Specified by:
        deleteAsync in interface RKeysAsync
        Parameters:
        keys - - object names
        Returns:
        number of removed keys
      • count

        public long count()
        Description copied from interface: RKeys
        Returns the number of keys in the currently-selected database
        Specified by:
        count in interface RKeys
        Returns:
        count of keys
      • countAsync

        public > countAsync()
        Description copied from interface: RKeysAsync
        Returns the number of keys in the currently-selected database in async mode
        Specified by:
        countAsync in interface RKeysAsync
        Returns:
        number of keys
      • flushdbParallel

        public void flushdbParallel()
        Description copied from interface: RKeys
        Delete all keys of currently selected database in background without blocking server.

        Requires Redis 4.0+

        Specified by:
        flushdbParallel in interface RKeys
      • flushdbParallelAsync

        public > flushdbParallelAsync()
        Description copied from interface: RKeysAsync
        Delete all keys of currently selected database in background without blocking server.

        Requires Redis 4.0+

        Specified by:
        flushdbParallelAsync in interface RKeysAsync
        Returns:
        void
      • flushallParallel

        public void flushallParallel()
        Description copied from interface: RKeys
        Delete all keys of all existing databases in background without blocking server.

        Requires Redis 4.0+

        Specified by:
        flushallParallel in interface RKeys
      • flushallParallelAsync

        public > flushallParallelAsync()
        Description copied from interface: RKeysAsync
        Delete all keys of all existing databases in background without blocking server.

        Requires Redis 4.0+

        Specified by:
        flushallParallelAsync in interface RKeysAsync
        Returns:
        void
      • flushdb

        public void flushdb()
        Description copied from interface: RKeys
        Delete all keys of currently selected database
        Specified by:
        flushdb in interface RKeys
      • flushdbAsync

        public > flushdbAsync()
        Description copied from interface: RKeysAsync
        Delete all keys of currently selected database
        Specified by:
        flushdbAsync in interface RKeysAsync
        Returns:
        void
      • flushall

        public void flushall()
        Description copied from interface: RKeys
        Delete all keys of all existing databases
        Specified by:
        flushall in interface RKeys
      • flushallAsync

        public > flushallAsync()
        Description copied from interface: RKeysAsync
        Delete all keys of all existing databases
        Specified by:
        flushallAsync in interface RKeysAsync
        Returns:
        void
      • remainTimeToLive

        public long remainTimeToLive​( name)
        Description copied from interface: RKeys
        Remaining time to live of Redisson object that has a timeout
        Specified by:
        remainTimeToLive in interface RKeys
        Parameters:
        name - of key
        Returns:
        time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
      • remainTimeToLiveAsync

        public > remainTimeToLiveAsync​( name)
        Description copied from interface: RKeysAsync
        Remaining time to live of Redisson object that has a timeout
        Specified by:
        remainTimeToLiveAsync in interface RKeysAsync
        Parameters:
        name - of key
        Returns:
        time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
      • rename

        public void rename​( currentName,
                            newName)
        Description copied from interface: RKeys
        Rename current object key to newName
        Specified by:
        rename in interface RKeys
        Parameters:
        currentName - - current name of object
        newName - - new name of object
      • renameAsync

        public > renameAsync​( currentName,
                                          newName)
        Description copied from interface: RKeysAsync
        Rename current object key to newName
        Specified by:
        renameAsync in interface RKeysAsync
        Parameters:
        currentName - - current name of object
        newName - - new name of object
        Returns:
        void
      • renamenx

        public boolean renamenx​( oldName,
                                 newName)
        Description copied from interface: RKeys
        Rename object with oldName to newName only if new key is not exists
        Specified by:
        renamenx in interface RKeys
        Parameters:
        oldName - - old name of object
        newName - - new name of object
        Returns:
        true if object has been renamed successfully and false otherwise
      • renamenxAsync

        public > renamenxAsync​( oldName,
                                               newName)
        Description copied from interface: RKeysAsync
        Rename object with oldName to newName only if new key is not exists
        Specified by:
        renamenxAsync in interface RKeysAsync
        Parameters:
        oldName - - old name of object
        newName - - new name of object
        Returns:
        true if object has been renamed successfully and false otherwise
      • clearExpire

        public boolean clearExpire​( name)
        Description copied from interface: RKeys
        Clear an expire timeout or expire date for object.
        Specified by:
        clearExpire in interface RKeys
        Parameters:
        name - of object
        Returns:
        true if timeout was removed false if object does not exist or does not have an associated timeout
      • clearExpireAsync

        public > clearExpireAsync​( name)
        Description copied from interface: RKeysAsync
        Clear an expire timeout or expire date for object.
        Specified by:
        clearExpireAsync in interface RKeysAsync
        Parameters:
        name - of object
        Returns:
        true if timeout was removed false if object does not exist or does not have an associated timeout
      • expireAt

        public boolean expireAt​( name,
                                long timestamp)
        Description copied from interface: RKeys
        Set an expire date for object. When expire date comes the key will automatically be deleted.
        Specified by:
        expireAt in interface RKeys
        Parameters:
        name - of object
        timestamp - - expire date in milliseconds (Unix timestamp)
        Returns:
        true if the timeout was set and false if not
      • expireAtAsync

        public > expireAtAsync​( name,
                                              long timestamp)
        Description copied from interface: RKeysAsync
        Set an expire date for object. When expire date comes the key will automatically be deleted.
        Specified by:
        expireAtAsync in interface RKeysAsync
        Parameters:
        name - of object
        timestamp - - expire date in milliseconds (Unix timestamp)
        Returns:
        true if the timeout was set and false if not
      • expire

        public boolean expire​( name,
                              long timeToLive,
                               timeUnit)
        Description copied from interface: RKeys
        Set a timeout for object. After the timeout has expired, the key will automatically be deleted.
        Specified by:
        expire in interface RKeys
        Parameters:
        name - of object
        timeToLive - - timeout before object will be deleted
        timeUnit - - timeout time unit
        Returns:
        true if the timeout was set and false if not
      • expireAsync

        public > expireAsync​( name,
                                            long timeToLive,
                                             timeUnit)
        Description copied from interface: RKeysAsync
        Set a timeout for object. After the timeout has expired, the key will automatically be deleted.
        Specified by:
        expireAsync in interface RKeysAsync
        Parameters:
        name - of object
        timeToLive - - timeout before object will be deleted
        timeUnit - - timeout time unit
        Returns:
        true if the timeout was set and false if not
      • migrate

        public void migrate​( name,
                             host,
                            int port,
                            int database,
                            long timeout)
        Description copied from interface: RKeys
        Transfer object from source Redis instance to destination Redis instance
        Specified by:
        migrate in interface RKeys
        Parameters:
        name - of object
        host - - destination host
        port - - destination port
        database - - destination database
        timeout - - maximum idle time in any moment of the communication with the destination instance in milliseconds
      • migrateAsync

        public > migrateAsync​( name,
                                           host,
                                          int port,
                                          int database,
                                          long timeout)
        Description copied from interface: RKeysAsync
        Transfer object from source Redis instance to destination Redis instance
        Specified by:
        migrateAsync in interface RKeysAsync
        Parameters:
        name - of object
        host - - destination host
        port - - destination port
        database - - destination database
        timeout - - maximum idle time in any moment of the communication with the destination instance in milliseconds
        Returns:
        void
      • copy

        public void copy​( name,
                          host,
                         int port,
                         int database,
                         long timeout)
        Description copied from interface: RKeys
        Copy object from source Redis instance to destination Redis instance
        Specified by:
        copy in interface RKeys
        Parameters:
        name - of object
        host - - destination host
        port - - destination port
        database - - destination database
        timeout - - maximum idle time in any moment of the communication with the destination instance in milliseconds
      • copyAsync

        public > copyAsync​( name,
                                        host,
                                       int port,
                                       int database,
                                       long timeout)
        Description copied from interface: RKeysAsync
        Copy object from source Redis instance to destination Redis instance in async mode
        Specified by:
        copyAsync in interface RKeysAsync
        Parameters:
        name - of object
        host - - destination host
        port - - destination port
        database - - destination database
        timeout - - maximum idle time in any moment of the communication with the destination instance in milliseconds
        Returns:
        void
      • move

        public boolean move​( name,
                            int database)
        Description copied from interface: RKeys
        Move object to another database
        Specified by:
        move in interface RKeys
        Parameters:
        name - of object
        database - - Redis database number
        Returns:
        true if key was moved else false
      • moveAsync

        public > moveAsync​( name,
                                          int database)
        Description copied from interface: RKeysAsync
        Move object to another database
        Specified by:
        moveAsync in interface RKeysAsync
        Parameters:
        name - of object
        database - - Redis database number
        Returns:
        true if key was moved else false
      • getKeysStreamByPattern

        public <> getKeysStreamByPattern​( pattern)
        Description copied from interface: RKeys
        Get all keys by pattern using Stream. Keys traversed with SCAN operation. Each SCAN operation loads up to 10 keys per request.

        Supported glob-style patterns:

        h?llo subscribes to hello, hallo and hxllo

        h*llo subscribes to hllo and heeeello

        h[ae]llo subscribes to hello and hallo, but not hillo

        Specified by:
        getKeysStreamByPattern in interface RKeys
        Parameters:
        pattern - - match pattern
        Returns:
        Iterable object
      • toStream

        protected <T> <T> toStream​(<T> iterator)
      • getKeysStreamByPattern

        public <> getKeysStreamByPattern​( pattern,
                                                     int count)
        Description copied from interface: RKeys
        Get all keys by pattern using Stream. Keys traversed with SCAN operation. Each SCAN operation loads up to count keys per request.

        Supported glob-style patterns:

        h?llo subscribes to hello, hallo and hxllo

        h*llo subscribes to hllo and heeeello

        h[ae]llo subscribes to hello and hallo, but not hillo

        Specified by:
        getKeysStreamByPattern in interface RKeys
        Parameters:
        pattern - - match pattern
        count - - keys loaded per request to Redis
        Returns:
        Iterable object
      • getKeysStream

        public <> getKeysStream()
        Description copied from interface: RKeys
        Get all keys using Stream. Keys traversing with SCAN operation. Each SCAN operation loads up to 10 keys per request.
        Specified by:
        getKeysStream in interface RKeys
        Returns:
        Iterable object
      • getKeysStream

        public <> getKeysStream​(int count)
        Description copied from interface: RKeys
        Get all keys using Stream. Keys traversing with SCAN operation. Each SCAN operation loads up to count keys per request.
        Specified by:
        getKeysStream in interface RKeys
        Parameters:
        count - - keys loaded per request to Redis
        Returns:
        Iterable object
      • swapdb

        public void swapdb​(int db1,
                           int db2)
        Description copied from interface: RKeys
        Swap two databases.
        Specified by:
        swapdb in interface RKeys
      • swapdbAsync

        public > swapdbAsync​(int db1,
                                         int db2)
        Description copied from interface: RKeysAsync
        Swap two databases.

        Requires Redis 4.0+

        Specified by:
        swapdbAsync in interface RKeysAsync
        Returns:
        void