CacheSource增加delex方法

This commit is contained in:
redkale
2024-01-14 20:47:31 +08:00
parent ef802bb1ce
commit 2992250745
4 changed files with 81 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
/*
*
*/
package org.redkale.annotation;
import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.*;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.Target;
/**
*
* @since Common Annotations 1.0
*
* @since 2.8.0
*/
@Documented
@Retention(RUNTIME)
@Target(METHOD)
public @interface PostConstruct {
}

View File

@@ -0,0 +1,21 @@
/*
*
*/
package org.redkale.annotation;
import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
*
*
* @since Common Annotations 1.0
*
* @since 2.8.0
*/
@Documented
@Retention(RUNTIME)
@Target(METHOD)
public @interface PreDestroy {
}

View File

@@ -704,6 +704,38 @@ public final class CacheMemorySource extends AbstractCacheSource {
return supplyFuture(() -> del(keys));
}
@Override
public long delex(String key, String expectedValue) {
if (key == null) {
return 0L;
}
containerLock.lock();
try {
CacheEntry entry = find(key);
if (entry == null) {
return 0;
} else {
entry.lock();
try {
if (Objects.equals(expectedValue, entry.getObjectValue(convert, String.class))) {
return container.remove(key) == null ? 0 : 1;
} else {
return 0;
}
} finally {
entry.unlock();
}
}
} finally {
containerLock.unlock();
}
}
@Override
public CompletableFuture<Long> delexAsync(String key, String expectedValue) {
return supplyFuture(() -> delex(key, expectedValue));
}
@Override
public long incr(final String key) {
return incrby(key, 1);

View File

@@ -25,7 +25,6 @@ import org.redkale.util.*;
* Long统一用setLong、getLong、incr等系列方法。<br>
* 其他则供自定义数据类型使用。
*
* param V value的类型 移除 @2.4.0
* <p>
* 详情见: https://redkale.org
*
@@ -369,6 +368,10 @@ public interface CacheSource extends Resourcable {
return delAsync(keys).join();
}
default long delex(String key, String expectedValue) {
return delexAsync(key, expectedValue).join();
}
default boolean exists(String key) {
return existsAsync(key).join();
}
@@ -1301,6 +1304,8 @@ public interface CacheSource extends Resourcable {
}
//------------------------ 键 Keys ------------------------
public CompletableFuture<Long> delexAsync(String key, String expectedValue);
public CompletableFuture<Long> delAsync(String... keys);
public CompletableFuture<Boolean> existsAsync(String key);