org.springframework.data.redis.connection.RedisServerCommands Maven / Gradle / Ivy
/*
* Copyright 2011-2018 the original author or authors.
*
* 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.springframework.data.redis.connection;
import java.util.List;
import java.util.Properties;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.lang.Nullable;
/**
* Server-specific commands supported by Redis.
*
* @author Costin Leau
* @author Christoph Strobl
* @author Thomas Darimont
* @author Mark Paluch
*/
public interface RedisServerCommands {
enum ShutdownOption {
SAVE, NOSAVE;
}
/**
* @since 1.7
*/
enum MigrateOption {
COPY, REPLACE
}
/**
* Start an {@literal Append Only File} rewrite process on server.
*
* @deprecated As of 1.3, use {@link #bgReWriteAof}.
* @see Redis Documentation: BGREWRITEAOF
*/
@Deprecated
default void bgWriteAof() {
bgReWriteAof();
}
/**
* Start an {@literal Append Only File} rewrite process on server.
*
* @since 1.3
* @see Redis Documentation: BGREWRITEAOF
*/
void bgReWriteAof();
/**
* Start background saving of db on server.
*
* @see Redis Documentation: BGSAVE
*/
void bgSave();
/**
* Get time of last {@link #bgSave()} operation in seconds.
*
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: LASTSAVE
*/
@Nullable
Long lastSave();
/**
* Synchronous save current db snapshot on server.
*
* @see Redis Documentation: SAVE
*/
void save();
/**
* Get the total number of available keys in currently selected database.
*
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: DBSIZE
*/
@Nullable
Long dbSize();
/**
* Delete all keys of the currently selected database.
*
* @see Redis Documentation: FLUSHDB
*/
void flushDb();
/**
* Delete all all keys from all databases.
*
* @see Redis Documentation: FLUSHALL
*/
void flushAll();
/**
* Load {@literal default} server information like
*
* - memory
* - cpu utilization
* - replication
*
*
*
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: INFO
*/
@Nullable
Properties info();
/**
* Load server information for given {@code selection}.
*
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: INFO
*/
@Nullable
Properties info(String section);
/**
* Shutdown server.
*
* @see Redis Documentation: SHUTDOWN
*/
void shutdown();
/**
* Shutdown server.
*
* @see Redis Documentation: SHUTDOWN
* @since 1.3
*/
void shutdown(ShutdownOption option);
/**
* Load configuration parameters for given {@code pattern} from server.
*
* @param pattern must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: CONFIG GET
*/
@Nullable
Properties getConfig(String pattern);
/**
* Set server configuration for {@code param} to {@code value}.
*
* @param param must not be {@literal null}.
* @param value must not be {@literal null}.
* @see Redis Documentation: CONFIG SET
*/
void setConfig(String param, String value);
/**
* Reset statistic counters on server.
* Counters can be retrieved using {@link #info()}.
*
* @see Redis Documentation: CONFIG RESETSTAT
*/
void resetConfigStats();
/**
* Request server timestamp using {@code TIME} command.
*
* @return current server time in milliseconds or {@literal null} when used in pipeline / transaction.
* @since 1.1
* @see Redis Documentation: TIME
*/
@Nullable
Long time();
/**
* Closes a given client connection identified by {@literal host:port}.
*
* @param host of connection to close.
* @param port of connection to close
* @since 1.3
* @see Redis Documentation: CLIENT KILL
*/
void killClient(String host, int port);
/**
* Assign given name to current connection.
*
* @param name
* @since 1.3
* @see Redis Documentation: CLIENT SETNAME
*/
void setClientName(byte[] name);
/**
* Returns the name of the current connection.
*
* @see Redis Documentation: CLIENT GETNAME
* @return {@literal null} when used in pipeline / transaction.
* @since 1.3
*/
@Nullable
String getClientName();
/**
* Request information and statistics about connected clients.
*
* @return {@link List} of {@link RedisClientInfo} objects or {@literal null} when used in pipeline / transaction.
* @since 1.3
* @see Redis Documentation: CLIENT LIST
*/
@Nullable
List getClientList();
/**
* Change redis replication setting to new master.
*
* @param host must not be {@literal null}.
* @param port
* @since 1.3
* @see Redis Documentation: SLAVEOF
*/
void slaveOf(String host, int port);
/**
* Change server into master.
*
* @since 1.3
* @see Redis Documentation: SLAVEOF
*/
void slaveOfNoOne();
/**
* Atomically transfer a key from a source Redis instance to a destination Redis instance. On success the key is
* deleted from the original instance and is guaranteed to exist in the target instance.
*
* @param key must not be {@literal null}.
* @param target must not be {@literal null}.
* @param dbIndex
* @param option can be {@literal null}. Defaulted to {@link MigrateOption#COPY}.
* @since 1.7
* @see Redis Documentation: MIGRATE
*/
void migrate(byte[] key, RedisNode target, int dbIndex, @Nullable MigrateOption option);
/**
* Atomically transfer a key from a source Redis instance to a destination Redis instance. On success the key is
* deleted from the original instance and is guaranteed to exist in the target instance.
*
* @param key must not be {@literal null}.
* @param target must not be {@literal null}.
* @param dbIndex
* @param option can be {@literal null}. Defaulted to {@link MigrateOption#COPY}.
* @param timeout
* @since 1.7
* @see Redis Documentation: MIGRATE
*/
void migrate(byte[] key, RedisNode target, int dbIndex, @Nullable MigrateOption option, long timeout);
}