From fbf0f9b8e1dc755d15f69221c3717e8b3524f8a0 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Tue, 19 May 2020 10:36:57 +0300 Subject: [PATCH] Feature - RLiveObjectService.count() method implemented. #2785 --- .../org/redisson/RedissonLiveObjectService.java | 6 ++++++ .../org/redisson/api/RLiveObjectService.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java b/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java index c1fa01283..8383c895f 100644 --- a/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java +++ b/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java @@ -138,6 +138,12 @@ public class RedissonLiveObjectService implements RLiveObjectService { .collect(Collectors.toList()); } + @Override + public long count(Class entityClass, Condition condition) { + Set ids = seachEngine.find(entityClass, condition); + return ids.size(); + } + @Override public T attach(T detachedObject) { validateDetached(detachedObject); diff --git a/redisson/src/main/java/org/redisson/api/RLiveObjectService.java b/redisson/src/main/java/org/redisson/api/RLiveObjectService.java index 200db86db..33efb3159 100644 --- a/redisson/src/main/java/org/redisson/api/RLiveObjectService.java +++ b/redisson/src/main/java/org/redisson/api/RLiveObjectService.java @@ -70,6 +70,22 @@ public interface RLiveObjectService { */ Collection find(Class entityClass, Condition condition); + /** + * Counts the entities matches specified condition. + * Usage example: + *
+     * long objectsAmount = liveObjectService.count(MyObject.class, Conditions.or(Conditions.in("field", "value1", "value2"),
+     *                          Conditions.and(Conditions.eq("field2", "value2"), Conditions.eq("field3", "value5"))));
+     * 
+ * + * @see Conditions + * + * @param entityClass - entity class + * @param condition - condition object + * @return amount of live objects. + */ + long count(Class entityClass, Condition condition); + /** * Returns iterator for all entry ids by specified entityClass. * Ids traversed with SCAN operation. Each SCAN operation loads