diff --git a/redisson/src/main/java/org/redisson/api/RJsonStore.java b/redisson/src/main/java/org/redisson/api/RJsonStore.java new file mode 100644 index 000000000..afa0a9dc5 --- /dev/null +++ b/redisson/src/main/java/org/redisson/api/RJsonStore.java @@ -0,0 +1,893 @@ +/** + * Copyright (c) 2013-2024 Nikita Koksharov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.redisson.api; + +import org.redisson.codec.JsonCodec; + +import java.time.Duration; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * JSON Store which stores each entry as key and value. Both are POJO objects. + * Value is stored as JSON datatype in Redis. + *

+ * The implementation is available in Redisson PRO only. + * + * @author Nikita Koksharov + * + * @param the type of key + * @param the type of value + * + */ +public interface RJsonStore extends RExpirable, RJsonStoreAsync { + + /** + * Gets value by specified key and JSONPath + * + * @param key entry key + * @param codec entry value codec + * @param paths JSON paths + * @return entry value + * + * @param the type of object + */ + T get(K key, JsonCodec codec, String... paths); + + /** + * Sets value by specified key and JSONPath only if previous value is empty. + * + * @param key entry key + * @param path JSON path + * @param value entry value + * @return {@code true} if successful, or {@code false} if + * value was already set + */ + boolean setIfAbsent(K key, String path, Object value); + + /** + * Sets value by specified key and JSONPath only if previous value is non-empty. + * + * @param key entry key + * @param path JSON path + * @param value object + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + boolean setIfExists(K key, String path, Object value); + + /** + * Atomically sets the value to the given updated value + * by specified key and JSONPath, only if serialized state of + * the current value equals to serialized state of the expected value. + * + * @param key entry key + * @param path JSON path + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ + boolean compareAndSet(K key, String path, Object expect, Object update); + + /** + * Retrieves current value stored by specified key and JSONPath then + * replaces it with new value. + * + * @param key entry key + * @param codec entry value codec + * @param path JSON path + * @param newValue value to set + * @return previous value + */ + T getAndSet(K key, JsonCodec codec, String path, Object newValue); + + /** + * Stores value by specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param value value to set + */ + void set(K key, String path, Object value); + + /** + * Returns size of string data by specified key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return size of string + */ + Long stringSize(K key, String path); + + /** + * Returns list of string data size by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @return list of string data sizes + */ + List stringSizeMulti(K key, String path); + + /** + * Appends string data to element specified by specified key and JSONPath. + * Returns new size of string data. + * + * @param key entry key + * @param path JSON path + * @param value data + * @return size of string data + */ + long stringAppend(K key, String path, Object value); + + /** + * Appends string data to elements specified by specified key and JSONPath. + * Returns new size of string data. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value data + * @return list of string data sizes + */ + List stringAppendMulti(K key, String path, Object value); + + /** + * Appends values to array by specified key and JSONPath. + * Returns new size of array. + * + * @param key entry key + * @param path JSON path + * @param values values to append + * @return size of array + */ + long arrayAppend(K key, String path, Object... values); + + /** + * Appends values to arrays by specified key and JSONPath. + * Returns new size of arrays. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param values values to append + * @return list of arrays size + */ + List arrayAppendMulti(K key, String path, Object... values); + + /** + * Returns index of object in array by specified key and JSONPath. + * -1 means object not found. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @return index in array + */ + long arrayIndex(K key, String path, Object value); + + /** + * Returns index of object in arrays by specified key and JSONPath. + * -1 means object not found. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @return list of index in arrays + */ + List arrayIndexMulti(K key, String path, Object value); + + /** + * Returns index of object in array by specified key and JSONPath + * in range between start (inclusive) and end (exclusive) indexes. + * -1 means object not found. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @param start start index, inclusive + * @param end end index, exclusive + * @return index in array + */ + long arrayIndex(K key, String path, Object value, long start, long end); + + /** + * Returns index of object in arrays by specified key and JSONPath + * in range between start (inclusive) and end (exclusive) indexes. + * -1 means object not found. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @param start start index, inclusive + * @param end end index, exclusive + * @return list of index in arrays + */ + List arrayIndexMulti(K key, String path, Object value, long start, long end); + + /** + * Inserts values into array by specified key and JSONPath. + * Values are inserted at defined index. + * + * @param key entry key + * @param path JSON path + * @param index array index at which values are inserted + * @param values values to insert + * @return size of array + */ + long arrayInsert(K key, String path, long index, Object... values); + + /** + * Inserts values into arrays by specified key and JSONPath. + * Values are inserted at defined index. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param index array index at which values are inserted + * @param values values to insert + * @return list of arrays size + */ + List arrayInsertMulti(K key, String path, long index, Object... values); + + /** + * Returns size of array by specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @return size of array + */ + long arraySize(K key, String path); + + /** + * Returns size of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @return list of arrays size + */ + List arraySizeMulti(K key, String path); + + /** + * Polls last element of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return last element + * + * @param the type of object + */ + T arrayPollLast(K key, JsonCodec codec, String path); + + /** + * Polls last element of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return list of last elements + * + * @param the type of object + */ + List arrayPollLastMulti(K key, JsonCodec codec, String path); + + /** + * Polls first element of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return first element + * + * @param the type of object + */ + T arrayPollFirst(K key, JsonCodec codec, String path); + + /** + * Polls first element of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return list of first elements + * + * @param the type of object + */ + List arrayPollFirstMulti(K key, JsonCodec codec, String path); + + /** + * Pops element located at index of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @param index array index + * @return element + * + * @param the type of object + */ + T arrayPop(K key, JsonCodec codec, String path, long index); + + /** + * Pops elements located at index of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @param index array index + * @return list of elements + * + * @param the type of object + */ + List arrayPopMulti(K key, JsonCodec codec, String path, long index); + + /** + * Trims array by specified key and JSONPath in range + * between start (inclusive) and end (inclusive) indexes. + * + * @param key entry key + * @param path JSON path + * @param start start index, inclusive + * @param end end index, inclusive + * @return length of array + */ + long arrayTrim(K key, String path, long start, long end); + + /** + * Trims arrays by specified key and JSONPath in range + * between start (inclusive) and end (inclusive) indexes. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param start start index, inclusive + * @param end end index, inclusive + * @return length of array + */ + List arrayTrimMulti(K key, String path, long start, long end); + + /** + * Clears value by specified key + * + * @param key entry key + * @return {@code true} if successful, or {@code false} if + * entry doesn't exist + */ + boolean clear(K key); + + /** + * Clears json containers by specified keys. + * + * @param keys entry keys + * @return number of cleared containers + */ + long clear(Set keys); + + /** + * Clears json container by specified keys and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param path JSON path + * @param keys entry keys + * @return number of cleared containers + */ + long clear(String path, Set keys); + + /** + * Increments the current value specified by key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param delta increment value + * @return the updated value + */ + T incrementAndGet(K key, String path, T delta); + + /** + * Increments the current values specified by key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param delta increment value + * @return list of updated value + */ + List incrementAndGetMulti(K key, String path, T delta); + + /** + * Merges value into element by the specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param value value to merge + */ + void merge(K key, String path, Object value); + + /** + * Returns keys amount in JSON container by specified key + * + * @param key entry key + * @return keys amount + */ + long countKeys(K key); + + /** + * Returns keys amount in JSON container specified by key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return keys amount + */ + long countKeys(K key, String path); + + /** + * Returns list of keys amount in JSON containers specified by key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return list of keys amount + */ + List countKeysMulti(K key, String path); + + /** + * Returns list of keys in JSON container by specified key + * + * @return list of keys + */ + List getKeys(K key); + + /** + * Returns list of keys in JSON container by specified key and JSONPath + * + * @param path JSON path + * @return list of keys + */ + List getKeys(K key, String path); + + /** + * Returns list of keys in JSON containers by specified key and JSONPath + * + * @param path JSON path + * @return list of keys + */ + List> getKeysMulti(K key, String path); + + /** + * Toggle boolean value by specified key and JSONPath + * + * @param path JSON path + * @return new boolean value + */ + boolean toggle(K key, String path); + + /** + * Toggle boolean values by specified key and JSONPath + * + * @param path JSON path + * @return list of boolean values + */ + List toggleMulti(K key, String path); + + /** + * Returns type of value + * + * @return type of element + */ + JsonType getType(K key); + + /** + * Returns type of element specified by key and JSONPath + * + * @param path JSON path + * @return type of element + */ + JsonType getType(K key, String path); + + /** + * Deletes entry by specified key + * + * @param key entry key + * @return {@code true} if successful, or {@code false} if + * entry doesn't exist + */ + boolean delete(K key); + + /** + * Deletes entries by specified keys + * + * @param keys entry keys + * @return number of deleted elements + */ + long delete(Set keys); + + /** + * Deletes JSON elements specified by keys and JSONPath + * + * @param path JSON path + * @param keys entry keys + * @return number of deleted elements + */ + long delete(String path, Set keys); + + /** + * Returns size of entry in bytes specified by key. + * + * @param key entry key + * @return entry size + */ + long sizeInMemory(K key); + + /** + * Retrieves value by specified key. + * + * @param key entry key + * @return element + */ + V get(K key); + + /** + * Retrieves values by specified keys. + * + * @param keys entry keys + * @return map with entries where value mapped by key + */ + Map get(Set keys); + + /** + * Retrieves values by specified keys and JSONPath. + * + * @param path JSON path + * @param keys entry keys + * @return map with entries where value mapped by key + */ + Map get(String path, Set keys); + + /** + * Retrieves entry value by specified key and removes it. + * + * @param key entry key + * @return element + */ + V getAndDelete(K key); + + /** + * Sets value only if entry doesn't exist. + * + * @param key entry key + * @param value value to set + * @return {@code true} if successful, or {@code false} if + * element was already set + */ + boolean setIfAbsent(K key, V value); + + /** + * Sets value with defined duration only if entry doesn't exist. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return {@code true} if successful, or {@code false} if + * element was already set + */ + boolean setIfAbsent(K key, V value, Duration duration); + + /** + * Sets value only if entry already exists. + * + * @param key entry key + * @param value value to set + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + boolean setIfExists(K key, V value); + + /** + * Sets value with expiration duration only if entry already exists. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + boolean setIfExists(K key, V value, Duration duration); + + /** + * Atomically sets the value to the given updated value + * by specified key only if serialized state of the current value equals + * to serialized state of the expected value. + * + * @param key entry key + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ + boolean compareAndSet(K key, V expect, V update); + + /** + * Retrieves current value by specified key and replaces it with new value. + * + * @param key entry key + * @param newValue value to set + * @return previous value + */ + V getAndSet(K key, V newValue); + + /** + * Retrieves current value by specified key and replaces it + * with value and defines expiration duration. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return previous value + */ + V getAndSet(K key, V value, Duration duration); + + /** + * Retrieves current value by specified key and sets an expiration duration for it. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @param duration of object time to live interval + * @return value + */ + V getAndExpire(K key, Duration duration); + + /** + * Retrieves current value by specified key and sets an expiration date for it. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @param time of exact object expiration moment + * @return value + */ + V getAndExpire(K key, Instant time); + + /** + * Retrieves current value by specified key and clears expiration date set before. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @return value + */ + V getAndClearExpire(K key); + + /** + * Stores value by specified key. + * + * @param key entry key + * @param value value to set + */ + void set(K key, V value); + + /** + * Stores values by specified keys. + * + * @param entries entries to store + */ + void set(Map entries); + + /** + * Stores values by specified keys and JSONPath. + * + * @param path JSONPath + * @param entries entries to store + */ + void set(String path, Map entries); + + /** + * Stores value by specified key with defined expiration duration. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + */ + void set(K key, V value, Duration duration); + + /** + * Stores values by specified keys with defined expiration duration. + * + * @param entries entries to store + * @param duration expiration duration + */ + void set(Map entries, Duration duration); + + /** + * Sets value by specified key and keep existing TTL. + *

+ * Requires Redis 6.0.0 and higher. + * + * @param value value to set + */ + void setAndKeepTTL(K key, V value); + + /** + * Adds object event listener + * + * @see org.redisson.api.ExpiredObjectListener + * @see org.redisson.api.DeletedObjectListener + * @see org.redisson.api.listener.SetObjectListener + * + * @param listener object event listener + * @return listener id + */ + int addListener(ObjectListener listener); + + /** + * Remaining time to live of map entry associated with a key. + * + * @param key - map key + * @return time in milliseconds + * -2 if the key does not exist. + * -1 if the key exists but has no associated expire. + */ + long remainTimeToLive(K key); + + /** + * Returns key set of this map. + * Keys are loaded in batch. Batch size is 10. + * + * @see #readAllKeySet() + * + * @return key set + */ + Set keySet(); + + /** + * Returns key set of this map. + * Keys are loaded in batch. Batch size is defined by count param. + * + * @see #readAllKeySet() + * + * @param count - size of keys batch + * @return key set + */ + Set keySet(int count); + + /** + * Returns key set of this map. + * If pattern is not null then only keys match this pattern are loaded. + * Keys are loaded in batch. Batch size is defined by count param. + *

+ * Use org.redisson.client.codec.StringCodec for Map keys. + *

+ * + * 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 + * + * @see #readAllKeySet() + * + * @param pattern - key pattern + * @param count - size of keys batch + * @return key set + */ + Set keySet(String pattern, int count); + + /** + * Returns key set of this map. + * If pattern is not null then only keys match this pattern are loaded. + *

+ * Use org.redisson.client.codec.StringCodec for Map keys. + *

+ * + * 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 + * + * @see #readAllKeySet() + * + * @param pattern - key pattern + * @return key set + */ + Set keySet(String pattern); + + /** + * Returns true if this map contains map entry + * mapped by specified key, otherwise false + * + * @param key - map key + * @return true if this map contains map entry + * mapped by specified key, otherwise false + */ + boolean containsKey(Object key); + + /** + * Read all keys at once + * + * @return keys + */ + Set readAllKeySet(); + + /** + * Returns entries amount in store + * + * @return entries amount + */ + int size(); + + /** + * Returns RCountDownLatch instance associated with key + * + * @param key - map key + * @return countdownlatch + */ + RCountDownLatch getCountDownLatch(K key); + + /** + * Returns RPermitExpirableSemaphore instance associated with key + * + * @param key - map key + * @return permitExpirableSemaphore + */ + RPermitExpirableSemaphore getPermitExpirableSemaphore(K key); + + /** + * Returns RSemaphore instance associated with key + * + * @param key - map key + * @return semaphore + */ + RSemaphore getSemaphore(K key); + + /** + * Returns RLock instance associated with key + * + * @param key - map key + * @return fairlock + */ + RLock getFairLock(K key); + + /** + * Returns RReadWriteLock instance associated with key + * + * @param key - map key + * @return readWriteLock + */ + RReadWriteLock getReadWriteLock(K key); + + /** + * Returns RLock instance associated with key + * + * @param key - map key + * @return lock + */ + RLock getLock(K key); + +} diff --git a/redisson/src/main/java/org/redisson/api/RJsonStoreAsync.java b/redisson/src/main/java/org/redisson/api/RJsonStoreAsync.java new file mode 100644 index 000000000..ead018f43 --- /dev/null +++ b/redisson/src/main/java/org/redisson/api/RJsonStoreAsync.java @@ -0,0 +1,792 @@ +/** + * Copyright (c) 2013-2024 Nikita Koksharov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.redisson.api; + +import org.redisson.codec.JsonCodec; + +import java.time.Duration; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * JSON Store which stores each entry as key and value. Both are POJO objects. + * Value is stored as JSON datatype in Redis. + *

+ * The implementation is available in Redisson PRO only. + * + * @author Nikita Koksharov + * + * @param the type of key + * @param the type of value + * + */ +public interface RJsonStoreAsync extends RExpirableAsync { + + /** + * Gets value by specified key and JSONPath + * + * @param key entry key + * @param codec entry value codec + * @param paths JSON paths + * @return entry value + * + * @param the type of object + */ + RFuture getAsync(K key, JsonCodec codec, String... paths); + + /** + * Sets value by specified key and JSONPath only if previous value is empty. + * + * @param key entry key + * @param path JSON path + * @param value entry value + * @return {@code true} if successful, or {@code false} if + * value was already set + */ + RFuture setIfAbsentAsync(K key, String path, Object value); + + /** + * Sets value by specified key and JSONPath only if previous value is non-empty. + * + * @param key entry key + * @param path JSON path + * @param value object + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + RFuture setIfExistsAsync(K key, String path, Object value); + + /** + * Atomically sets the value to the given updated value + * by specified key and JSONPath, only if serialized state of + * the current value equals to serialized state of the expected value. + * + * @param key entry key + * @param path JSON path + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ + RFuture compareAndSetAsync(K key, String path, Object expect, Object update); + + /** + * Retrieves current value stored by specified key and JSONPath then + * replaces it with new value. + * + * @param key entry key + * @param codec entry value codec + * @param path JSON path + * @param newValue value to set + * @return previous value + */ + RFuture getAndSetAsync(K key, JsonCodec codec, String path, Object newValue); + + /** + * Stores value by specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param value value to set + */ + RFuture setAsync(K key, String path, Object value); + + /** + * Returns size of string data by specified key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return size of string + */ + RFuture stringSizeAsync(K key, String path); + + /** + * Returns list of string data size by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @return list of string data sizes + */ + RFuture> stringSizeMultiAsync(K key, String path); + + /** + * Appends string data to element specified by specified key and JSONPath. + * Returns new size of string data. + * + * @param key entry key + * @param path JSON path + * @param value data + * @return size of string data + */ + RFuture stringAppendAsync(K key, String path, Object value); + + /** + * Appends string data to elements by specified key and JSONPath. + * Returns new size of string data. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value data + * @return list of string data sizes + */ + RFuture> stringAppendMultiAsync(K key, String path, Object value); + + /** + * Appends values to array by specified key and JSONPath. + * Returns new size of array. + * + * @param key entry key + * @param path JSON path + * @param values values to append + * @return size of array + */ + RFuture arrayAppendAsync(K key, String path, Object... values); + + /** + * Appends values to arrays by specified key and JSONPath. + * Returns new size of arrays. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param values values to append + * @return list of arrays size + */ + RFuture> arrayAppendMultiAsync(K key, String path, Object... values); + + /** + * Returns index of object in array by specified key and JSONPath. + * -1 means object not found. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @return index in array + */ + RFuture arrayIndexAsync(K key, String path, Object value); + + /** + * Returns index of object in arrays by specified key and JSONPath. + * -1 means object not found. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @return list of index in arrays + */ + RFuture> arrayIndexMultiAsync(K key, String path, Object value); + + /** + * Returns index of object in array by specified key and JSONPath + * in range between start (inclusive) and end (exclusive) indexes. + * -1 means object not found. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @param start start index, inclusive + * @param end end index, exclusive + * @return index in array + */ + RFuture arrayIndexAsync(K key, String path, Object value, long start, long end); + + /** + * Returns index of object in arrays by specified key and JSONPath + * in range between start (inclusive) and end (exclusive) indexes. + * -1 means object not found. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @param start start index, inclusive + * @param end end index, exclusive + * @return list of index in arrays + */ + RFuture> arrayIndexMultiAsync(K key, String path, Object value, long start, long end); + + /** + * Inserts values into array by specified key and JSONPath. + * Values are inserted at defined index. + * + * @param key entry key + * @param path JSON path + * @param index array index at which values are inserted + * @param values values to insert + * @return size of array + */ + RFuture arrayInsertAsync(K key, String path, long index, Object... values); + + /** + * Inserts values into arrays by specified key and JSONPath. + * Values are inserted at defined index. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param index array index at which values are inserted + * @param values values to insert + * @return list of arrays size + */ + RFuture> arrayInsertMultiAsync(K key, String path, long index, Object... values); + + /** + * Returns size of array by specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @return size of array + */ + RFuture arraySizeAsync(K key, String path); + + /** + * Returns size of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @return list of arrays size + */ + RFuture> arraySizeMultiAsync(K key, String path); + + /** + * Polls last element of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return last element + * + * @param the type of object + */ + RFuture arrayPollLastAsync(K key, JsonCodec codec, String path); + + /** + * Polls last element of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return list of last elements + * + * @param the type of object + */ + RFuture> arrayPollLastMultiAsync(K key, JsonCodec codec, String path); + + /** + * Polls first element of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return first element + * + * @param the type of object + */ + RFuture arrayPollFirstAsync(K key, JsonCodec codec, String path); + + /** + * Polls first element of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return list of first elements + * + * @param the type of object + */ + RFuture> arrayPollFirstMultiAsync(K key, JsonCodec codec, String path); + + /** + * Pops element located at index of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @param index array index + * @return element + * + * @param the type of object + */ + RFuture arrayPopAsync(K key, JsonCodec codec, String path, long index); + + /** + * Pops elements located at index of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @param index array index + * @return list of elements + * + * @param the type of object + */ + RFuture> arrayPopMultiAsync(K key, JsonCodec codec, String path, long index); + + /** + * Trims array by specified key and JSONPath in range + * between start (inclusive) and end (inclusive) indexes. + * + * @param key entry key + * @param path JSON path + * @param start start index, inclusive + * @param end end index, inclusive + * @return length of array + */ + RFuture arrayTrimAsync(K key, String path, long start, long end); + + /** + * Trims arrays by specified key and JSONPath in range + * between start (inclusive) and end (inclusive) indexes. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param start start index, inclusive + * @param end end index, inclusive + * @return length of array + */ + RFuture> arrayTrimMultiAsync(K key, String path, long start, long end); + + /** + * Clears value by specified key + * + * @param key entry key + * @return {@code true} if successful, or {@code false} if + * entry doesn't exist + */ + RFuture clearAsync(K key); + + /** + * Clears json containers by specified keys. + * + * @param keys entry keys + * @return number of cleared containers + */ + RFuture clearAsync(Set keys); + + /** + * Clears json container by specified keys and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param path JSON path + * @param keys entry keys + * @return number of cleared containers + */ + RFuture clearAsync(String path, Set keys); + + /** + * Increments the current value specified by key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param delta increment value + * @return the updated value + */ + RFuture incrementAndGetAsync(K key, String path, T delta); + + /** + * Increments the current values specified by key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param delta increment value + * @return list of updated value + */ + RFuture> incrementAndGetMultiAsync(K key, String path, T delta); + + /** + * Merges object into element by the specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param value value to merge + */ + RFuture mergeAsync(K key, String path, Object value); + + /** + * Returns keys amount in JSON container by specified key + * + * @param key entry key + * @return keys amount + */ + RFuture countKeysAsync(K key); + + /** + * Returns keys amount in JSON container specified by key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return keys amount + */ + RFuture countKeysAsync(K key, String path); + + /** + * Returns list of keys amount in JSON containers specified by key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return list of keys amount + */ + RFuture> countKeysMultiAsync(K key, String path); + + /** + * Returns list of keys in JSON container by specified key + * + * @return list of keys + */ + RFuture> getKeysAsync(K key); + + /** + * Returns list of keys in JSON container by specified key and JSONPath + * + * @param path JSON path + * @return list of keys + */ + RFuture> getKeysAsync(K key, String path); + + /** + * Returns list of keys in JSON containers by specified key and JSONPath + * + * @param path JSON path + * @return list of keys + */ + RFuture>> getKeysMultiAsync(K key, String path); + + /** + * Toggle boolean value by specified key and JSONPath + * + * @param path JSON path + * @return new boolean value + */ + RFuture toggleAsync(K key, String path); + + /** + * Toggle boolean values by specified key and JSONPath + * + * @param path JSON path + * @return list of boolean values + */ + RFuture> toggleMultiAsync(K key, String path); + + /** + * Returns type of value + * + * @return type of element + */ + RFuture getTypeAsync(K key); + + /** + * Returns type of element specified by key and JSONPath + * + * @param path JSON path + * @return type of element + */ + RFuture getTypeAsync(K key, String path); + + /** + * Deletes entry by specified key + * + * @param key entry key + * @return {@code true} if successful, or {@code false} if + * entry doesn't exist + */ + RFuture deleteAsync(K key); + + /** + * Deletes JSON elements specified by keys + * + * @param keys entry keys + * @return number of deleted elements + */ + RFuture deleteAsync(Set keys); + + /** + * Deletes JSON elements specified by keys and JSONPath + * + * @param path JSON path + * @param keys entry keys + * @return number of deleted elements + */ + RFuture deleteAsync(String path, Set keys); + + /** + * Returns size of entry in bytes specified by key. + * + * @param key entry key + * @return entry size + */ + RFuture sizeInMemoryAsync(K key); + + /** + * Retrieves value by specified key. + * + * @param key entry key + * @return element + */ + RFuture getAsync(K key); + + /** + * Retrieves values by specified keys. + * + * @param keys entry keys + * @return map with entries where value mapped by key + */ + RFuture> getAsync(Set keys); + + /** + * Retrieves values by specified keys and JSONPath. + * + * @param path JSON path + * @param keys entry keys + * @return map with entries where value mapped by key + */ + RFuture> getAsync(String path, Set keys); + + /** + * Retrieves entry value by specified key and removes it. + * + * @param key entry key + * @return element + */ + RFuture getAndDeleteAsync(K key); + + /** + * Sets value only if entry doesn't exist. + * + * @param key entry key + * @param value value to set + * @return {@code true} if successful, or {@code false} if + * element was already set + */ + RFuture setIfAbsentAsync(K key, V value); + + /** + * Sets value with defined duration only if entry doesn't exist. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return {@code true} if successful, or {@code false} if + * element was already set + */ + RFuture setIfAbsentAsync(K key, V value, Duration duration); + + /** + * Sets value only if entry already exists. + * + * @param key entry key + * @param value value to set + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + RFuture setIfExistsAsync(K key, V value); + + /** + * Sets value with expiration duration only if entry already exists. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + RFuture setIfExistsAsync(K key, V value, Duration duration); + + /** + * Atomically sets the value to the given updated value + * by specified key only if serialized state of the current value equals + * to serialized state of the expected value. + * + * @param key entry key + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ + RFuture compareAndSetAsync(K key, V expect, V update); + + /** + * Retrieves current value by specified key and replaces it with new value. + * + * @param key entry key + * @param newValue value to set + * @return previous value + */ + RFuture getAndSetAsync(K key, V newValue); + + /** + * Retrieves current value by specified key and replaces it + * with value and defines expiration duration. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return previous value + */ + RFuture getAndSetAsync(K key, V value, Duration duration); + + /** + * Retrieves current value by specified key and sets an expiration duration for it. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @param duration of object time to live interval + * @return value + */ + RFuture getAndExpireAsync(K key, Duration duration); + + /** + * Retrieves current value by specified key and sets an expiration date for it. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @param time of exact object expiration moment + * @return value + */ + RFuture getAndExpireAsync(K key, Instant time); + + /** + * Retrieves current value by specified key and clears expiration date set before. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @return value + */ + RFuture getAndClearExpireAsync(K key); + + /** + * Stores value by specified key. + * + * @param key entry key + * @param value value to set + */ + RFuture setAsync(K key, V value); + + /** + * Stores values by specified keys. + * + * @param entries entries to store + */ + RFuture setAsync(Map entries); + + /** + * Stores values by specified keys and JSONPath. + * + * @param path JSONPath + * @param entries entries to store + */ + RFuture setAsync(String path, Map entries); + + /** + * Stores value by specified key with defined expiration duration. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + */ + RFuture setAsync(K key, V value, Duration duration); + + /** + * Stores values by specified keys with defined expiration duration. + * + * @param entries entries to store + * @param duration expiration duration + */ + RFuture setAsync(Map entries, Duration duration); + + /** + * Sets value by specified key and keep existing TTL. + *

+ * Requires Redis 6.0.0 and higher. + * + * @param value value to set + * @return void + */ + RFuture setAndKeepTTLAsync(K key, V value); +// +// /** +// * Adds object event listener +// * +// * @see org.redisson.api.listener.TrackingListener +// * @see org.redisson.api.ExpiredObjectListener +// * @see org.redisson.api.DeletedObjectListener +// * @see org.redisson.api.listener.SetObjectListener +// * +// * @param listener object event listener +// * @return listener id +// */ +// RFuture addListenerAsync(K key, ObjectListener listener); + + /** + * Remaining time to live of map entry associated with a key. + * + * @param key - map key + * @return time in milliseconds + * -2 if the key does not exist. + * -1 if the key exists but has no associated expire. + */ + RFuture remainTimeToLiveAsync(K key); + + /** + * Returns true if this map contains map entry + * mapped by specified key, otherwise false + * + * @param key - map key + * @return true if this map contains map entry + * mapped by specified key, otherwise false + */ + RFuture containsKeyAsync(Object key); + + /** + * Read all keys at once + * + * @return keys + */ + RFuture> readAllKeySetAsync(); + + /** + * Returns entries amount in store + * + * @return entries amount + */ + RFuture sizeAsync(); + + /** + * Adds object event listener + * + * @see org.redisson.api.ExpiredObjectListener + * @see org.redisson.api.DeletedObjectListener + * @see org.redisson.api.listener.SetObjectListener + * + * @param listener - object event listener + * @return listener id + */ + RFuture addListenerAsync(ObjectListener listener); + +} diff --git a/redisson/src/main/java/org/redisson/api/RJsonStoreReactive.java b/redisson/src/main/java/org/redisson/api/RJsonStoreReactive.java new file mode 100644 index 000000000..4183e898c --- /dev/null +++ b/redisson/src/main/java/org/redisson/api/RJsonStoreReactive.java @@ -0,0 +1,893 @@ +/** + * Copyright (c) 2013-2024 Nikita Koksharov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.redisson.api; + +import org.redisson.codec.JsonCodec; +import reactor.core.publisher.Mono; + +import java.time.Duration; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * JSON Store which stores each entry as key and value. Both are POJO objects. + * Value is stored as JSON datatype in Redis. + *

+ * The implementation is available in Redisson PRO only. + * + * @author Nikita Koksharov + * + * @param the type of key + * @param the type of value + * + */ +public interface RJsonStoreReactive extends RExpirableReactive { + + /** + * Gets value by specified key and JSONPath + * + * @param key entry key + * @param codec entry value codec + * @param paths JSON paths + * @param the type of object + * @return entry value + */ + Mono get(K key, JsonCodec codec, String... paths); + + /** + * Sets value by specified key and JSONPath only if previous value is empty. + * + * @param key entry key + * @param path JSON path + * @param value entry value + * @return {@code true} if successful, or {@code false} if + * value was already set + */ + Mono setIfAbsent(K key, String path, Object value); + + /** + * Sets value by specified key and JSONPath only if previous value is non-empty. + * + * @param key entry key + * @param path JSON path + * @param value object + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + Mono setIfExists(K key, String path, Object value); + + /** + * Atomically sets the value to the given updated value + * by specified key and JSONPath, only if serialized state of + * the current value equals to serialized state of the expected value. + * + * @param key entry key + * @param path JSON path + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ + Mono compareAndSet(K key, String path, Object expect, Object update); + + /** + * Retrieves current value stored by specified key and JSONPath then + * replaces it with new value. + * + * @param key entry key + * @param codec entry value codec + * @param path JSON path + * @param newValue value to set + * @return previous value + */ + Mono getAndSet(K key, JsonCodec codec, String path, Object newValue); + + /** + * Stores value by specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param value value to set + */ + Mono set(K key, String path, Object value); + + /** + * Returns size of string data by specified key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return size of string + */ + Mono stringSize(K key, String path); + + /** + * Returns list of string data size by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @return list of string data sizes + */ + Mono> stringSizeMulti(K key, String path); + + /** + * Appends string data to element specified by specified key and JSONPath. + * Returns new size of string data. + * + * @param key entry key + * @param path JSON path + * @param value data + * @return size of string data + */ + Mono stringAppend(K key, String path, Object value); + + /** + * Appends string data to elements specified by specified key and JSONPath. + * Returns new size of string data. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value data + * @return list of string data sizes + */ + Mono> stringAppendMulti(K key, String path, Object value); + + /** + * Appends values to array by specified key and JSONPath. + * Returns new size of array. + * + * @param key entry key + * @param path JSON path + * @param values values to append + * @return size of array + */ + Mono arrayAppend(K key, String path, Object... values); + + /** + * Appends values to arrays by specified key and JSONPath. + * Returns new size of arrays. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param values values to append + * @return list of arrays size + */ + Mono> arrayAppendMulti(K key, String path, Object... values); + + /** + * Returns index of object in array by specified key and JSONPath. + * -1 means object not found. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @return index in array + */ + Mono arrayIndex(K key, String path, Object value); + + /** + * Returns index of object in arrays by specified key and JSONPath. + * -1 means object not found. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @return list of index in arrays + */ + Mono> arrayIndexMulti(K key, String path, Object value); + + /** + * Returns index of object in array by specified key and JSONPath + * in range between start (inclusive) and end (exclusive) indexes. + * -1 means object not found. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @param start start index, inclusive + * @param end end index, exclusive + * @return index in array + */ + Mono arrayIndex(K key, String path, Object value, Mono start, Mono end); + + /** + * Returns index of object in arrays by specified key and JSONPath + * in range between start (inclusive) and end (exclusive) indexes. + * -1 means object not found. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @param start start index, inclusive + * @param end end index, exclusive + * @return list of index in arrays + */ + Mono> arrayIndexMulti(K key, String path, Object value, Mono start, Mono end); + + /** + * Inserts values into array by specified key and JSONPath. + * Values are inserted at defined index. + * + * @param key entry key + * @param path JSON path + * @param index array index at which values are inserted + * @param values values to insert + * @return size of array + */ + Mono arrayInsert(K key, String path, Mono index, Object... values); + + /** + * Inserts values into arrays by specified key and JSONPath. + * Values are inserted at defined index. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param index array index at which values are inserted + * @param values values to insert + * @return list of arrays size + */ + Mono> arrayInsertMulti(K key, String path, Mono index, Object... values); + + /** + * Returns size of array by specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @return size of array + */ + Mono arraySize(K key, String path); + + /** + * Returns size of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @return list of arrays size + */ + Mono> arraySizeMulti(K key, String path); + + /** + * Polls last element of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return last element + * + * @param the type of object + */ + Mono arrayPollLast(K key, JsonCodec codec, String path); + + /** + * Polls last element of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return list of last elements + * + * @param the type of object + */ + Mono> arrayPollLastMulti(K key, JsonCodec codec, String path); + + /** + * Polls first element of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return first element + * + * @param the type of object + */ + Mono arrayPollFirst(K key, JsonCodec codec, String path); + + /** + * Polls first element of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return list of first elements + * + * @param the type of object + */ + Mono> arrayPollFirstMulti(K key, JsonCodec codec, String path); + + /** + * Pops element located at index of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @param index array index + * @return element + * + * @param the type of object + */ + Mono arrayPop(K key, JsonCodec codec, String path, Mono index); + + /** + * Pops elements located at index of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @param index array index + * @return list of elements + * + * @param the type of object + */ + Mono> arrayPopMulti(K key, JsonCodec codec, String path, Mono index); + + /** + * Trims array by specified key and JSONPath in range + * between start (inclusive) and end (inclusive) indexes. + * + * @param key entry key + * @param path JSON path + * @param start start index, inclusive + * @param end end index, inclusive + * @return length of array + */ + Mono arrayTrim(K key, String path, Mono start, Mono end); + + /** + * Trims arrays by specified key and JSONPath in range + * between start (inclusive) and end (inclusive) indexes. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param start start index, inclusive + * @param end end index, inclusive + * @return length of array + */ + Mono> arrayTrimMulti(K key, String path, Mono start, Mono end); + + /** + * Clears value by specified key + * + * @param key entry key + * @return {@code true} if successful, or {@code false} if + * entry doesn't exist + */ + Mono clear(K key); + + /** + * Clears json containers by specified keys. + * + * @param keys entry keys + * @return number of cleared containers + */ + Mono clear(Mono> keys); + + /** + * Clears json container by specified keys and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param path JSON path + * @param keys entry keys + * @return number of cleared containers + */ + Mono clear(String path, Mono> keys); + + /** + * Increments the current value specified by key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param delta increment value + * @return the updated value + */ + Mono incrementAndGet(K key, String path, Mono delta); + + /** + * Increments the current values specified by key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param delta increment value + * @return list of updated value + */ + Mono> incrementAndGetMulti(K key, String path, Mono delta); + + /** + * Merges value into element by the specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param value value to merge + */ + Mono merge(K key, String path, Object value); + + /** + * Returns keys amount in JSON container by specified key + * + * @param key entry key + * @return keys amount + */ + Mono countKeys(K key); + + /** + * Returns keys amount in JSON container specified by key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return keys amount + */ + Mono countKeys(K key, String path); + + /** + * Returns list of keys amount in JSON containers specified by key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return list of keys amount + */ + Mono> countKeysMulti(K key, String path); + + /** + * Returns list of keys in JSON container by specified key + * + * @return list of keys + */ + Mono> getKeys(K key); + + /** + * Returns list of keys in JSON container by specified key and JSONPath + * + * @param path JSON path + * @return list of keys + */ + Mono> getKeys(K key, String path); + + /** + * Returns list of keys in JSON containers by specified key and JSONPath + * + * @param path JSON path + * @return list of keys + */ + List>> getKeysMulti(K key, String path); + + /** + * Toggle Mono value by specified key and JSONPath + * + * @param path JSON path + * @return new Mono value + */ + Mono toggle(K key, String path); + + /** + * Toggle Mono values by specified key and JSONPath + * + * @param path JSON path + * @return list of Mono values + */ + List> toggleMulti(K key, String path); + + /** + * Returns type of value + * + * @return type of element + */ + Mono getType(K key); + + /** + * Returns type of element specified by key and JSONPath + * + * @param path JSON path + * @return type of element + */ + Mono getType(K key, String path); + + /** + * Deletes entry by specified key + * + * @param key entry key + * @return {@code true} if successful, or {@code false} if + * entry doesn't exist + */ + Mono delete(K key); + + /** + * Deletes entries by specified keys + * + * @param keys entry keys + * @return number of deleted elements + */ + Mono delete(Mono> keys); + + /** + * Deletes JSON elements specified by keys and JSONPath + * + * @param path JSON path + * @param keys entry keys + * @return number of deleted elements + */ + Mono delete(String path, Mono> keys); + + /** + * Returns size of entry in bytes specified by key. + * + * @param key entry key + * @return entry size + */ + Mono sizeInMemory(K key); + + /** + * Retrieves value by specified key. + * + * @param key entry key + * @return element + */ + Mono get(K key); + + /** + * Retrieves values by specified keys. + * + * @param keys entry keys + * @return map with entries where value mapped by key + */ + Mono> get(Mono> keys); + + /** + * Retrieves values by specified keys and JSONPath. + * + * @param path JSON path + * @param keys entry keys + * @return map with entries where value mapped by key + */ + Mono> get(String path, Mono> keys); + + /** + * Retrieves entry value by specified key and removes it. + * + * @param key entry key + * @return element + */ + Mono getAndDelete(K key); + + /** + * Sets value only if entry doesn't exist. + * + * @param key entry key + * @param value value to set + * @return {@code true} if successful, or {@code false} if + * element was already set + */ + Mono setIfAbsent(K key, V value); + + /** + * Sets value with defined duration only if entry doesn't exist. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return {@code true} if successful, or {@code false} if + * element was already set + */ + Mono setIfAbsent(K key, V value, Duration duration); + + /** + * Sets value only if entry already exists. + * + * @param key entry key + * @param value value to set + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + Mono setIfExists(K key, V value); + + /** + * Sets value with expiration duration only if entry already exists. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + Mono setIfExists(K key, V value, Duration duration); + + /** + * Atomically sets the value to the given updated value + * by specified key only if serialized state of the current value equals + * to serialized state of the expected value. + * + * @param key entry key + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ + Mono compareAndSet(K key, V expect, V update); + + /** + * Retrieves current value by specified key and replaces it with new value. + * + * @param key entry key + * @param newValue value to set + * @return previous value + */ + Mono getAndSet(K key, V newValue); + + /** + * Retrieves current value by specified key and replaces it + * with value and defines expiration duration. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return previous value + */ + Mono getAndSet(K key, V value, Duration duration); + + /** + * Retrieves current value by specified key and sets an expiration duration for it. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @param duration of object time to live interval + * @return value + */ + Mono getAndExpire(K key, Duration duration); + + /** + * Retrieves current value by specified key and sets an expiration date for it. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @param time of exact object expiration moment + * @return value + */ + Mono getAndExpire(K key, Instant time); + + /** + * Retrieves current value by specified key and clears expiration date set before. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @return value + */ + Mono getAndClearExpire(K key); + + /** + * Stores value by specified key. + * + * @param key entry key + * @param value value to set + */ + Mono set(K key, V value); + + /** + * Stores values by specified keys. + * + * @param entries entries to store + */ + Mono set(Mono> entries); + + /** + * Stores values by specified keys and JSONPath. + * + * @param path JSONPath + * @param entries entries to store + */ + Mono set(String path, Mono> entries); + + /** + * Stores value by specified key with defined expiration duration. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + */ + Mono set(K key, V value, Duration duration); + + /** + * Stores values by specified keys with defined expiration duration. + * + * @param entries entries to store + * @param duration expiration duration + */ + Mono set(Mono> entries, Duration duration); + + /** + * Sets value by specified key and keep existing TTL. + *

+ * Requires Redis 6.0.0 and higher. + * + * @param value value to set + */ + Mono setAndKeepTTL(K key, V value); + + /** + * Adds object event listener + * + * @see ExpiredObjectListener + * @see DeletedObjectListener + * @see org.redisson.api.listener.SetObjectListener + * + * @param listener object event listener + * @return listener id + */ + Mono addListener(ObjectListener listener); + + /** + * Remaining time to live of map entry associated with a key. + * + * @param key - map key + * @return time in milliseconds + * -2 if the key does not exist. + * -1 if the key exists but has no associated expire. + */ + Mono remainTimeToLive(K key); + + /** + * Returns key set of this map. + * Keys are loaded in batch. Batch size is 10. + * + * @see #readAllKeySet() + * + * @return key set + */ + Mono> keySet(); + + /** + * Returns key set of this map. + * Keys are loaded in batch. Batch size is defined by count param. + * + * @see #readAllKeySet() + * + * @param count - size of keys batch + * @return key set + */ + Mono> keySet(int count); + + /** + * Returns key set of this map. + * If pattern is not null then only keys match this pattern are loaded. + * Keys are loaded in batch. Batch size is defined by count param. + *

+ * Use org.redisson.client.codec.StringCodec for Map keys. + *

+ * + * 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 + * + * @see #readAllKeySet() + * + * @param pattern - key pattern + * @param count - size of keys batch + * @return key set + */ + Mono> keySet(String pattern, Mono count); + + /** + * Returns key set of this map. + * If pattern is not null then only keys match this pattern are loaded. + *

+ * Use org.redisson.client.codec.StringCodec for Map keys. + *

+ * + * 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 + * + * @see #readAllKeySet() + * + * @param pattern - key pattern + * @return key set + */ + Mono> keySet(String pattern); + + /** + * Returns true if this map contains map entry + * mapped by specified key, otherwise false + * + * @param key - map key + * @return true if this map contains map entry + * mapped by specified key, otherwise false + */ + Mono containsKey(Object key); + + /** + * Read all keys at once + * + * @return keys + */ + Mono> readAllKeySet(); + + /** + * Returns entries amount in store + * + * @return entries amount + */ + Mono size(); + + /** + * Returns RCountDownLatch instance associated with key + * + * @param key - map key + * @return countdownlatch + */ + RCountDownLatch getCountDownLatch(K key); + + /** + * Returns RPermitExpirableSemaphore instance associated with key + * + * @param key - map key + * @return permitExpirableSemaphore + */ + RPermitExpirableSemaphore getPermitExpirableSemaphore(K key); + + /** + * Returns RSemaphore instance associated with key + * + * @param key - map key + * @return semaphore + */ + RSemaphore getSemaphore(K key); + + /** + * Returns RLock instance associated with key + * + * @param key - map key + * @return fairlock + */ + RLock getFairLock(K key); + + /** + * Returns RReadWriteLock instance associated with key + * + * @param key - map key + * @return readWriteLock + */ + RReadWriteLock getReadWriteLock(K key); + + /** + * Returns RLock instance associated with key + * + * @param key - map key + * @return lock + */ + RLock getLock(K key); + +} diff --git a/redisson/src/main/java/org/redisson/api/RJsonStoreRx.java b/redisson/src/main/java/org/redisson/api/RJsonStoreRx.java new file mode 100644 index 000000000..44a6a5277 --- /dev/null +++ b/redisson/src/main/java/org/redisson/api/RJsonStoreRx.java @@ -0,0 +1,896 @@ +/** + * Copyright (c) 2013-2024 Nikita Koksharov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.redisson.api; + +import io.reactivex.rxjava3.core.Completable; +import io.reactivex.rxjava3.core.Maybe; +import io.reactivex.rxjava3.core.Single; +import org.redisson.codec.JsonCodec; + +import java.time.Duration; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * JSON Store which stores each entry as key and value. Both are POJO objects. + * Value is stored as JSON datatype in Redis. + *

+ * The implementation is available in Redisson PRO only. + * + * @author Nikita Koksharov + * + * @param the type of key + * @param the type of value + * + */ +public interface RJsonStoreRx extends RExpirableRx { + + /** + * Gets value by specified key and JSONPath + * + * @param key entry key + * @param codec entry value codec + * @param paths JSON paths + * @return entry value + * + * @param the type of object + */ + Maybe get(K key, JsonCodec codec, String... paths); + + /** + * Sets value by specified key and JSONPath only if previous value is empty. + * + * @param key entry key + * @param path JSON path + * @param value entry value + * @return {@code true} if successful, or {@code false} if + * value was already set + */ + Single setIfAbsent(K key, String path, Object value); + + /** + * Sets value by specified key and JSONPath only if previous value is non-empty. + * + * @param key entry key + * @param path JSON path + * @param value object + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + Single setIfExists(K key, String path, Object value); + + /** + * Atomically sets the value to the given updated value + * by specified key and JSONPath, only if serialized state of + * the current value equals to serialized state of the expected value. + * + * @param key entry key + * @param path JSON path + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ + Single compareAndSet(K key, String path, Object expect, Object update); + + /** + * Retrieves current value stored by specified key and JSONPath then + * replaces it with new value. + * + * @param key entry key + * @param codec entry value codec + * @param path JSON path + * @param newValue value to set + * @return previous value + */ + Maybe getAndSet(K key, JsonCodec codec, String path, Object newValue); + + /** + * Stores value by specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param value value to set + */ + Completable set(K key, String path, Object value); + + /** + * Returns size of string data by specified key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return size of string + */ + Maybe stringSize(K key, String path); + + /** + * Returns list of string data size by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @return list of string data sizes + */ + Single> stringSizeMulti(K key, String path); + + /** + * Appends string data to element specified by specified key and JSONPath. + * Returns new size of string data. + * + * @param key entry key + * @param path JSON path + * @param value data + * @return size of string data + */ + Single stringAppend(K key, String path, Object value); + + /** + * Appends string data to elements specified by specified key and JSONPath. + * Returns new size of string data. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value data + * @return list of string data sizes + */ + Single> stringAppendMulti(K key, String path, Object value); + + /** + * Appends values to array by specified key and JSONPath. + * Returns new size of array. + * + * @param key entry key + * @param path JSON path + * @param values values to append + * @return size of array + */ + Single arrayAppend(K key, String path, Object... values); + + /** + * Appends values to arrays by specified key and JSONPath. + * Returns new size of arrays. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param values values to append + * @return list of arrays size + */ + Single> arrayAppendMulti(K key, String path, Object... values); + + /** + * Returns index of object in array by specified key and JSONPath. + * -1 means object not found. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @return index in array + */ + Single arrayIndex(K key, String path, Object value); + + /** + * Returns index of object in arrays by specified key and JSONPath. + * -1 means object not found. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @return list of index in arrays + */ + Single> arrayIndexMulti(K key, String path, Object value); + + /** + * Returns index of object in array by specified key and JSONPath + * in range between start (inclusive) and end (exclusive) indexes. + * -1 means object not found. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @param start start index, inclusive + * @param end end index, exclusive + * @return index in array + */ + Single arrayIndex(K key, String path, Object value, Single start, Single end); + + /** + * Returns index of object in arrays by specified key and JSONPath + * in range between start (inclusive) and end (exclusive) indexes. + * -1 means object not found. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param value value to search + * @param start start index, inclusive + * @param end end index, exclusive + * @return list of index in arrays + */ + Single> arrayIndexMulti(K key, String path, Object value, Single start, Single end); + + /** + * Inserts values into array by specified key and JSONPath. + * Values are inserted at defined index. + * + * @param key entry key + * @param path JSON path + * @param index array index at which values are inserted + * @param values values to insert + * @return size of array + */ + Single arrayInsert(K key, String path, Single index, Object... values); + + /** + * Inserts values into arrays by specified key and JSONPath. + * Values are inserted at defined index. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param index array index at which values are inserted + * @param values values to insert + * @return list of arrays size + */ + Single> arrayInsertMulti(K key, String path, Single index, Object... values); + + /** + * Returns size of array by specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @return size of array + */ + Single arraySize(K key, String path); + + /** + * Returns size of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @return list of arrays size + */ + Single> arraySizeMulti(K key, String path); + + /** + * Polls last element of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return last element + * + * @param the type of object + */ + Maybe arrayPollLast(K key, JsonCodec codec, String path); + + /** + * Polls last element of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return list of last elements + * + * @param the type of object + */ + Single> arrayPollLastMulti(K key, JsonCodec codec, String path); + + /** + * Polls first element of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return first element + * + * @param the type of object + */ + Maybe arrayPollFirst(K key, JsonCodec codec, String path); + + /** + * Polls first element of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @return list of first elements + * + * @param the type of object + */ + Single> arrayPollFirstMulti(K key, JsonCodec codec, String path); + + /** + * Pops element located at index of array by specified key and JSONPath. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @param index array index + * @return element + * + * @param the type of object + */ + Maybe arrayPop(K key, JsonCodec codec, String path, Single index); + + /** + * Pops elements located at index of arrays by specified key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param codec object codec + * @param path JSON path + * @param index array index + * @return list of elements + * + * @param the type of object + */ + Single> arrayPopMulti(K key, JsonCodec codec, String path, Single index); + + /** + * Trims array by specified key and JSONPath in range + * between start (inclusive) and end (inclusive) indexes. + * + * @param key entry key + * @param path JSON path + * @param start start index, inclusive + * @param end end index, inclusive + * @return length of array + */ + Single arrayTrim(K key, String path, Single start, Single end); + + /** + * Trims arrays by specified key and JSONPath in range + * between start (inclusive) and end (inclusive) indexes. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param start start index, inclusive + * @param end end index, inclusive + * @return length of array + */ + Single> arrayTrimMulti(K key, String path, Single start, Single end); + + /** + * Clears value by specified key + * + * @param key entry key + * @return {@code true} if successful, or {@code false} if + * entry doesn't exist + */ + Single clear(K key); + + /** + * Clears json containers by specified keys. + * + * @param keys entry keys + * @return number of cleared containers + */ + Single clear(Set keys); + + /** + * Clears json container by specified keys and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param path JSON path + * @param keys entry keys + * @return number of cleared containers + */ + Single clear(String path, Set keys); + + /** + * Increments the current value specified by key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param delta increment value + * @return the updated value + */ + Maybe incrementAndGet(K key, String path, Maybe delta); + + /** + * Increments the current values specified by key and JSONPath. + * Compatible only with enhanced syntax starting with '$' character. + * + * @param key entry key + * @param path JSON path + * @param delta increment value + * @return list of updated value + */ + List incrementAndGetMulti(K key, String path, Maybe delta); + + /** + * Merges value into element by the specified key and JSONPath. + * + * @param key entry key + * @param path JSON path + * @param value value to merge + */ + Completable merge(K key, String path, Object value); + + /** + * Returns keys amount in JSON container by specified key + * + * @param key entry key + * @return keys amount + */ + Maybe countKeys(K key); + + /** + * Returns keys amount in JSON container specified by key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return keys amount + */ + Maybe countKeys(K key, String path); + + /** + * Returns list of keys amount in JSON containers specified by key and JSONPath + * + * @param key entry key + * @param path JSON path + * @return list of keys amount + */ + Single> countKeysMulti(K key, String path); + + /** + * Returns list of keys in JSON container by specified key + * + * @return list of keys + */ + Single> getKeys(K key); + + /** + * Returns list of keys in JSON container by specified key and JSONPath + * + * @param path JSON path + * @return list of keys + */ + Single> getKeys(K key, String path); + + /** + * Returns list of keys in JSON containers by specified key and JSONPath + * + * @param path JSON path + * @return list of keys + */ + Single>> getKeysMulti(K key, String path); + + /** + * Toggle Single value by specified key and JSONPath + * + * @param path JSON path + * @return new Single value + */ + Single toggle(K key, String path); + + /** + * Toggle Single values by specified key and JSONPath + * + * @param path JSON path + * @return list of Single values + */ + Single> toggleMulti(K key, String path); + + /** + * Returns type of value + * + * @return type of element + */ + Single getType(K key); + + /** + * Returns type of element specified by key and JSONPath + * + * @param path JSON path + * @return type of element + */ + Single getType(K key, String path); + + /** + * Deletes entry by specified key + * + * @param key entry key + * @return {@code true} if successful, or {@code false} if + * entry doesn't exist + */ + Single delete(K key); + + /** + * Deletes entries by specified keys + * + * @param keys entry keys + * @return number of deleted elements + */ + Single delete(Set keys); + + /** + * Deletes JSON elements specified by keys and JSONPath + * + * @param path JSON path + * @param keys entry keys + * @return number of deleted elements + */ + Single delete(String path, Set keys); + + /** + * Returns size of entry in bytes specified by key. + * + * @param key entry key + * @return entry size + */ + Single sizeInMemory(K key); + + /** + * Retrieves value by specified key. + * + * @param key entry key + * @return element + */ + Maybe get(K key); + + /** + * Retrieves values by specified keys. + * + * @param keys entry keys + * @return map with entries where value mapped by key + */ + Single> get(Set keys); + + /** + * Retrieves values by specified keys and JSONPath. + * + * @param path JSON path + * @param keys entry keys + * @return map with entries where value mapped by key + */ + Single> get(String path, Set keys); + + /** + * Retrieves entry value by specified key and removes it. + * + * @param key entry key + * @return element + */ + Maybe getAndDelete(K key); + + /** + * Sets value only if entry doesn't exist. + * + * @param key entry key + * @param value value to set + * @return {@code true} if successful, or {@code false} if + * element was already set + */ + Single setIfAbsent(K key, V value); + + /** + * Sets value with defined duration only if entry doesn't exist. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return {@code true} if successful, or {@code false} if + * element was already set + */ + Single setIfAbsent(K key, V value, Duration duration); + + /** + * Sets value only if entry already exists. + * + * @param key entry key + * @param value value to set + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + Single setIfExists(K key, V value); + + /** + * Sets value with expiration duration only if entry already exists. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return {@code true} if successful, or {@code false} if + * element wasn't set + */ + Single setIfExists(K key, V value, Duration duration); + + /** + * Atomically sets the value to the given updated value + * by specified key only if serialized state of the current value equals + * to serialized state of the expected value. + * + * @param key entry key + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ + Single compareAndSet(K key, V expect, V update); + + /** + * Retrieves current value by specified key and replaces it with new value. + * + * @param key entry key + * @param newValue value to set + * @return previous value + */ + Maybe getAndSet(K key, V newValue); + + /** + * Retrieves current value by specified key and replaces it + * with value and defines expiration duration. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + * @return previous value + */ + Maybe getAndSet(K key, V value, Duration duration); + + /** + * Retrieves current value by specified key and sets an expiration duration for it. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @param duration of object time to live interval + * @return value + */ + Maybe getAndExpire(K key, Duration duration); + + /** + * Retrieves current value by specified key and sets an expiration date for it. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @param time of exact object expiration moment + * @return value + */ + Maybe getAndExpire(K key, Instant time); + + /** + * Retrieves current value by specified key and clears expiration date set before. + *

+ * Requires Redis 6.2.0 and higher. + * + * @param key entry key + * @return value + */ + Maybe getAndClearExpire(K key); + + /** + * Stores value by specified key. + * + * @param key entry key + * @param value value to set + */ + Completable set(K key, V value); + + /** + * Stores values by specified keys. + * + * @param entries entries to store + */ + Completable set(Map entries); + + /** + * Stores values by specified keys and JSONPath. + * + * @param path JSONPath + * @param entries entries to store + */ + Completable set(String path, Map entries); + + /** + * Stores value by specified key with defined expiration duration. + * + * @param key entry key + * @param value value to set + * @param duration expiration duration + */ + Completable set(K key, V value, Duration duration); + + /** + * Stores values by specified keys with defined expiration duration. + * + * @param entries entries to store + * @param duration expiration duration + */ + Completable set(Map entries, Duration duration); + + /** + * Sets value by specified key and keep existing TTL. + *

+ * Requires Redis 6.0.0 and higher. + * + * @param value value to set + */ + Completable setAndKeepTTL(K key, V value); + + /** + * Adds object event listener + * + * @see ExpiredObjectListener + * @see DeletedObjectListener + * @see org.redisson.api.listener.SetObjectListener + * + * @param listener object event listener + * @return listener id + */ + Single addListener(ObjectListener listener); + + /** + * Remaining time to live of map entry associated with a key. + * + * @param key - map key + * @return time in milliseconds + * -2 if the key does not exist. + * -1 if the key exists but has no associated expire. + */ + Single remainTimeToLive(K key); + + /** + * Returns key set of this map. + * Keys are loaded in batch. Batch size is 10. + * + * @see #readAllKeySet() + * + * @return key set + */ + Set keySet(); + + /** + * Returns key set of this map. + * Keys are loaded in batch. Batch size is defined by count param. + * + * @see #readAllKeySet() + * + * @param count - size of keys batch + * @return key set + */ + Set keySet(int count); + + /** + * Returns key set of this map. + * If pattern is not null then only keys match this pattern are loaded. + * Keys are loaded in batch. Batch size is defined by count param. + *

+ * Use org.redisson.client.codec.StringCodec for Map keys. + *

+ * + * 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 + * + * @see #readAllKeySet() + * + * @param pattern - key pattern + * @param count - size of keys batch + * @return key set + */ + Set keySet(String pattern, int count); + + /** + * Returns key set of this map. + * If pattern is not null then only keys match this pattern are loaded. + *

+ * Use org.redisson.client.codec.StringCodec for Map keys. + *

+ * + * 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 + * + * @see #readAllKeySet() + * + * @param pattern - key pattern + * @return key set + */ + Set keySet(String pattern); + + /** + * Returns true if this map contains map entry + * mapped by specified key, otherwise false + * + * @param key - map key + * @return true if this map contains map entry + * mapped by specified key, otherwise false + */ + Single containsKey(Object key); + + /** + * Read all keys at once + * + * @return keys + */ + Set readAllKeySet(); + + /** + * Returns entries amount in store + * + * @return entries amount + */ + Single size(); + + /** + * Returns RCountDownLatch instance associated with key + * + * @param key - map key + * @return countdownlatch + */ + RCountDownLatch getCountDownLatch(K key); + + /** + * Returns RPermitExpirableSemaphore instance associated with key + * + * @param key - map key + * @return permitExpirableSemaphore + */ + RPermitExpirableSemaphore getPermitExpirableSemaphore(K key); + + /** + * Returns RSemaphore instance associated with key + * + * @param key - map key + * @return semaphore + */ + RSemaphore getSemaphore(K key); + + /** + * Returns RLock instance associated with key + * + * @param key - map key + * @return fairlock + */ + RLock getFairLock(K key); + + /** + * Returns RReadWriteLock instance associated with key + * + * @param key - map key + * @return readWriteLock + */ + RReadWriteLock getReadWriteLock(K key); + + /** + * Returns RLock instance associated with key + * + * @param key - map key + * @return lock + */ + RLock getLock(K key); + +}