org.redisson.RedissonFuction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redisson-all Show documentation
Show all versions of redisson-all Show documentation
Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC
/**
* 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.*;
import org.redisson.client.codec.ByteArrayCodec;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.misc.CompletableFutureWrapper;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
*
* @author Nikita Koksharov
*
*/
public class RedissonFuction implements RFunction {
private final Codec codec;
private final CommandAsyncExecutor commandExecutor;
public RedissonFuction(CommandAsyncExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
this.codec = commandExecutor.getServiceManager().getCfg().getCodec();
}
public RedissonFuction(CommandAsyncExecutor commandExecutor, Codec codec) {
this.commandExecutor = commandExecutor;
this.codec = commandExecutor.getServiceManager().getCodec(codec);
}
@Override
public void delete(String libraryName) {
commandExecutor.get(deleteAsync(libraryName));
}
@Override
public RFuture deleteAsync(String libraryName) {
return commandExecutor.writeAllVoidAsync(RedisCommands.FUNCTION_DELETE, libraryName);
}
@Override
public byte[] dump() {
return commandExecutor.get(dumpAsync());
}
@Override
public RFuture dumpAsync() {
return commandExecutor.readAsync((String) null, ByteArrayCodec.INSTANCE, RedisCommands.FUNCTION_DUMP);
}
@Override
public void flush() {
commandExecutor.get(flushAsync());
}
@Override
public RFuture flushAsync() {
return commandExecutor.writeAllVoidAsync(RedisCommands.FUNCTION_FLUSH);
}
@Override
public void kill() {
commandExecutor.get(killAsync());
}
@Override
public RFuture killAsync() {
List> futures = commandExecutor.executeAllAsync(RedisCommands.FUNCTION_KILL);
CompletableFuture f = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
return new CompletableFutureWrapper<>(f);
}
@Override
public List list() {
return commandExecutor.get(listAsync());
}
@Override
public RFuture> listAsync() {
return commandExecutor.readAsync((String) null, ByteArrayCodec.INSTANCE, RedisCommands.FUNCTION_LIST);
}
@Override
public List list(String namePattern) {
return commandExecutor.get(listAsync(namePattern));
}
@Override
public RFuture> listAsync(String namePattern) {
return commandExecutor.readAsync((String) null, ByteArrayCodec.INSTANCE, RedisCommands.FUNCTION_LIST, "LIBRARYNAME", namePattern);
}
@Override
public void load(String libraryName, String code) {
commandExecutor.get(loadAsync(libraryName, code));
}
@Override
public RFuture loadAsync(String libraryName, String code) {
return commandExecutor.writeAllVoidAsync(RedisCommands.FUNCTION_LOAD, "#!lua name=" + libraryName + " \n " + code);
}
@Override
public void loadAndReplace(String libraryName, String code) {
commandExecutor.get(loadAndReplaceAsync(libraryName, code));
}
@Override
public RFuture loadAndReplaceAsync(String libraryName, String code) {
return commandExecutor.writeAllVoidAsync(RedisCommands.FUNCTION_LOAD, "REPLACE",
"#!lua name=" + libraryName + " \n " + code);
}
@Override
public void restore(byte[] payload) {
commandExecutor.get(restoreAsync(payload));
}
@Override
public RFuture restoreAsync(byte[] payload) {
return commandExecutor.writeAllVoidAsync(RedisCommands.FUNCTION_RESTORE, payload);
}
@Override
public void restoreAndReplace(byte[] payload) {
commandExecutor.get(restoreAndReplaceAsync(payload));
}
@Override
public RFuture restoreAndReplaceAsync(byte[] payload) {
return commandExecutor.writeAllVoidAsync(RedisCommands.FUNCTION_RESTORE, payload, "REPLACE");
}
@Override
public void restoreAfterFlush(byte[] payload) {
commandExecutor.get(restoreAfterFlushAsync(payload));
}
@Override
public RFuture restoreAfterFlushAsync(byte[] payload) {
return commandExecutor.writeAllVoidAsync(RedisCommands.FUNCTION_RESTORE, payload, "FLUSH");
}
private List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy