/**
* 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.api.map.MapWriter;
import java.time.Duration;
import java.util.Map;
import java.util.Set;
/**
* Map-based cache with ability to set TTL per entry.
* Uses Redis native commands for entry expiration and not a scheduled eviction task.
*
* Requires Redis 7.4.0 and higher.
*
* @author Nikita Koksharov
*
* @param key
* @param value
*/
public interface RMapCacheNativeAsync extends RMapAsync {
/**
* Stores value mapped by key with specified time to live.
* Entry expires after specified time to live.
*
* If the map previously contained a mapping for
* the key, the old value is replaced by the specified value.
*
* @param key - map key
* @param value - map value
* @param ttl - time to live for key\value entry.
* If 0
then stores infinitely.
* @return previous associated value
*/
RFuture putAsync(K key, V value, Duration ttl);
/**
* Stores value mapped by key with specified time to live.
* Entry expires after specified time to live.
*
* If the map previously contained a mapping for
* the key, the old value is replaced by the specified value.
*
* Works faster than usual {@link #putAsync(Object, Object, Duration)}
* as it not returns previous value.
*
* @param key - map key
* @param value - map value
* @param ttl - time to live for key\value entry.
* If 0
then stores infinitely.
*
* @return true
if key is a new key 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, Duration ttl);
/**
* If the specified key is not already associated
* with a value, associate it with the given value.
*
* Stores value mapped by key with specified time to live.
* Entry expires after specified time to live.
*
* @param key - map key
* @param value - map value
* @param ttl - time to live for key\value entry.
* If 0
then stores infinitely.
*
* @return current associated value
*/
RFuture putIfAbsentAsync(K key, V value, Duration ttl);
/**
* If the specified key is not already associated
* with a value, associate it with the given value.
*
* Stores value mapped by key with specified time to live.
* Entry expires after specified time to live.
*
* Works faster than usual {@link #putIfAbsentAsync(Object, Object, Duration)}
* as it not returns previous value.
*
* @param key - map key
* @param value - map value
* @param ttl - time to live for key\value entry.
* If 0
then stores infinitely.
*
* @return true
if key is a new key in the hash and value was set.
* false
if key already exists in the hash
*/
RFuture fastPutIfAbsentAsync(K key, V value, Duration ttl);
/**
* 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);
RFuture