1. Object name

Name of Redisson object stored as a key in Redis or Valkey.

Example:

  1. RMap map = redisson.getMap("mymap");
  2. map.getName(); // = mymap

2. Common methods

Each Redisson object implements RObject and RExpirable interfaces.

Below are the most commonly used methods.

  1. RObject object = ...
  2. // Copy methods
  3. object.copy("myNewCopy");
  4. object.copyAndReplace("myNewCopy");
  5. // Delete methods
  6. object.delete();
  7. object.unlink(); // works faster because it's executed on the database side in a different thread
  8. // Rename methods
  9. object.rename("myNewName");
  10. object.renamenx("myNewName"); // rename only if the new key doesn't exist
  11. // Dump and restore methods
  12. byte[] state = object.dump();
  13. object.restore(state);

3. Listeners per Redisson object instance

Listeners can be attached per Redisson object instance. Base listeners are ExpiredObjectListener and DeletedObjectListener. Redisson objects may support specific listeners. Like RScoredSortedSet), RStream) and others.

  1. RObject object = ...
  2. // listening to expired events
  3. object.addListener((ExpiredObjectListener) name -> {
  4. //...
  5. });
  6. // listening to delete events
  7. object.addListener((DeletedObjectListener) name -> {
  8. //...
  9. });

4. Operations over all Redisson object instances

Operations over all objects are exposed by RKeys interface.

Usage example:

  1. RKeys keys = redisson.getKeys();
  2. // Keys iteration
  3. Iterable<String> allKeys = keys.getKeys();
  4. Iterable<String> foundedKeys = keys.getKeys(KeysScanOptions.defaults().pattern("key*"));
  5. String randomKey = keys.randomKey();
  6. long keysAmount = keys.count();
  7. long keysAmount = keys.countExists("obj1", "obj2", "obj3"); // amount of existing keys
  8. // Delete methods
  9. long delKeys = keys.delete("obj1", "obj2", "obj3");
  10. long delKeys = keys.deleteByPattern("test?");
  11. long delKeys = keys.unlink("obj1", "obj2", "obj3"); // works faster because it's executed on the database side in a different thread
  12. long delKeys = keys.unlinkByPattern("test?"); // works faster because it's executed on the database side in a different thread
  13. keys.flushall(); // Delete all keys of all existing databases
  14. keys.flushallParallel(); // Delete all keys of all existing databases in background without blocking server
  15. keys.flushdb(); // Delete all keys of currently selected database

5. Global listeners

Global listeners are attached to all Redisson object instances.

Available listeners:

Usage example:

  1. RKeys keys = redisson.getKeys();
  2. int id = keys.addListener((NewObjectListener) name -> {
  3. //...
  4. });
  5. int id = keys.addListener((DeletedObjectListener) name -> {
  6. //...
  7. });
  8. // Flush listener is executed on flushall/flushdb commands execution.
  9. int id = keys.addListener((FlushListener) address -> {
  10. //...
  11. });
  12. keys.removeListener(id);