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 lettuce clients for benchmarking
Signed-off-by: acarbonetto <[email protected]>
- Loading branch information
1 parent
035ef20
commit 0b4a5bf
Showing
10 changed files
with
488 additions
and
4 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
19 changes: 19 additions & 0 deletions
19
java/benchmarks/src/main/java/javababushka/benchmarks/clients/AsyncClient.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,19 @@ | ||
package javababushka.benchmarks.clients; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
/** | ||
* A Redis client with async capabilities | ||
*/ | ||
public interface AsyncClient extends Client { | ||
|
||
long DEFAULT_TIMEOUT = 1000; | ||
|
||
Future<?> asyncSet(String key, String value); | ||
|
||
Future<String> asyncGet(String key); | ||
|
||
<T> T waitForResult(Future<T> future); | ||
|
||
<T> T waitForResult(Future<T> future, long timeout); | ||
} |
16 changes: 16 additions & 0 deletions
16
java/benchmarks/src/main/java/javababushka/benchmarks/clients/Client.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,16 @@ | ||
package javababushka.benchmarks.clients; | ||
|
||
import javababushka.benchmarks.utils.ConnectionSettings; | ||
|
||
/** | ||
* A Redis client interface | ||
*/ | ||
public interface Client { | ||
void connectToRedis(); | ||
|
||
void connectToRedis(ConnectionSettings connectionSettings); | ||
|
||
default void closeConnection() {} | ||
|
||
String getName(); | ||
} |
73 changes: 73 additions & 0 deletions
73
java/benchmarks/src/main/java/javababushka/benchmarks/clients/LettuceAsyncClient.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,73 @@ | ||
package javababushka.benchmarks.clients; | ||
|
||
import io.lettuce.core.RedisClient; | ||
import io.lettuce.core.RedisFuture; | ||
import io.lettuce.core.api.StatefulRedisConnection; | ||
import io.lettuce.core.api.async.RedisAsyncCommands; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
import javababushka.benchmarks.utils.ConnectionSettings; | ||
|
||
/** | ||
* A Lettuce client with async capabilities | ||
* see: https://lettuce.io/ | ||
*/ | ||
public class LettuceAsyncClient implements AsyncClient { | ||
|
||
RedisClient client; | ||
RedisAsyncCommands asyncCommands; | ||
StatefulRedisConnection<String, String> connection; | ||
|
||
@Override | ||
public void connectToRedis() { | ||
connectToRedis(new ConnectionSettings("localhost", 6379, false)); | ||
} | ||
|
||
@Override | ||
public void connectToRedis(ConnectionSettings connectionSettings) { | ||
client = | ||
RedisClient.create( | ||
String.format( | ||
"%s://%s:%d", | ||
connectionSettings.useSsl ? "rediss" : "redis", | ||
connectionSettings.host, | ||
connectionSettings.port)); | ||
connection = client.connect(); | ||
asyncCommands = connection.async(); | ||
} | ||
|
||
@Override | ||
public RedisFuture<?> asyncSet(String key, String value) { | ||
return asyncCommands.set(key, value); | ||
} | ||
|
||
@Override | ||
public RedisFuture<String> asyncGet(String key) { | ||
return asyncCommands.get(key); | ||
} | ||
|
||
@Override | ||
public Object waitForResult(Future future) { | ||
return waitForResult(future, DEFAULT_TIMEOUT); | ||
} | ||
|
||
@Override | ||
public Object waitForResult(Future future, long timeoutMS) { | ||
try { | ||
return future.get(timeoutMS, TimeUnit.MILLISECONDS); | ||
} catch (Exception ignored) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public void closeConnection() { | ||
connection.close(); | ||
client.shutdown(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Lettuce Async"; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
java/benchmarks/src/main/java/javababushka/benchmarks/clients/LettuceClient.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,56 @@ | ||
package javababushka.benchmarks.clients; | ||
|
||
import io.lettuce.core.RedisClient; | ||
import io.lettuce.core.api.StatefulRedisConnection; | ||
import io.lettuce.core.api.sync.RedisStringCommands; | ||
import javababushka.benchmarks.utils.ConnectionSettings; | ||
|
||
/** | ||
* A Lettuce client with sync capabilities | ||
* see: https://lettuce.io/ | ||
*/ | ||
public class LettuceClient implements SyncClient { | ||
|
||
RedisClient client; | ||
RedisStringCommands syncCommands; | ||
StatefulRedisConnection<String, String> connection; | ||
|
||
@Override | ||
public void connectToRedis() { | ||
connectToRedis(new ConnectionSettings("localhost", 6379, false)); | ||
} | ||
|
||
@Override | ||
public void connectToRedis(ConnectionSettings connectionSettings) { | ||
client = | ||
RedisClient.create( | ||
String.format( | ||
"%s://%s:%d", | ||
connectionSettings.useSsl ? "rediss" : "redis", | ||
connectionSettings.host, | ||
connectionSettings.port)); | ||
connection = client.connect(); | ||
syncCommands = connection.sync(); | ||
} | ||
|
||
@Override | ||
public void set(String key, String value) { | ||
syncCommands.set(key, value); | ||
} | ||
|
||
@Override | ||
public String get(String key) { | ||
return (String) syncCommands.get(key); | ||
} | ||
|
||
@Override | ||
public void closeConnection() { | ||
connection.close(); | ||
client.shutdown(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Lettuce"; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
java/benchmarks/src/main/java/javababushka/benchmarks/clients/SyncClient.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,10 @@ | ||
package javababushka.benchmarks.clients; | ||
|
||
/** | ||
* A Redis client with sync capabilities | ||
*/ | ||
public interface SyncClient extends Client { | ||
void set(String key, String value); | ||
|
||
String get(String key); | ||
} |
Oops, something went wrong.