Skip to content

Commit c2e2e18

Browse files
committed
fix examples
1 parent 70c68cc commit c2e2e18

File tree

1 file changed

+69
-42
lines changed

1 file changed

+69
-42
lines changed

java/README.md

Lines changed: 69 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Example shown below is for `glide-osx-aarch_64`.
113113
dependencies {
114114
testImplementation platform('org.junit:junit-bom:5.10.0')
115115
testImplementation 'org.junit.jupiter:junit-jupiter'
116-
implementation group: 'software.amazon.glide', name: 'glide-osx-aarch_64', version: '0.4.2'
116+
implementation group: 'software.amazon.glide', name: 'glide-for-redis', version: '0.4.3'
117117
}
118118
```
119119

@@ -133,72 +133,99 @@ Maven (AARCH_64) specific.
133133
### Standalone Valkey:
134134

135135
```java
136+
// You can run this example code in the Main.
136137
import glide.api.RedisClient;
137138
import glide.api.models.configuration.NodeAddress;
138139
import glide.api.models.configuration.RedisClientConfiguration;
139-
140140
import java.util.concurrent.ExecutionException;
141+
141142
import static glide.api.models.GlideString.gs;
142143

143-
// Run this code in the Main file. Include InterruptedException and ExecutionException handling.
144+
public class Main {
144145

145-
public static void main(String[] args) throws InterruptedException, ExecutionException {
146+
public static void main(String[] args) {
147+
runGlideExamples();
148+
}
146149

147-
String host = "localhost";
148-
Integer port = 6379;
149-
boolean useSsl = false;
150+
private static void runGlideExamples() {
151+
String host = "localhost";
152+
Integer port = 6379;
153+
boolean useSsl = false;
150154

151-
RedisClientConfiguration config =
152-
RedisClientConfiguration.builder()
153-
.address(NodeAddress.builder().host(host).port(port).build())
154-
.useTLS(useSsl)
155-
.build();
155+
RedisClientConfiguration config =
156+
RedisClientConfiguration.builder()
157+
.address(NodeAddress.builder().host(host).port(port).build())
158+
.useTLS(useSsl)
159+
.build();
156160

157-
RedisClient client = RedisClient.CreateClient(config).get();
161+
try {
162+
RedisClient client = RedisClient.CreateClient(config).get();
158163

159-
System.out.println("PING: " + client.ping().get());
160-
System.out.println("PING(found you): " + client.ping("found you").get());
164+
// TODO wait for this PR to get merged https://github.com/aws/glide-for-redis/pull/1663/ for PING to work.
165+
System.out.println("PING: " + client.ping(gs("PING")).get());
166+
System.out.println("PING(found you): " + client.ping( gs("found you")).get());
161167

162-
System.out.println("SET(apples, oranges): " + client.set("apples", "oranges").get());
163-
System.out.println("GET(apples): " + client.get("apples").get());
168+
System.out.println("SET(apples, oranges): " + client.set(gs("apples"), gs("oranges")).get());
169+
System.out.println("GET(apples): " + client.get(gs("apples")).get());
164170

165-
System.out.println("GLIDESTRINGSET(cats, meow): " + client.set(gs("cats"), gs("meow")).get());
166-
System.out.println("GET(cats): " + client.get("cats").get());
171+
} catch (ExecutionException | InterruptedException e) {
172+
System.out.println("Glide example failed with an exception: ");
173+
e.printStackTrace();
174+
}
175+
}
176+
}
167177
}
168178
```
169179

170180
### Cluster Valkey:
171181
```java
172-
173182
import glide.api.RedisClusterClient;
174183
import glide.api.models.configuration.NodeAddress;
175184
import glide.api.models.configuration.RedisClusterClientConfiguration;
185+
import glide.api.models.configuration.RequestRoutingConfiguration;
176186

177187
import java.util.concurrent.ExecutionException;
178-
import static glide.api.models.GlideString.gs;
179-
180-
// Run this code in the Main file. Include InterruptedException and ExecutionException handling.
181188

182-
String host = "localhost";
183-
Integer port = 6379;
184-
boolean useSsl = false;
185-
186-
RedisClusterClientConfiguration config =
187-
RedisClusterClientConfiguration.builder()
188-
.address(NodeAddress.builder().host(host).port(port).build())
189-
.useTLS(useSsl)
190-
.build();
191-
192-
RedisClusterClient client = RedisClusterClient.CreateClient(config).get();
193-
194-
System.out.println("PING: " + client.ping().get());
195-
System.out.println("PING(found you): " + client.ping("found you").get());
196-
197-
System.out.println("SET(apples, oranges): " + client.set("apples", "oranges").get());
198-
System.out.println("GET(apples): " + client.get("apples").get());
189+
import static glide.api.models.GlideString.gs;
199190

200-
System.out.println("GLIDESTRINGSET(cats, meow): " + client.set(gs("cats"), gs("meow")).get());
201-
System.out.println("GET(cats): " + client.get("cats").get());
191+
public class Main {
192+
193+
public static void main(String[] args) {
194+
runGlideExamples();
195+
}
196+
197+
private static void runGlideExamples() {
198+
String host = "localhost";
199+
Integer port1 = 7001;
200+
Integer port2 = 7002;
201+
Integer port3 = 7003;
202+
Integer port4 = 7004;
203+
Integer port5 = 7005;
204+
Integer port6 = 7006;
205+
boolean useSsl = false;
206+
207+
RedisClusterClientConfiguration config =
208+
RedisClusterClientConfiguration.builder()
209+
.address(NodeAddress.builder().host(host).port(port1).port(port2).port(port3).port(port4).port(port5).port(port6).build())
210+
.useTLS(useSsl)
211+
.build();
212+
213+
try {
214+
RedisClusterClient client = RedisClusterClient.CreateClient(config).get();
215+
216+
// TODO wait for this PR to get merged https://github.com/aws/glide-for-redis/pull/1663/ for PING to work.
217+
System.out.println("PING: " + client.ping(gs("PING")).get());
218+
System.out.println("PING(found you): " + client.ping( gs("found you")).get());
219+
220+
System.out.println("SET(apples, oranges): " + client.set(gs("apples"), gs("oranges")).get());
221+
System.out.println("GET(apples): " + client.get(gs("apples")).get());
222+
223+
} catch (ExecutionException | InterruptedException e) {
224+
System.out.println("Glide example failed with an exception: ");
225+
e.printStackTrace();
226+
}
227+
}
228+
}
202229
```
203230

204231
### Benchmarks

0 commit comments

Comments
 (0)