Class JedisWrapper
java.lang.Object
net.ognetwork.ogcore.api.wrappers.JedisWrapper
A wrapper for a normal Jedis instance.
Provides simplifications and utilities that make working with Jedis for a
long time more feasible.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionJedisWrapper
(String host, int port, String user, String password) Creates an instance of a Jedis Pool with some light wrapper management. -
Method Summary
Modifier and TypeMethodDescriptionvoid
connect()
Instantiates the JedisPool.static JedisWrapper
redis.clients.jedis.JedisPool
getPool()
Gets the Jedis pool.boolean
Checks if the Jedis pool is connected.<T> T
runCommand
(JedisCommand<T> command) Runs a command with an instance from the Jedis pool.boolean
Attempts to reconnect the Jedis pool.
-
Field Details
-
JEDIS_PREFIX
- See Also:
-
-
Constructor Details
-
JedisWrapper
Creates an instance of a Jedis Pool with some light wrapper management.- Parameters:
host
- The host name of the Redis server.port
- The port of the Redis server.
-
-
Method Details
-
connect
public void connect()Instantiates the JedisPool. This is called automatically byJedisWrapper(String, int, String, String)
andtryReconnect()
. -
getPool
public redis.clients.jedis.JedisPool getPool()Gets the Jedis pool.- Returns:
- the JedisPool instance.
-
runCommand
Runs a command with an instance from the Jedis pool.- Type Parameters:
T
- Any generic type. This would be the type that is returnd by theJedisCommand
.- Parameters:
command
- the command of typeJedisCommand
.- Returns:
- The result of the JedisCommand run function.
-
isConnected
public boolean isConnected()Checks if the Jedis pool is connected.- Returns:
- true if the jedis pool is connected, otherwise false.
-
tryReconnect
public boolean tryReconnect()Attempts to reconnect the Jedis pool. If the connection is strong, this will not do anything. If the connection is broken, this will reconnect.- Returns:
- true if the connection was re-established, false if the connection did not need to be reconnected.
-
getInstance
-