CacheScoredValue
This commit is contained in:
@@ -1585,7 +1585,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
|||||||
return runFuture(() -> {
|
return runFuture(() -> {
|
||||||
List<Object> list = new ArrayList<>();
|
List<Object> list = new ArrayList<>();
|
||||||
for (CacheScoredValue v : values) {
|
for (CacheScoredValue v : values) {
|
||||||
list.add(new CacheScoredValue.NumberScoredValue(v));
|
list.add(new CacheScoredValue(v));
|
||||||
}
|
}
|
||||||
CacheEntry entry = find(key, CacheEntryType.ZSET);
|
CacheEntry entry = find(key, CacheEntryType.ZSET);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
@@ -1627,10 +1627,10 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
|||||||
}
|
}
|
||||||
entry.lock();
|
entry.lock();
|
||||||
try {
|
try {
|
||||||
Set<CacheScoredValue.NumberScoredValue> sets = entry.setValue;
|
Set<CacheScoredValue> sets = entry.setValue;
|
||||||
CacheScoredValue.NumberScoredValue old = sets.stream().filter(v -> Objects.equals(v.getValue(), value.getValue())).findAny().orElse(null);
|
CacheScoredValue old = sets.stream().filter(v -> Objects.equals(v.getValue(), value.getValue())).findAny().orElse(null);
|
||||||
if (old == null) {
|
if (old == null) {
|
||||||
sets.add(new CacheScoredValue.NumberScoredValue(value.getScore().doubleValue(), value.getValue()));
|
sets.add(new CacheScoredValue(value.getScore().doubleValue(), value.getValue()));
|
||||||
return (T) value.getScore();
|
return (T) value.getScore();
|
||||||
} else {
|
} else {
|
||||||
Number ic = value.getScore();
|
Number ic = value.getScore();
|
||||||
@@ -1673,10 +1673,10 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
|||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<CacheScoredValue.NumberScoredValue> list = new ArrayList<>(entry.setValue);
|
List<CacheScoredValue> list = new ArrayList<>(entry.setValue);
|
||||||
Collections.sort(list);
|
Collections.sort(list);
|
||||||
long c = 0;
|
long c = 0;
|
||||||
for (CacheScoredValue.NumberScoredValue v : list) {
|
for (CacheScoredValue v : list) {
|
||||||
if (Objects.equals(v.getValue(), member)) {
|
if (Objects.equals(v.getValue(), member)) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -1693,10 +1693,10 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
|||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<CacheScoredValue.NumberScoredValue> list = new ArrayList<>(entry.setValue);
|
List<CacheScoredValue> list = new ArrayList<>(entry.setValue);
|
||||||
Collections.sort(list, Collections.reverseOrder());
|
Collections.sort(list, Collections.reverseOrder());
|
||||||
long c = 0;
|
long c = 0;
|
||||||
for (CacheScoredValue.NumberScoredValue v : list) {
|
for (CacheScoredValue v : list) {
|
||||||
if (Objects.equals(v.getValue(), member)) {
|
if (Objects.equals(v.getValue(), member)) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -1727,13 +1727,13 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<CacheScoredValue.NumberScoredValue>> zscanAsync(String key, Type scoreType, AtomicLong cursor, int limit, String pattern) {
|
public CompletableFuture<List<CacheScoredValue>> zscanAsync(String key, Type scoreType, AtomicLong cursor, int limit, String pattern) {
|
||||||
return supplyFuture(() -> {
|
return supplyFuture(() -> {
|
||||||
CacheEntry entry = find(key, CacheEntryType.ZSET);
|
CacheEntry entry = find(key, CacheEntryType.ZSET);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return new ArrayList();
|
return new ArrayList();
|
||||||
}
|
}
|
||||||
Set<CacheScoredValue.NumberScoredValue> sets = entry.setValue;
|
Set<CacheScoredValue> sets = entry.setValue;
|
||||||
if (Utility.isEmpty(pattern)) {
|
if (Utility.isEmpty(pattern)) {
|
||||||
return sets.stream().collect(Collectors.toList());
|
return sets.stream().collect(Collectors.toList());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -19,84 +19,77 @@ import org.redkale.convert.ConvertColumn;
|
|||||||
*
|
*
|
||||||
* @since 2.8.0
|
* @since 2.8.0
|
||||||
*/
|
*/
|
||||||
public interface CacheScoredValue<S extends Number> extends Serializable, Comparable<CacheScoredValue> {
|
public class CacheScoredValue implements Serializable, Comparable<CacheScoredValue> {
|
||||||
|
|
||||||
public S getScore();
|
@ConvertColumn(index = 1)
|
||||||
|
private Number score;
|
||||||
|
|
||||||
public String getValue();
|
@ConvertColumn(index = 2)
|
||||||
|
private String value;
|
||||||
|
|
||||||
public static NumberScoredValue create(Number score, String value) {
|
public CacheScoredValue() {
|
||||||
return new NumberScoredValue(score, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class NumberScoredValue implements CacheScoredValue<Number> {
|
protected CacheScoredValue(Number score, String value) {
|
||||||
|
Objects.requireNonNull(score);
|
||||||
|
Objects.requireNonNull(value);
|
||||||
|
this.score = score;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
@ConvertColumn(index = 1)
|
protected CacheScoredValue(CacheScoredValue scoredValue) {
|
||||||
private Number score;
|
this.score = scoredValue.getScore();
|
||||||
|
this.value = scoredValue.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
@ConvertColumn(index = 2)
|
public static CacheScoredValue create(Number score, String value) {
|
||||||
private String value;
|
return new CacheScoredValue(score, value);
|
||||||
|
}
|
||||||
|
|
||||||
public NumberScoredValue(Number score, String value) {
|
public Number getScore() {
|
||||||
Objects.requireNonNull(score);
|
return score;
|
||||||
Objects.requireNonNull(value);
|
}
|
||||||
this.score = score;
|
|
||||||
this.value = value;
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScore(Number score) {
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(CacheScoredValue o) {
|
||||||
|
return ((Comparable) this.score).compareTo((Number) o.getScore());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
if (obj == null) {
|
||||||
public NumberScoredValue(CacheScoredValue scoredValue) {
|
return false;
|
||||||
this.score = scoredValue.getScore();
|
|
||||||
this.value = scoredValue.getValue();
|
|
||||||
}
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
@Override
|
return false;
|
||||||
public Number getScore() {
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScore(Number score) {
|
|
||||||
this.score = score;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(CacheScoredValue o) {
|
|
||||||
return ((Comparable) this.score).compareTo((Number) o.getScore());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(this.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (getClass() != obj.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final NumberScoredValue other = (NumberScoredValue) obj;
|
|
||||||
return Objects.equals(this.value, other.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "{score:" + score + ", value:" + value + "}";
|
|
||||||
}
|
}
|
||||||
|
final CacheScoredValue other = (CacheScoredValue) obj;
|
||||||
|
return Objects.equals(this.value, other.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{score:" + score + ", value:" + value + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -990,35 +990,35 @@ public interface CacheSource extends Resourcable {
|
|||||||
return zrangeAsync(key, start, stop).join();
|
return zrangeAsync(key, start, stop).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<CacheScoredValue.NumberScoredValue> zscan(String key, Type scoreType, AtomicLong cursor, int limit, String pattern) {
|
default List<CacheScoredValue> zscan(String key, Type scoreType, AtomicLong cursor, int limit, String pattern) {
|
||||||
return zscanAsync(key, scoreType, cursor, limit, pattern).join();
|
return zscanAsync(key, scoreType, cursor, limit, pattern).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<CacheScoredValue.NumberScoredValue> zscanInteger(String key, AtomicLong cursor, int limit, String pattern) {
|
default List<CacheScoredValue> zscanInteger(String key, AtomicLong cursor, int limit, String pattern) {
|
||||||
return zscan(key, Integer.class, cursor, limit, pattern);
|
return zscan(key, Integer.class, cursor, limit, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<CacheScoredValue.NumberScoredValue> zscanLong(String key, AtomicLong cursor, int limit, String pattern) {
|
default List<CacheScoredValue> zscanLong(String key, AtomicLong cursor, int limit, String pattern) {
|
||||||
return zscan(key, Long.class, cursor, limit, pattern);
|
return zscan(key, Long.class, cursor, limit, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<CacheScoredValue.NumberScoredValue> zscanDouble(String key, AtomicLong cursor, int limit, String pattern) {
|
default List<CacheScoredValue> zscanDouble(String key, AtomicLong cursor, int limit, String pattern) {
|
||||||
return zscan(key, Double.class, cursor, limit, pattern);
|
return zscan(key, Double.class, cursor, limit, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<CacheScoredValue.NumberScoredValue> zscan(String key, Type scoreType, AtomicLong cursor, int limit) {
|
default List<CacheScoredValue> zscan(String key, Type scoreType, AtomicLong cursor, int limit) {
|
||||||
return zscan(key, scoreType, cursor, limit, null);
|
return zscan(key, scoreType, cursor, limit, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<CacheScoredValue.NumberScoredValue> zscanInteger(String key, AtomicLong cursor, int limit) {
|
default List<CacheScoredValue> zscanInteger(String key, AtomicLong cursor, int limit) {
|
||||||
return zscan(key, Integer.class, cursor, limit, null);
|
return zscan(key, Integer.class, cursor, limit, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<CacheScoredValue.NumberScoredValue> zscanLong(String key, AtomicLong cursor, int limit) {
|
default List<CacheScoredValue> zscanLong(String key, AtomicLong cursor, int limit) {
|
||||||
return zscan(key, Long.class, cursor, limit, null);
|
return zscan(key, Long.class, cursor, limit, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default List<CacheScoredValue.NumberScoredValue> zscanDouble(String key, AtomicLong cursor, int limit) {
|
default List<CacheScoredValue> zscanDouble(String key, AtomicLong cursor, int limit) {
|
||||||
return zscan(key, Double.class, cursor, limit, null);
|
return zscan(key, Double.class, cursor, limit, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1735,33 +1735,33 @@ public interface CacheSource extends Resourcable {
|
|||||||
|
|
||||||
public CompletableFuture<List<String>> zrangeAsync(String key, int start, int stop);
|
public CompletableFuture<List<String>> zrangeAsync(String key, int start, int stop);
|
||||||
|
|
||||||
public CompletableFuture<List<CacheScoredValue.NumberScoredValue>> zscanAsync(String key, Type scoreType, AtomicLong cursor, int limit, String pattern);
|
public CompletableFuture<List<CacheScoredValue>> zscanAsync(String key, Type scoreType, AtomicLong cursor, int limit, String pattern);
|
||||||
|
|
||||||
default CompletableFuture<List<CacheScoredValue.NumberScoredValue>> zscanIntegerAsync(String key, AtomicLong cursor, int limit, String pattern) {
|
default CompletableFuture<List<CacheScoredValue>> zscanIntegerAsync(String key, AtomicLong cursor, int limit, String pattern) {
|
||||||
return zscanAsync(key, Integer.class, cursor, limit, pattern);
|
return zscanAsync(key, Integer.class, cursor, limit, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
default CompletableFuture<List<CacheScoredValue.NumberScoredValue>> zscanLongAsync(String key, AtomicLong cursor, int limit, String pattern) {
|
default CompletableFuture<List<CacheScoredValue>> zscanLongAsync(String key, AtomicLong cursor, int limit, String pattern) {
|
||||||
return zscanAsync(key, Long.class, cursor, limit, pattern);
|
return zscanAsync(key, Long.class, cursor, limit, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
default CompletableFuture<List<CacheScoredValue.NumberScoredValue>> zscanDoubleAsync(String key, AtomicLong cursor, int limit, String pattern) {
|
default CompletableFuture<List<CacheScoredValue>> zscanDoubleAsync(String key, AtomicLong cursor, int limit, String pattern) {
|
||||||
return zscanAsync(key, Double.class, cursor, limit, pattern);
|
return zscanAsync(key, Double.class, cursor, limit, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
default CompletableFuture<List<CacheScoredValue.NumberScoredValue>> zscanAsync(String key, Type scoreType, AtomicLong cursor, int limit) {
|
default CompletableFuture<List<CacheScoredValue>> zscanAsync(String key, Type scoreType, AtomicLong cursor, int limit) {
|
||||||
return zscanAsync(key, scoreType, cursor, limit, null);
|
return zscanAsync(key, scoreType, cursor, limit, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default CompletableFuture<List<CacheScoredValue.NumberScoredValue>> zscanIntegerAsync(String key, AtomicLong cursor, int limit) {
|
default CompletableFuture<List<CacheScoredValue>> zscanIntegerAsync(String key, AtomicLong cursor, int limit) {
|
||||||
return zscanAsync(key, Integer.class, cursor, limit, null);
|
return zscanAsync(key, Integer.class, cursor, limit, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default CompletableFuture<List<CacheScoredValue.NumberScoredValue>> zscanLongAsync(String key, AtomicLong cursor, int limit) {
|
default CompletableFuture<List<CacheScoredValue>> zscanLongAsync(String key, AtomicLong cursor, int limit) {
|
||||||
return zscanAsync(key, Long.class, cursor, limit, null);
|
return zscanAsync(key, Long.class, cursor, limit, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default CompletableFuture<List<CacheScoredValue.NumberScoredValue>> zscanDoubleAsync(String key, AtomicLong cursor, int limit) {
|
default CompletableFuture<List<CacheScoredValue>> zscanDoubleAsync(String key, AtomicLong cursor, int limit) {
|
||||||
return zscanAsync(key, Double.class, cursor, limit, null);
|
return zscanAsync(key, Double.class, cursor, limit, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user