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.
Signed-off-by: acarbonetto <[email protected]>
- Loading branch information
1 parent
4117580
commit 2799ac1
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
java/benchmarks/src/main/java/javababushka/benchmarks/clients/JedisClient.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,58 @@ | ||
package javababushka.benchmarks.clients; | ||
|
||
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 JedisClient implements SyncClient { | ||
|
||
public static final String DEFAULT_HOST = "localhost"; | ||
public static final int DEFAULT_PORT = 6379; | ||
|
||
protected Jedis jedisResource; | ||
|
||
@Override | ||
public void connectToRedis() { | ||
JedisPool pool = new JedisPool(DEFAULT_HOST, DEFAULT_PORT); | ||
jedisResource = pool.getResource(); | ||
} | ||
|
||
@Override | ||
public void closeConnection() { | ||
try { | ||
jedisResource.close(); | ||
} catch (Exception ignored) { | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Jedis"; | ||
} | ||
|
||
@Override | ||
public void connectToRedis(ConnectionSettings connectionSettings) { | ||
jedisResource = | ||
new Jedis(connectionSettings.host, connectionSettings.port, connectionSettings.useSsl); | ||
jedisResource.connect(); | ||
} | ||
|
||
public String info() { | ||
return jedisResource.info(); | ||
} | ||
|
||
public String info(String section) { | ||
return jedisResource.info(section); | ||
} | ||
|
||
@Override | ||
public void set(String key, String value) { | ||
jedisResource.set(key, value); | ||
} | ||
|
||
@Override | ||
public String get(String key) { | ||
return jedisResource.get(key); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
java/benchmarks/src/main/java/javababushka/benchmarks/clients/JedisPseudoAsyncClient.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,42 @@ | ||
package javababushka.benchmarks.clients; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* A jedis client with pseudo-sync capabilities. Jedis doesn't provide async API | ||
* https://github.com/redis/jedis/issues/241 | ||
* | ||
* <p>See: https://github.com/redis/jedis | ||
*/ | ||
public class JedisPseudoAsyncClient extends JedisClient implements AsyncClient { | ||
@Override | ||
public Future<?> asyncSet(String key, String value) { | ||
return CompletableFuture.runAsync(() -> super.set(key, value)); | ||
} | ||
|
||
@Override | ||
public Future<String> asyncGet(String key) { | ||
return CompletableFuture.supplyAsync(() -> super.get(key)); | ||
} | ||
|
||
@Override | ||
public <T> T waitForResult(Future<T> future) { | ||
return waitForResult(future, DEFAULT_TIMEOUT); | ||
} | ||
|
||
@Override | ||
public <T> T waitForResult(Future<T> future, long timeout) { | ||
try { | ||
return future.get(timeout, TimeUnit.MILLISECONDS); | ||
} catch (Exception ignored) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Jedis pseudo-async"; | ||
} | ||
} |