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.
Java: Add ExamplesApp and Update benchmarkingApp to both have Java/Gl…
…ide-for-redis client (valkey-io#896) * Java: Add ExamplesApp and Update benchmarkingApp to both have Java/Glide-for-redis client (valkey-io#896) Signed-off-by: Andrew Carbonetto <[email protected]> --------- Signed-off-by: Andrew Carbonetto <[email protected]> Signed-off-by: Yury-Fridlyand <[email protected]> Co-authored-by: Yury-Fridlyand <[email protected]>
- Loading branch information
1 parent
2c55611
commit 7292960
Showing
10 changed files
with
177 additions
and
24 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
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
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
83 changes: 83 additions & 0 deletions
83
java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClient.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,83 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.benchmarks.clients.glide; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
||
import glide.api.BaseClient; | ||
import glide.api.RedisClient; | ||
import glide.api.RedisClusterClient; | ||
import glide.api.models.configuration.NodeAddress; | ||
import glide.api.models.configuration.RedisClientConfiguration; | ||
import glide.api.models.configuration.RedisClusterClientConfiguration; | ||
import glide.benchmarks.clients.AsyncClient; | ||
import glide.benchmarks.utils.ConnectionSettings; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
/** A Glide client with async capabilities */ | ||
public class GlideAsyncClient implements AsyncClient<String> { | ||
private BaseClient redisClient; | ||
|
||
@Override | ||
public void connectToRedis(ConnectionSettings connectionSettings) { | ||
|
||
if (connectionSettings.clusterMode) { | ||
RedisClusterClientConfiguration config = | ||
RedisClusterClientConfiguration.builder() | ||
.address( | ||
NodeAddress.builder() | ||
.host(connectionSettings.host) | ||
.port(connectionSettings.port) | ||
.build()) | ||
.useTLS(connectionSettings.useSsl) | ||
.build(); | ||
try { | ||
redisClient = RedisClusterClient.CreateClient(config).get(10, SECONDS); | ||
} catch (InterruptedException | ExecutionException | TimeoutException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} else { | ||
RedisClientConfiguration config = | ||
RedisClientConfiguration.builder() | ||
.address( | ||
NodeAddress.builder() | ||
.host(connectionSettings.host) | ||
.port(connectionSettings.port) | ||
.build()) | ||
.useTLS(connectionSettings.useSsl) | ||
.build(); | ||
|
||
try { | ||
redisClient = RedisClient.CreateClient(config).get(10, SECONDS); | ||
} catch (InterruptedException | ExecutionException | TimeoutException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public CompletableFuture<String> asyncSet(String key, String value) { | ||
return redisClient.set(key, value); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<String> asyncGet(String key) { | ||
return redisClient.get(key); | ||
} | ||
|
||
@Override | ||
public void closeConnection() { | ||
try { | ||
redisClient.close(); | ||
} catch (ExecutionException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Glide Async"; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
// Apply the application plugin to add support for building a CLI application in Java. | ||
id 'application' | ||
} | ||
|
||
repositories { | ||
// Use Maven Central for resolving dependencies. | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation project(':client') | ||
|
||
implementation 'redis.clients:jedis:4.4.3' | ||
implementation 'io.lettuce:lettuce-core:6.2.6.RELEASE' | ||
implementation 'commons-cli:commons-cli:1.5.0' | ||
} | ||
|
||
run.dependsOn ':client:buildRustRelease' | ||
|
||
application { | ||
// Define the main class for the application. | ||
mainClass = 'glide.examples.ExamplesApp' | ||
applicationDefaultJvmArgs = ['-Djava.library.path=../target/release'] | ||
} |
41 changes: 41 additions & 0 deletions
41
java/examples/src/main/java/glide/examples/ExamplesApp.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,41 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.examples; | ||
|
||
import glide.api.RedisClient; | ||
import glide.api.models.configuration.NodeAddress; | ||
import glide.api.models.configuration.RedisClientConfiguration; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class ExamplesApp { | ||
|
||
// main application entrypoint | ||
public static void main(String[] args) { | ||
runGlideExamples(); | ||
} | ||
|
||
private static void runGlideExamples() { | ||
String host = "localhost"; | ||
Integer port = 6379; | ||
boolean useSsl = false; | ||
|
||
RedisClientConfiguration config = | ||
RedisClientConfiguration.builder() | ||
.address(NodeAddress.builder().host(host).port(port).build()) | ||
.useTLS(useSsl) | ||
.build(); | ||
|
||
try { | ||
RedisClient client = RedisClient.CreateClient(config).get(); | ||
|
||
System.out.println("PING: " + client.ping().get()); | ||
System.out.println("PING(found you): " + client.ping("found you").get()); | ||
|
||
System.out.println("SET(apples, oranges): " + client.set("apples", "oranges").get()); | ||
System.out.println("GET(apples): " + client.get("apples").get()); | ||
|
||
} catch (ExecutionException | InterruptedException e) { | ||
System.out.println("Glide example failed with an exception: "); | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ rootProject.name = 'glide' | |
|
||
include 'client' | ||
include 'integTest' | ||
include 'examples' | ||
include 'benchmarks' |