forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pool and pooled Jedis clients for comparison
Signed-off-by: Andrew Carbonetto <[email protected]>
- Loading branch information
1 parent
596fa98
commit 3e6feed
Showing
4 changed files
with
148 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
java/benchmarks/src/main/java/javababushka/benchmarks/clients/jedis/JedisPoolClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package javababushka.benchmarks.clients.jedis; | ||
|
||
import javababushka.benchmarks.clients.SyncClient; | ||
import javababushka.benchmarks.utils.ConnectionSettings; | ||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.JedisPool; | ||
|
||
/** A Jedis client with sync capabilities. See: https://github.com/redis/jedis */ | ||
public class JedisPoolClient implements SyncClient { | ||
|
||
// protected Jedis jedisResource; | ||
protected JedisPool pool; | ||
|
||
// protected JedisPooled pooledConnection; | ||
@Override | ||
public void closeConnection() { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Jedis"; | ||
} | ||
|
||
@Override | ||
public void connectToRedis() { | ||
connectToRedis(DEFAULT_CONNECTION_STRING); | ||
} | ||
|
||
@Override | ||
public void connectToRedis(ConnectionSettings connectionSettings) { | ||
assert connectionSettings.clusterMode == false | ||
: "JedisClient does not support clusterMode: use JedisClusterClient instead"; | ||
pool = | ||
new JedisPool(connectionSettings.host, connectionSettings.port, connectionSettings.useSsl); | ||
|
||
// check if the pool is properly connected | ||
try (Jedis jedis = pool.getResource()) { | ||
assert jedis.isConnected() : "failed to connect to jedis"; | ||
} | ||
} | ||
|
||
public String info() { | ||
try (Jedis jedis = pool.getResource()) { | ||
return jedis.info(); | ||
} | ||
} | ||
|
||
public String info(String section) { | ||
try (Jedis jedis = pool.getResource()) { | ||
return jedis.info(section); | ||
} | ||
} | ||
|
||
@Override | ||
public void set(String key, String value) { | ||
try (Jedis jedis = pool.getResource()) { | ||
jedis.set(key, value); | ||
} | ||
} | ||
|
||
@Override | ||
public String get(String key) { | ||
try (Jedis jedis = pool.getResource()) { | ||
return jedis.get(key); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
java/benchmarks/src/main/java/javababushka/benchmarks/clients/jedis/JedisPooledClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package javababushka.benchmarks.clients.jedis; | ||
|
||
import javababushka.benchmarks.clients.SyncClient; | ||
import javababushka.benchmarks.utils.ConnectionSettings; | ||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.JedisPool; | ||
import redis.clients.jedis.JedisPooled; | ||
|
||
/** A Jedis client with sync capabilities. See: https://github.com/redis/jedis */ | ||
public class JedisPooledClient implements SyncClient { | ||
|
||
// protected Jedis jedisResource; | ||
protected JedisPooled pool; | ||
|
||
// protected JedisPooled pooledConnection; | ||
@Override | ||
public void closeConnection() { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Jedis"; | ||
} | ||
|
||
@Override | ||
public void connectToRedis() { | ||
connectToRedis(DEFAULT_CONNECTION_STRING); | ||
} | ||
|
||
@Override | ||
public void connectToRedis(ConnectionSettings connectionSettings) { | ||
assert connectionSettings.clusterMode == false | ||
: "JedisClient does not support clusterMode: use JedisClusterClient instead"; | ||
pool = | ||
new JedisPooled(connectionSettings.host, connectionSettings.port, connectionSettings.useSsl); | ||
|
||
// check if the pool is properly connected | ||
assert pool.getPool().getResource().isConnected() : "failed to connect to jedis"; | ||
} | ||
|
||
public String info() { | ||
return "N/A"; | ||
} | ||
|
||
public String info(String section) { | ||
return "N/A"; | ||
} | ||
|
||
@Override | ||
public void set(String key, String value) { | ||
pool.set(key, value); | ||
} | ||
|
||
@Override | ||
public String get(String key) { | ||
return pool.get(key); | ||
} | ||
} |