All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.redisson.api.RMapAsync Maven / Gradle / Ivy

/**
 * Copyright 2018 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 java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;

import org.redisson.api.map.MapLoader;
import org.redisson.api.map.MapWriter;

import java.util.Set;

/**
 * Distributed async implementation of {@link Map}.
 * 
 * This map doesn't allow to store null as key or value.
 *
 * @author Nikita Koksharov
 *
 * @param  key
 * @param  value
 */
public interface RMapAsync extends RExpirableAsync {

    /**
     * Loads all map entries to this Redis map using {@link org.redisson.api.map.MapLoader}.
     * 
     * @param replaceExistingValues - true if existed values should be replaced, false otherwise.  
     * @param parallelism - parallelism level, used to increase speed of process execution
     * @return void
     */
    RFuture loadAllAsync(boolean replaceExistingValues, int parallelism);
    
    /**
     * Loads map entries using {@link org.redisson.api.map.MapLoader} whose keys are listed in defined keys parameter.
     * 
     * @param keys - map keys
     * @param replaceExistingValues - true if existed values should be replaced, false otherwise.
     * @param parallelism - parallelism level, used to increase speed of process execution
     * @return void
     */
    RFuture loadAllAsync(Set keys, boolean replaceExistingValues, int parallelism);
    
    /**
     * Returns size of value mapped by key in bytes
     * 
     * @param key - map key
     * @return size of value
     */
    RFuture valueSizeAsync(K key);
    
    /**
     * Gets a map slice contained the mappings with defined keys
     * by one operation.
     * 

* If map doesn't contain value/values for specified key/keys and {@link MapLoader} is defined * then value/values will be loaded in read-through mode. *

* The returned map is NOT backed by the original map. * * @param keys - map keys * @return Map slice */ RFuture> getAllAsync(Set keys); /** * Associates the specified value with the specified key * in batch. *

* If {@link MapWriter} is defined then new map entries are stored in write-through mode. * * @param map mappings to be stored in this map * @return void */ RFuture putAllAsync(Map map); /** * Associates the specified value with the specified key * in batch. Batch inserted by chunks limited by batchSize amount * to avoid OOM and/or Redis response timeout error for map with big size. *

* If {@link MapWriter} is defined then new map entries are stored in write-through mode. * * @param map mappings to be stored in this map * @param batchSize - map chunk size * @return void */ RFuture putAllAsync(Map map, int batchSize); /** * Atomically adds the given delta to the current value * by mapped key. * * Works only for numeric values! * * @param key - map key * @param value - delta the value to add * @return the updated value */ RFuture addAndGetAsync(K key, Number value); RFuture containsValueAsync(Object value); RFuture containsKeyAsync(Object key); /** * Returns size of this map * * @return size */ RFuture sizeAsync(); /** * Removes keys from map by one operation in async manner. *

* Works faster than {@link RMap#removeAsync(Object, Object)} but doesn't return * the value associated with key. *

* If {@link MapWriter} is defined then keysare deleted in write-through mode. * * @param keys - map keys * @return the number of keys that were removed from the hash, not including specified but non existing keys */ RFuture fastRemoveAsync(K ... keys); /** * Associates the specified value with the specified key * in async manner. *

* Works faster than {@link RMap#putAsync(Object, Object)} but not returning * the previous value associated with key *

* If {@link MapWriter} is defined then new map entry is stored in write-through mode. * * @param key - map key * @param value - map value * @return true if key is a new one in the hash and value was set. * false if key already exists in the hash and the value was updated. */ RFuture fastPutAsync(K key, V value); /** * Replaces previous value with a new value associated with the key. *

* Works faster than {@link RMap#replaceAsync(Object, Object)} but not returning * the previous value associated with key *

* If {@link MapWriter} is defined then new map entry is stored in write-through mode. * * @param key - map key * @param value - map value * @return true if key exists and value was updated. * false if key doesn't exists and value wasn't updated. */ RFuture fastReplaceAsync(K key, V value); /** * Associates the specified value with the specified key * only if there is no any association with specifiedkey. *

* Works faster than {@link RMap#putIfAbsentAsync(Object, Object)} but not returning * the previous value associated with key *

* If {@link MapWriter} is defined then new map entry is stored in write-through mode. * * @param key - map key * @param value - map value * @return true if key is a new one in the hash and value was set. * false if key already exists in the hash and change hasn't been made. */ RFuture fastPutIfAbsentAsync(K key, V value); /** * Read all keys at once * * @return keys */ RFuture> readAllKeySetAsync(); /** * Read all values at once * * @return values */ RFuture> readAllValuesAsync(); /** * Read all map entries at once * * @return entries */ RFuture>> readAllEntrySetAsync(); /** * Read all map as local instance at once * * @return map */ RFuture> readAllMapAsync(); /** * Returns the value to which the specified key is mapped, * or {@code null} if this map contains no mapping for the key. *

* If map doesn't contain value for specified key and {@link MapLoader} is defined * then value will be loaded in read-through mode. * * @param key the key whose associated value is to be returned * @return the value to which the specified key is mapped, or * {@code null} if this map contains no mapping for the key */ RFuture getAsync(K key); /** * Associates the specified value with the specified key * in async manner. *

* If {@link MapWriter} is defined then new map entry is stored in write-through mode. * * @param key - map key * @param value - map value * @return previous associated value */ RFuture putAsync(K key, V value); /** * Removes key from map and returns associated value in async manner. *

* If {@link MapWriter} is defined then keyis deleted in write-through mode. * * @param key - map key * @return deleted value or null if there wasn't any association */ RFuture removeAsync(K key); /** * Replaces previous value with a new value associated with the key. * If there wasn't any association before then method returns null. *

* If {@link MapWriter} is defined then new valueis written in write-through mode. * * @param key - map key * @param value - map value * @return previous associated value * or null if there wasn't any association and change hasn't been made */ RFuture replaceAsync(K key, V value); /** * Replaces previous oldValue with a newValue associated with the key. * If previous value doesn't exist or equal to oldValue then method returns false. *

* If {@link MapWriter} is defined then newValueis written in write-through mode. * * @param key - map key * @param oldValue - map old value * @param newValue - map new value * @return true if value has been replaced otherwise false. */ RFuture replaceAsync(K key, V oldValue, V newValue); /** * Removes key from map only if it associated with value. *

* If {@link MapWriter} is defined then keyis deleted in write-through mode. * * @param key - map key * @param value - map value * @return true if map entry has been replaced otherwise false. */ RFuture removeAsync(Object key, Object value); /** * Associates the specified value with the specified key * only if there is no any association with specifiedkey. *

* If {@link MapWriter} is defined then new map entry is stored in write-through mode. * * @param key - map key * @param value - map value * @return null if key is a new one in the hash and value was set. * Previous value if key already exists in the hash and change hasn't been made. */ RFuture putIfAbsentAsync(K key, V value); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy