Package io.toro.martini.redis
Class RedisConnectionMethods
- java.lang.Object
-
- io.toro.martini.redis.RedisBaseMethods
-
- io.toro.martini.redis.RedisConnectionMethods
-
public class RedisConnectionMethods extends io.toro.martini.redis.RedisBaseMethods
-
-
Constructor Summary
Constructors Constructor Description RedisConnectionMethods(io.toro.martini.database.DataSourceManager dataSourceManager)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static io.toro.martini.database.LettuceRedisDataSource
connection(String redisConnectionName)
Return Redis datasource objectstatic RedisCommand
dispatch(String connectionName, RedisCommand command, GloopExecutionContext context)
Dispatch a command.static Collection<RedisCommand>
dispatch(String connectionName, Collection<? extends RedisCommand> commands, GloopExecutionContext context)
Dispatch multiple command in a single write on the channel.static Future<Object>
dispatchAsync(String connectionName, ProtocolKeyword type, CommandOutput output, CommandArgs<Object,Object> args, GloopExecutionContext context)
Asynchronously dispatch a command to the redis server.static Future<Object>
dispatchAsync(String connectionName, ProtocolKeyword type, CommandOutput output, GloopExecutionContext context)
Asynchronously dispatch a command to the redis server.static Object
echo(String connectionName, Object msg, GloopExecutionContext context)
Echo the given string.static Future<Object>
echoAsync(String connectionName, Object msg, GloopExecutionContext context)
Asynchronously echo the given string.static void
flushCommands(String connectionName, GloopExecutionContext context)
Flush pending commands.static void
flushCommandsAsync(String connectionName, GloopExecutionContext context)
Asynchronously flush pending commands.static ClientOptions
getOptions(String connectionName, GloopExecutionContext context)
static ClientResources
getResources(String connectionName, GloopExecutionContext context)
static Duration
getTimeout(String connectionName, GloopExecutionContext context)
static boolean
isOpen(String connectionName, GloopExecutionContext context)
Checks whether the connection to Redis is open or notstatic String
ping(String connectionName, GloopExecutionContext context)
Ping the server.static Future<String>
pingAsync(String connectionName, GloopExecutionContext context)
Asynchronously ping the server.static Long
publish(String connectionName, Object channel, Object message, GloopExecutionContext context)
Post a message to a channel.static Future<Long>
publishAsync(String connectionName, Object channel, Object message, GloopExecutionContext context)
Asynchronously post a message to a channel.static List<Object>
pubsubChannels(String connectionName, Object channel, GloopExecutionContext context)
Lists the currently *active channels*.static Future<List<Object>>
pubsubChannelsAsync(String connectionName, GloopExecutionContext context)
Asynchronously lists the currently *active channels*.static Future<List<Object>>
pubsubChannelsAsync(String connectionName, Object channel, GloopExecutionContext context)
Asynchronously lists the currently *active channels*.static Long
pubsubNumpat(String connectionName, GloopExecutionContext context)
Returns the number of subscriptions to patterns.static Future<Long>
pubsubNumpatAsync(String connectionName, GloopExecutionContext context)
Asynchronously returns the number of subscriptions to patterns.static GloopModel
pubsubNumsub(String connectionName, GloopExecutionContext context, Object... channels)
Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.static Future<Map<Object,Long>>
pubsubNumsubAsync(String connectionName, GloopExecutionContext context, Object... channels)
Asynchronously returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.static String
quit(String connectionName, GloopExecutionContext context)
Instructs Redis to disconnect the connection.static Future<String>
quitAsync(String connectionName, GloopExecutionContext context)
Asynchronously instructs redis to disconnect the connection.static String
readOnly(String connectionName, GloopExecutionContext context)
Switch connection to Read-Only mode when connecting to a cluster.static Future<String>
readOnlyAsync(String connectionName, GloopExecutionContext context)
Asynchronously switch connection to read-Only mode when connecting to a cluster.static String
readWrite(String connectionName, GloopExecutionContext context)
Switch connection to Read-Write mode (default) when connecting to a cluster.static Future<String>
readWriteAsync(String connectionName, GloopExecutionContext context)
Asynchronously switch connection to read-Write mode (default) when connecting to a cluster.static void
reset(String connectionName, GloopExecutionContext context)
Reset the command state.static void
resetAsync(String connectionName, GloopExecutionContext context)
Asynchronously reset the command state.static List<Object>
role(String connectionName, GloopExecutionContext context)
Return the role of the instance in the context of replication.static Future<List<Object>>
roleAsync(String connectionName, GloopExecutionContext context)
Asynchronously return the role of the instance in the context of replication.static void
setAutoFlushCommands(String connectionName, boolean autoFlush, GloopExecutionContext context)
Disable or enable auto-flush behavior.static void
setAutoFlushCommandsAsync(String connectionName, boolean autoFlush, GloopExecutionContext context)
Disable or enable auto-flush behavior.static void
setTimeout(String connectionName, Duration timeout, GloopExecutionContext context)
Set the default command timeout for this connection.static void
setTimeoutAsync(String connectionName, Duration timeout, GloopExecutionContext context)
Asynchronously set the default command timeout for this connection.static Long
waitForReplication(String connectionName, int replicas, long timeout, GloopExecutionContext context)
Wait for replication.static Future<Long>
waitForReplicationAsync(String connectionName, int replicas, long timeout, GloopExecutionContext context)
Asynchronously wait for replication.
-
-
-
Constructor Detail
-
RedisConnectionMethods
@Autowired RedisConnectionMethods(io.toro.martini.database.DataSourceManager dataSourceManager)
-
-
Method Detail
-
connection
public static io.toro.martini.database.LettuceRedisDataSource connection(String redisConnectionName)
Return Redis datasource object- Parameters:
redisConnectionName
- the name of the saved database connection in Martini- Returns:
- datasource
-
setTimeout
public static void setTimeout(@GloopParameter(allowNull=false) String connectionName, Duration timeout, GloopExecutionContext context)
Set the default command timeout for this connection.- Parameters:
connectionName
- The Martini Runtime Redis connection pool nametimeout
- Command timeout.- Since:
- 5.0
-
setTimeoutAsync
public static void setTimeoutAsync(@GloopParameter(allowNull=false) String connectionName, Duration timeout, GloopExecutionContext context)
Asynchronously set the default command timeout for this connection.- Parameters:
connectionName
- The Martini Runtime Redis connection pool nametimeout
- Command timeout.- Since:
- 5.0
-
getTimeout
public static Duration getTimeout(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- the timeout.
-
dispatch
public static RedisCommand dispatch(@GloopParameter(allowNull=false) String connectionName, RedisCommand command, GloopExecutionContext context)
Dispatch a command. Write a command on the channel. The command may be changed/wrapped during write and the written instance is returned after the call. This command does not wait until the command completes and does not guarantee whether the command is executed successfully.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namecommand
- the Redis command.- Returns:
- the written Redis command.
-
dispatch
public static Collection<RedisCommand> dispatch(@GloopParameter(allowNull=false) String connectionName, Collection<? extends RedisCommand> commands, GloopExecutionContext context)
Dispatch multiple command in a single write on the channel. The commands may be changed/wrapped during write and the written instance is returned after the call. This command does not wait until the command completes and does not guarantee whether the command is executed successfully.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namecommands
- the Redis commands.- Returns:
- the written Redis commands.
- Since:
- 5.0
-
dispatchAsync
@GloopParameter(name="redisFutureDispatchOutput") public static Future<Object> dispatchAsync(@GloopParameter(allowNull=false) String connectionName, @GloopParameter(allowNull=false) ProtocolKeyword type, @GloopParameter(allowNull=false) CommandOutput output, GloopExecutionContext context)
Asynchronously dispatch a command to the redis server. please note the command output type must fit to the command response.- Parameters:
connectionName
- The Martini Runtime Redis connection pool nametype
- the command, must not be null.output
- the command output, must not be null.- Returns:
- the command response
-
dispatchAsync
@GloopParameter(name="redisFutureDispatchOutput") public static Future<Object> dispatchAsync(@GloopParameter(allowNull=false) String connectionName, @GloopParameter(allowNull=false) ProtocolKeyword type, @GloopParameter(allowNull=false) CommandOutput output, @GloopParameter(allowNull=false) CommandArgs<Object,Object> args, GloopExecutionContext context)
Asynchronously dispatch a command to the redis server. please note the command output type must fit to the command response.- Parameters:
connectionName
- The Martini Runtime Redis connection pool nametype
- the command, must not be null.output
- the command output, must not be null.args
- the command arguments, must not be null.- Returns:
- the command response
-
isOpen
public static boolean isOpen(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Checks whether the connection to Redis is open or not- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- true if the connection is open (connected and not closed).
-
getOptions
public static ClientOptions getOptions(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- the client options valid for this connection.
-
getResources
public static ClientResources getResources(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- the client resources used for this connection.
-
reset
public static void reset(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Reset the command state. Queued commands will be canceled and the internal state will be reset. This is useful when the internal state machine gets out of sync with the connection.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name
-
resetAsync
public static void resetAsync(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Asynchronously reset the command state. queued commands will be canceled and the internal state will be reset. this is useful when the internal state machine gets out of sync with the connection.- Parameters:
connectionName
- the Martini Runtime redis connection pool name
-
setAutoFlushCommands
public static void setAutoFlushCommands(@GloopParameter(allowNull=false) String connectionName, boolean autoFlush, GloopExecutionContext context)
Disable or enable auto-flush behavior. Default is true. If autoFlushCommands is disabled, multiple commands can be issued without writing them actually to the transport. Commands are buffered until a#flushCommands(String)
is issued. After calling#flushCommands(String)
commands are sent to the transport and executed by Redis.- Parameters:
connectionName
- The Martini Runtime Redis connection pool nameautoFlush
- state of autoFlush.
-
setAutoFlushCommandsAsync
public static void setAutoFlushCommandsAsync(@GloopParameter(allowNull=false) String connectionName, boolean autoFlush, GloopExecutionContext context)
Disable or enable auto-flush behavior. Default is true. If autoFlushCommands is disabled, multiple commands can be issued without writing them actually to the transport. Commands are buffered until a#flushCommands(String)
is issued. After calling#flushCommands(String)
commands are sent to the transport and executed by Redis.- Parameters:
connectionName
- The Martini Runtime Redis connection pool nameautoFlush
- state of autoFlush.
-
flushCommands
public static void flushCommands(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Flush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to achieve batching. No-op if channel is not connected.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name
-
flushCommandsAsync
public static void flushCommandsAsync(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Asynchronously flush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to achieve batching. No-op if channel is not connected.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name
-
publish
@GloopParameter(name="redisPublishOutput") public static Long publish(@GloopParameter(allowNull=false) String connectionName, @GloopParameter(allowNull=false) Object channel, @GloopParameter(allowNull=false) Object message, GloopExecutionContext context)
Post a message to a channel.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namechannel
- the channel type: keymessage
- the message type: value- Returns:
- Long integer-reply the number of clients that received the message.
-
publishAsync
@GloopParameter(name="redisFuturePublishOutput") public static Future<Long> publishAsync(@GloopParameter(allowNull=false) String connectionName, @GloopParameter(allowNull=false) Object channel, @GloopParameter(allowNull=false) Object message, GloopExecutionContext context)
Asynchronously post a message to a channel.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namechannel
- the channel type: keymessage
- the message type: value- Returns:
- long integer-reply the number of clients that received the message.
-
pubsubChannels
@GloopParameter(name="redisPubsubChannelsOutput") public static List<Object> pubsubChannels(@GloopParameter(allowNull=false) String connectionName, @GloopParameter(allowNull=false) Object channel, GloopExecutionContext context)
Lists the currently *active channels*.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namechannel
- the key- Returns:
- List<K> array-reply a list of active channels, optionally matching the specified pattern.
-
pubsubChannelsAsync
@GloopParameter(name="redisFuturePubsubChannelsOutput") public static Future<List<Object>> pubsubChannelsAsync(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Asynchronously lists the currently *active channels*.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- list<K> array-reply a list of active channels, optionally matching the specified pattern.
-
pubsubChannelsAsync
@GloopParameter(name="redisFuturePubsubChannelsOutput") public static Future<List<Object>> pubsubChannelsAsync(@GloopParameter(allowNull=false) String connectionName, @GloopParameter(allowNull=false) Object channel, GloopExecutionContext context)
Asynchronously lists the currently *active channels*.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namechannel
- the key- Returns:
- list<K> array-reply a list of active channels, optionally matching the specified pattern.
-
pubsubNumsub
@GloopObjectParameter("output{\nredisMap[]{\n name:object\n value:object\n}\n}") public static GloopModel pubsubNumsub(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context, @GloopParameter(allowNull=false) Object... channels)
Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namechannels
- channel keys- Returns:
- array-reply a list of channels and number of subscribers for every channel.
-
pubsubNumsubAsync
@GloopParameter(name="redisFuturePubsubNumsubOutput") public static Future<Map<Object,Long>> pubsubNumsubAsync(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context, @GloopParameter(allowNull=false) Object... channels)
Asynchronously returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namechannels
- channel keys- Returns:
- array-reply a list of channels and number of subscribers for every channel.
-
pubsubNumpat
@GloopParameter(name="redisPubsubNumpatOutput") public static Long pubsubNumpat(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Returns the number of subscriptions to patterns.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- Long integer-reply the number of patterns all the clients are subscribed to.
-
pubsubNumpatAsync
@GloopParameter(name="redisFuturePubsubNumpatOutput") public static Future<Long> pubsubNumpatAsync(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Asynchronously returns the number of subscriptions to patterns.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- long integer-reply the number of patterns all the clients are subscribed to.
-
echo
@GloopParameter(name="redisEchoOutput") public static Object echo(@GloopParameter(allowNull=false) String connectionName, @GloopParameter(allowNull=false) Object msg, GloopExecutionContext context)
Echo the given string.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namemsg
- the message type: value- Returns:
- V bulk-string-reply
-
echoAsync
@GloopParameter(name="redisFutureEchoOutput") public static Future<Object> echoAsync(@GloopParameter(allowNull=false) String connectionName, @GloopParameter(allowNull=false) Object msg, GloopExecutionContext context)
Asynchronously echo the given string.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namemsg
- the message type: value- Returns:
- v bulk-string-reply
-
role
@GloopParameter(name="redisRoleOutput") public static List<Object> role(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Return the role of the instance in the context of replication.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- List<Object> array-reply where the first element is one of master, slave, sentinel and the additional elements are role-specific.
-
roleAsync
@GloopParameter(name="redisFutureRoleOutput") public static Future<List<Object>> roleAsync(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Asynchronously return the role of the instance in the context of replication.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- list<Object> array-reply where the first element is one of master, slave, sentinel and the additional elements are role-specific.
-
ping
@GloopParameter(name="redisPingOutput") public static String ping(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Ping the server.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- String simple-string-reply
-
pingAsync
@GloopParameter(name="redisFuturePingOutput") public static Future<String> pingAsync(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Asynchronously ping the server.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- string simple-string-reply
-
readOnly
@GloopParameter(name="redisReadOnlyOutput") public static String readOnly(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Switch connection to Read-Only mode when connecting to a cluster.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- String simple-string-reply.
-
readOnlyAsync
@GloopParameter(name="redisFutureReadOnlyOutput") public static Future<String> readOnlyAsync(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Asynchronously switch connection to read-Only mode when connecting to a cluster.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- string simple-string-reply.
-
readWrite
@GloopParameter(name="redisReadWriteOutput") public static String readWrite(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Switch connection to Read-Write mode (default) when connecting to a cluster.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- String simple-string-reply.
-
readWriteAsync
@GloopParameter(name="redisFutureReadWriteOutput") public static Future<String> readWriteAsync(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Asynchronously switch connection to read-Write mode (default) when connecting to a cluster.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- string simple-string-reply.
-
quit
@GloopParameter(name="redisQuitOutput") public static String quit(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Instructs Redis to disconnect the connection. Note that if auto-reconnect is enabled then Lettuce will auto-reconnect if the connection was disconnected. UseStatefulConnection.close()
to close connections and release resources.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- String simple-string-reply always OK.
-
quitAsync
@GloopParameter(name="redisFutureQuitOutput") public static Future<String> quitAsync(@GloopParameter(allowNull=false) String connectionName, GloopExecutionContext context)
Asynchronously instructs redis to disconnect the connection. note that if auto-reconnect is enabled then lettuce will auto-reconnect if the connection was disconnected. useStatefulConnection.close()
to close connections and release resources.- Parameters:
connectionName
- The Martini Runtime Redis connection pool name- Returns:
- string simple-string-reply always oK.
-
waitForReplication
@GloopParameter(name="redisWaitForReplicationOutput") public static Long waitForReplication(@GloopParameter(allowNull=false) String connectionName, @GloopParameter(allowNull=false) int replicas, @GloopParameter(allowNull=false) long timeout, GloopExecutionContext context)
Wait for replication.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namereplicas
- minimum number of replicastimeout
- timeout in milliseconds- Returns:
- number of replicas
-
waitForReplicationAsync
@GloopParameter(name="redisFutureWaitForReplicationOutput") public static Future<Long> waitForReplicationAsync(@GloopParameter(allowNull=false) String connectionName, @GloopParameter(allowNull=false) int replicas, @GloopParameter(allowNull=false) long timeout, GloopExecutionContext context)
Asynchronously wait for replication.- Parameters:
connectionName
- The Martini Runtime Redis connection pool namereplicas
- minimum number of replicastimeout
- timeout in milliseconds- Returns:
- number of replicas
-
-