Feature - RListMultimapCacheNative and RSetMultimapCacheNative objects added. Requires Redis 7.4+ #6113
parent
3f23018c83
commit
a58958a851
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import org.redisson.api.RFuture;
|
||||
import org.redisson.api.RListMultimapCacheNative;
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.command.CommandAsyncExecutor;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <K> key
|
||||
* @param <V> value
|
||||
*/
|
||||
public class RedissonListMultimapCacheNative<K, V> extends RedissonListMultimap<K, V> implements RListMultimapCacheNative<K, V> {
|
||||
|
||||
private final RedissonMultimapCacheNative<K> baseCache;
|
||||
|
||||
public RedissonListMultimapCacheNative(CommandAsyncExecutor connectionManager, String name) {
|
||||
super(connectionManager, name);
|
||||
baseCache = new RedissonMultimapCacheNative<>(connectionManager, this, prefix);
|
||||
}
|
||||
|
||||
public RedissonListMultimapCacheNative(Codec codec, CommandAsyncExecutor connectionManager, String name) {
|
||||
super(codec, connectionManager, name);
|
||||
baseCache = new RedissonMultimapCacheNative<>(connectionManager, this, prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean expireKey(K key, long timeToLive, TimeUnit timeUnit) {
|
||||
return get(expireKeyAsync(key, timeToLive, timeUnit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RFuture<Boolean> expireKeyAsync(K key, long timeToLive, TimeUnit timeUnit) {
|
||||
return baseCache.expireKeyAsync(key, timeToLive, timeUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit, String param, String... keys) {
|
||||
return baseCache.expireAsync(timeToLive, timeUnit, param);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RFuture<Boolean> expireAtAsync(long timestamp, String param, String... keys) {
|
||||
return baseCache.expireAtAsync(timestamp, param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RFuture<Boolean> clearExpireAsync() {
|
||||
return baseCache.clearExpireAsync();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.redisson.api.RFuture;
|
||||
import org.redisson.api.RObject;
|
||||
import org.redisson.client.codec.LongCodec;
|
||||
import org.redisson.client.protocol.RedisCommands;
|
||||
import org.redisson.command.CommandAsyncExecutor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <K> key type
|
||||
*/
|
||||
class RedissonMultimapCacheNative<K> {
|
||||
|
||||
private final CommandAsyncExecutor commandExecutor;
|
||||
private final RedissonMultimap<K, ?> object;
|
||||
private final String prefix;
|
||||
|
||||
RedissonMultimapCacheNative(CommandAsyncExecutor commandExecutor, RObject object, String prefix) {
|
||||
this.commandExecutor = commandExecutor;
|
||||
this.object = (RedissonMultimap<K, ?>) object;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public RFuture<Boolean> expireKeyAsync(K key, long timeToLive, TimeUnit timeUnit) {
|
||||
ByteBuf keyState = object.encodeMapKey(key);
|
||||
String keyHash = object.hash(keyState);
|
||||
String setName = object.getValuesName(keyHash);
|
||||
|
||||
return commandExecutor.evalWriteAsync(object.getRawName(), object.getCodec(), RedisCommands.EVAL_BOOLEAN,
|
||||
"if redis.call('hpexpire', KEYS[1], ARGV[1], 'fields', 1, ARGV[2]) == 1 then " +
|
||||
"redis.call('pexpire', KEYS[2], ARGV[1]); " +
|
||||
"return 1;" +
|
||||
"end; "
|
||||
+ "return 0; ",
|
||||
Arrays.asList(object.getRawName(), setName),
|
||||
timeUnit.toMillis(timeToLive), object.encodeMapKey(key));
|
||||
}
|
||||
|
||||
public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit, String param) {
|
||||
return commandExecutor.evalWriteAsync(object.getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
|
||||
"local entries = redis.call('hgetall', KEYS[1]); " +
|
||||
"for i, v in ipairs(entries) do " +
|
||||
"if i % 2 == 0 then " +
|
||||
"local name = ARGV[2] .. v; "
|
||||
+ "if ARGV[3] ~= '' then "
|
||||
+ "redis.call('pexpire', name, ARGV[1], ARGV[3]); "
|
||||
+ "else "
|
||||
+ "redis.call('pexpire', name, ARGV[1]); "
|
||||
+ "end; " +
|
||||
"end;" +
|
||||
"end; " +
|
||||
"if ARGV[3] ~= '' then "
|
||||
+ "return redis.call('pexpire', KEYS[1], ARGV[1], ARGV[3]); "
|
||||
+ "end; " +
|
||||
"return redis.call('pexpire', KEYS[1], ARGV[1]); ",
|
||||
Arrays.asList(object.getRawName()),
|
||||
timeUnit.toMillis(timeToLive), prefix, param);
|
||||
}
|
||||
|
||||
public RFuture<Boolean> expireAtAsync(long timestamp, String param) {
|
||||
return commandExecutor.evalWriteAsync(object.getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
|
||||
"local entries = redis.call('hgetall', KEYS[1]); " +
|
||||
"for i, v in ipairs(entries) do " +
|
||||
"if i % 2 == 0 then " +
|
||||
"local name = ARGV[2] .. v; "
|
||||
+ "if ARGV[3] ~= '' then "
|
||||
+ "redis.call('pexpireat', name, ARGV[1], ARGV[3]); "
|
||||
+ "else "
|
||||
+ "redis.call('pexpireat', name, ARGV[1]); "
|
||||
+ "end; " +
|
||||
"end;" +
|
||||
"end; " +
|
||||
"if ARGV[3] ~= '' then "
|
||||
+ "return redis.call('pexpireat', KEYS[1], ARGV[1], ARGV[3]); "
|
||||
+ "end; " +
|
||||
"return redis.call('pexpireat', KEYS[1], ARGV[1]); ",
|
||||
Arrays.asList(object.getRawName()),
|
||||
timestamp, prefix, param);
|
||||
}
|
||||
|
||||
public RFuture<Boolean> clearExpireAsync() {
|
||||
return commandExecutor.evalWriteAsync(object.getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
|
||||
"local entries = redis.call('hgetall', KEYS[1]); " +
|
||||
"for i, v in ipairs(entries) do " +
|
||||
"if i % 2 == 0 then " +
|
||||
"local name = ARGV[1] .. v; " +
|
||||
"redis.call('persist', name); " +
|
||||
"end;" +
|
||||
"end; " +
|
||||
"return redis.call('persist', KEYS[1]); ",
|
||||
Arrays.asList(object.getRawName()),
|
||||
prefix);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import org.redisson.api.RFuture;
|
||||
import org.redisson.api.RSetMultimapCacheNative;
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.command.CommandAsyncExecutor;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <K> key
|
||||
* @param <V> value
|
||||
*/
|
||||
public class RedissonSetMultimapCacheNative<K, V> extends RedissonSetMultimap<K, V> implements RSetMultimapCacheNative<K, V> {
|
||||
|
||||
private final RedissonMultimapCacheNative<K> baseCache;
|
||||
|
||||
public RedissonSetMultimapCacheNative(CommandAsyncExecutor connectionManager, String name) {
|
||||
super(connectionManager, name);
|
||||
baseCache = new RedissonMultimapCacheNative<>(connectionManager, this, prefix);
|
||||
}
|
||||
|
||||
public RedissonSetMultimapCacheNative(Codec codec, CommandAsyncExecutor connectionManager, String name) {
|
||||
super(codec, connectionManager, name);
|
||||
baseCache = new RedissonMultimapCacheNative<>(connectionManager, this, prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean expireKey(K key, long timeToLive, TimeUnit timeUnit) {
|
||||
return get(expireKeyAsync(key, timeToLive, timeUnit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RFuture<Boolean> expireKeyAsync(K key, long timeToLive, TimeUnit timeUnit) {
|
||||
return baseCache.expireKeyAsync(key, timeToLive, timeUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit, String param, String... keys) {
|
||||
return baseCache.expireAsync(timeToLive, timeUnit, param);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RFuture<Boolean> expireAtAsync(long timestamp, String param, String... keys) {
|
||||
return baseCache.expireAtAsync(timestamp, param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RFuture<Boolean> clearExpireAsync() {
|
||||
return baseCache.clearExpireAsync();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* List based Multimap with ability to set TTL per entry.
|
||||
* Stores insertion order and allows duplicates for values mapped to key.
|
||||
* Uses Redis native commands for entry expiration and not a scheduled eviction task.
|
||||
* <p>
|
||||
* Requires <b>Redis 7.4.0 and higher.</b>
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <K> key
|
||||
* @param <V> value
|
||||
*/
|
||||
public interface RListMultimapCacheNative<K, V> extends RListMultimap<K, V>, RMultimapCache<K, V> {
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* List based Multimap with ability to set TTL per entry.
|
||||
* Stores insertion order and allows duplicates for values mapped to key.
|
||||
* Uses Redis native commands for entry expiration and not a scheduled eviction task.
|
||||
* <p>
|
||||
* Requires <b>Redis 7.4.0 and higher.</b>
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <K> key
|
||||
* @param <V> value
|
||||
*/
|
||||
public interface RListMultimapCacheNativeReactive<K, V> extends RListMultimapReactive<K, V>, RMultimapCacheReactive<K, V> {
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* List based Multimap with ability to set TTL per entry.
|
||||
* Stores insertion order and allows duplicates for values mapped to key.
|
||||
* Uses Redis native commands for entry expiration and not a scheduled eviction task.
|
||||
* <p>
|
||||
* Requires <b>Redis 7.4.0 and higher.</b>
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <K> key
|
||||
* @param <V> value
|
||||
*/
|
||||
public interface RListMultimapCacheNativeRx<K, V> extends RListMultimapRx<K, V>, RMultimapCacheRx<K, V> {
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Set based Multimap with ability to set TTL per entry.
|
||||
* Doesn't allow duplications for values mapped to key.
|
||||
* Uses Redis native commands for entry expiration and not a scheduled eviction task.
|
||||
* <p>
|
||||
* Requires <b>Redis 7.4.0 and higher.</b>
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <K> key
|
||||
* @param <V> value
|
||||
*/
|
||||
public interface RSetMultimapCacheNative<K, V> extends RSetMultimap<K, V>, RMultimapCache<K, V> {
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Set based Multimap with ability to set TTL per entry.
|
||||
* Doesn't allow duplications for values mapped to key.
|
||||
* Uses Redis native commands for entry expiration and not a scheduled eviction task.
|
||||
* <p>
|
||||
* Requires <b>Redis 7.4.0 and higher.</b>
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <K> key
|
||||
* @param <V> value
|
||||
*/
|
||||
public interface RSetMultimapCacheNativeReactive<K, V> extends RSetMultimapReactive<K, V>, RMultimapCacheReactive<K, V> {
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Set based Multimap with ability to set TTL per entry.
|
||||
* Doesn't allow duplications for values mapped to key.
|
||||
* Uses Redis native commands for entry expiration and not a scheduled eviction task.
|
||||
* <p>
|
||||
* Requires <b>Redis 7.4.0 and higher.</b>
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <K> key
|
||||
* @param <V> value
|
||||
*/
|
||||
public interface RSetMultimapCacheNativeRx<K, V> extends RSetMultimapRx<K, V>, RMultimapCacheRx<K, V> {
|
||||
|
||||
}
|
Loading…
Reference in New Issue