Skip to content

Commit 747e391

Browse files
authored
Merge branch 'master' into 5.2.0
2 parents eb7e9fe + ac2a4e0 commit 747e391

15 files changed

+157
-84
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ EVAL
2020
EVALSHA
2121
Failback
2222
Failover
23+
FTCreateParams
24+
FTSearchParams
2325
GSON
2426
GenericObjectPool
2527
GenericObjectPoolConfig

.github/workflows/integration.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ jobs:
5555
env:
5656
JVM_OPTS: -Xmx3200m
5757
TERM: dumb
58-
- name: Codecov
59-
run: |
60-
bash <(curl -s https://codecov.io/bash)
58+
- name: Upload coverage to Codecov
59+
uses: codecov/codecov-action@v4
60+
with:
61+
fail_ci_if_error: false
62+
token: ${{ secrets.CODECOV_TOKEN }}

docs/redisearch.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# RediSearch Jedis Quick Start
22

3-
To use RediSearch features with Jedis, you'll need to use and implementation of RediSearchCommands.
3+
To use RediSearch features with Jedis, you'll need to use an implementation of RediSearchCommands.
44

55
## Creating the RediSearch client
66

@@ -22,6 +22,8 @@ JedisCluster client = new JedisCluster(nodes);
2222

2323
## Indexing and querying
2424

25+
### Indexing
26+
2527
Defining a schema for an index and creating it:
2628

2729
```java
@@ -37,6 +39,23 @@ IndexDefinition def = new IndexDefinition()
3739
client.ftCreate("item-index", IndexOptions.defaultOptions().setDefinition(def), sc);
3840
```
3941

42+
Alternatively, we can create the same index using FTCreateParams:
43+
44+
```java
45+
client.ftCreate("item-index",
46+
47+
FTCreateParams.createParams()
48+
.prefix("item:", "product:")
49+
.filter("@price>100"),
50+
51+
TextField.of("title").weight(5.0),
52+
TextField.of("body"),
53+
NumericField.of("price")
54+
);
55+
```
56+
57+
### Inserting
58+
4059
Adding documents to the index:
4160

4261
```java
@@ -49,18 +68,37 @@ fields.put("price", 1337);
4968
client.hset("item:hw", RediSearchUtil.toStringMap(fields));
5069
```
5170

71+
Another way to insert documents:
72+
73+
```java
74+
client.hsetObject("item:hw", fields);
75+
```
76+
77+
### Querying
78+
5279
Searching the index:
5380

5481
```java
55-
// creating a complex query
5682
Query q = new Query("hello world")
5783
.addFilter(new Query.NumericFilter("price", 0, 1000))
5884
.limit(0, 5);
5985

60-
// actual search
6186
SearchResult sr = client.ftSearch("item-index", q);
87+
```
88+
89+
Alternative searching using FTSearchParams:
6290

63-
// aggregation query
91+
```java
92+
SearchResult sr = client.ftSearch("item-index",
93+
"hello world",
94+
FTSearchParams.searchParams()
95+
.filter("price", 0, 1000)
96+
.limit(0, 5));
97+
```
98+
99+
Aggregation query:
100+
101+
```java
64102
AggregationBuilder ab = new AggregationBuilder("hello")
65103
.apply("@price/1000", "k")
66104
.groupBy("@state", Reducers.avg("@k").as("avgprice"))

docs/redisjson.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,37 @@ If we want to be able to query this JSON, we'll need to create an index. Let's c
8181
3. Then we actually create the index, called "student-index", by calling `ftCreate()`.
8282

8383
```java
84-
Schema schema = new Schema().addTextField("$.firstName", 1.0).addTextField("$" + ".lastName", 1.0);
84+
Schema schema = new Schema().addTextField("$.firstName", 1.0).addTextField("$.lastName", 1.0);
8585

8686
IndexDefinition rule = new IndexDefinition(IndexDefinition.Type.JSON)
8787
.setPrefixes(new String[]{"student:"});
8888

8989
client.ftCreate("student-index", IndexOptions.defaultOptions().setDefinition(rule), schema);
9090
```
9191

92+
Alternatively creating the same index using FTCreateParams:
93+
94+
```java
95+
client.ftCreate("student-index",
96+
FTCreateParams.createParams().on(IndexDataType.JSON).prefix("student:"),
97+
TextField.of("$.firstName"), TextField.of("$.lastName"));
98+
```
99+
92100
With an index now defined, we can query our JSON. Let's find all students whose name begins with "maya":
93101

94102
```java
95-
Query q = new Query("@\\$\\" + ".firstName:maya*");
103+
Query q = new Query("@\\$\\.firstName:maya*");
96104
SearchResult mayaSearch = client.ftSearch("student-index", q);
97105
```
98106

107+
Same query can be done using FTSearchParams:
108+
109+
```java
110+
SearchResult mayaSearch = client.ftSearch("student-index",
111+
"@\\$\\.firstName:maya*",
112+
FTSearchParams.searchParams());
113+
```
114+
99115
We can then iterate over our search results:
100116

101117
```java

src/main/java/redis/clients/jedis/BuilderFactory.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,9 @@ public String toString() {
598598
@Override
599599
@SuppressWarnings("unchecked")
600600
public KeyValue<String, Tuple> build(Object data) {
601-
List<Object> l = (List<Object>) data; // never null
602-
if (l.isEmpty()) {
603-
return null;
604-
}
601+
if (data == null) return null;
602+
List<Object> l = (List<Object>) data;
603+
if (l.isEmpty()) return null;
605604
return KeyValue.of(STRING.build(l.get(0)), new Tuple(BINARY.build(l.get(1)), DOUBLE.build(l.get(2))));
606605
}
607606

@@ -615,10 +614,9 @@ public String toString() {
615614
@Override
616615
@SuppressWarnings("unchecked")
617616
public KeyValue<byte[], Tuple> build(Object data) {
618-
List<Object> l = (List<Object>) data; // never null
619-
if (l.isEmpty()) {
620-
return null;
621-
}
617+
if (data == null) return null;
618+
List<Object> l = (List<Object>) data;
619+
if (l.isEmpty()) return null;
622620
return KeyValue.of(BINARY.build(l.get(0)), new Tuple(BINARY.build(l.get(1)), DOUBLE.build(l.get(2))));
623621
}
624622

src/main/java/redis/clients/jedis/Connection.java

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Connection(final JedisSocketFactory socketFactory, JedisClientConfig clie
7171

7272
@Override
7373
public String toString() {
74-
return "Connection{" + socketFactory + "}";
74+
return getClass().getSimpleName() + "{" + socketFactory + "}";
7575
}
7676

7777
@Experimental
@@ -80,52 +80,22 @@ public String toIdentityString() {
8080
return strVal;
8181
}
8282

83+
String className = getClass().getSimpleName();
8384
int id = hashCode();
84-
String classInfo = getClass().toString();
8585

8686
if (socket == null) {
87-
StringBuilder buf = new StringBuilder(56)
88-
.append("[")
89-
.append(classInfo)
90-
.append(", id: 0x")
91-
.append(id)
92-
.append(']');
93-
return buf.toString();
87+
return String.format("%s{id: 0x%X}", className, id);
9488
}
9589

9690
SocketAddress remoteAddr = socket.getRemoteSocketAddress();
9791
SocketAddress localAddr = socket.getLocalSocketAddress();
9892
if (remoteAddr != null) {
99-
StringBuilder buf = new StringBuilder(101)
100-
.append("[")
101-
.append(classInfo)
102-
.append(", id: 0x")
103-
.append(id)
104-
.append(", L:")
105-
.append(localAddr)
106-
.append(broken ? " ! " : " - ")
107-
.append("R:")
108-
.append(remoteAddr)
109-
.append(']');
110-
strVal = buf.toString();
93+
strVal = String.format("%s{id: 0x%X, L:%s %c R:%s}", className, id,
94+
localAddr, (broken ? '!' : '-'), remoteAddr);
11195
} else if (localAddr != null) {
112-
StringBuilder buf = new StringBuilder(64)
113-
.append("[")
114-
.append(classInfo)
115-
.append(", id: 0x")
116-
.append(id)
117-
.append(", L:")
118-
.append(localAddr)
119-
.append(']');
120-
strVal = buf.toString();
96+
strVal = String.format("%s{id: 0x%X, L:%s}", className, id, localAddr);
12197
} else {
122-
StringBuilder buf = new StringBuilder(56)
123-
.append("[")
124-
.append(classInfo)
125-
.append(", id: 0x")
126-
.append(id)
127-
.append(']');
128-
strVal = buf.toString();
98+
strVal = String.format("%s{id: 0x%X}", className, id);
12999
}
130100

131101
strValActive = broken;
@@ -154,7 +124,7 @@ public void setSoTimeout(int soTimeout) {
154124
try {
155125
this.socket.setSoTimeout(soTimeout);
156126
} catch (SocketException ex) {
157-
broken = true;
127+
setBroken();
158128
throw new JedisConnectionException(ex);
159129
}
160130
}
@@ -167,7 +137,7 @@ public void setTimeoutInfinite() {
167137
}
168138
socket.setSoTimeout(infiniteSoTimeout);
169139
} catch (SocketException ex) {
170-
broken = true;
140+
setBroken();
171141
throw new JedisConnectionException(ex);
172142
}
173143
}
@@ -176,7 +146,7 @@ public void rollbackTimeout() {
176146
try {
177147
socket.setSoTimeout(this.soTimeout);
178148
} catch (SocketException ex) {
179-
broken = true;
149+
setBroken();
180150
throw new JedisConnectionException(ex);
181151
}
182152
}
@@ -243,7 +213,7 @@ public void sendCommand(final CommandArguments args) {
243213
*/
244214
}
245215
// Any other exceptions related to connection?
246-
broken = true;
216+
setBroken();
247217
throw ex;
248218
}
249219
}
@@ -396,7 +366,7 @@ protected void flush() {
396366
try {
397367
outputStream.flush();
398368
} catch (IOException ex) {
399-
broken = true;
369+
setBroken();
400370
throw new JedisConnectionException(ex);
401371
}
402372
}
@@ -436,7 +406,7 @@ protected void readPushesWithCheckingBroken() {
436406
broken = true;
437407
throw new JedisConnectionException("Failed to check buffer on connection.", e);
438408
} catch (JedisConnectionException exc) {
439-
broken = true;
409+
setBroken();
440410
throw exc;
441411
}
442412
}
@@ -522,8 +492,8 @@ protected void initializeFromClientConfig(final JedisClientConfig config) {
522492
}
523493
}
524494

525-
// set readonly flag to ALL connections (including master nodes) when enable read from replica
526-
if (config.isReadOnlyForReplica()) {
495+
// set READONLY flag to ALL connections (including master nodes) when enable read from replica
496+
if (config.isReadOnlyForRedisClusterReplicas()) {
527497
fireAndForgetMsg.add(new CommandArguments(Command.READONLY));
528498
}
529499

src/main/java/redis/clients/jedis/DefaultJedisClientConfig.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public final class DefaultJedisClientConfig implements JedisClientConfig {
2626

2727
private final ClientSetInfoConfig clientSetInfoConfig;
2828

29-
private final boolean readOnlyForReplica;
29+
private final boolean readOnlyForRedisClusterReplicas;
3030

3131
private DefaultJedisClientConfig(RedisProtocol protocol, int connectionTimeoutMillis, int soTimeoutMillis,
3232
int blockingSocketTimeoutMillis, Supplier<RedisCredentials> credentialsProvider, int database,
3333
String clientName, boolean ssl, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
3434
HostnameVerifier hostnameVerifier, HostAndPortMapper hostAndPortMapper,
35-
ClientSetInfoConfig clientSetInfoConfig, boolean readOnlyForReplica) {
35+
ClientSetInfoConfig clientSetInfoConfig, boolean readOnlyForRedisClusterReplicas) {
3636
this.redisProtocol = protocol;
3737
this.connectionTimeoutMillis = connectionTimeoutMillis;
3838
this.socketTimeoutMillis = soTimeoutMillis;
@@ -46,7 +46,7 @@ private DefaultJedisClientConfig(RedisProtocol protocol, int connectionTimeoutMi
4646
this.hostnameVerifier = hostnameVerifier;
4747
this.hostAndPortMapper = hostAndPortMapper;
4848
this.clientSetInfoConfig = clientSetInfoConfig;
49-
this.readOnlyForReplica = readOnlyForReplica;
49+
this.readOnlyForRedisClusterReplicas = readOnlyForRedisClusterReplicas;
5050
}
5151

5252
@Override
@@ -126,8 +126,8 @@ public ClientSetInfoConfig getClientSetInfoConfig() {
126126
}
127127

128128
@Override
129-
public boolean isReadOnlyForReplica() {
130-
return readOnlyForReplica;
129+
public boolean isReadOnlyForRedisClusterReplicas() {
130+
return readOnlyForRedisClusterReplicas;
131131
}
132132

133133
public static Builder builder() {
@@ -157,7 +157,7 @@ public static class Builder {
157157

158158
private ClientSetInfoConfig clientSetInfoConfig = ClientSetInfoConfig.DEFAULT;
159159

160-
private boolean readOnlyForReplicas = false;
160+
private boolean readOnlyForRedisClusterReplicas = false;
161161

162162
private Builder() {
163163
}
@@ -171,7 +171,7 @@ public DefaultJedisClientConfig build() {
171171
return new DefaultJedisClientConfig(redisProtocol, connectionTimeoutMillis, socketTimeoutMillis,
172172
blockingSocketTimeoutMillis, credentialsProvider, database, clientName, ssl,
173173
sslSocketFactory, sslParameters, hostnameVerifier, hostAndPortMapper, clientSetInfoConfig,
174-
readOnlyForReplicas);
174+
readOnlyForRedisClusterReplicas);
175175
}
176176

177177
/**
@@ -267,8 +267,8 @@ public Builder clientSetInfoConfig(ClientSetInfoConfig setInfoConfig) {
267267
return this;
268268
}
269269

270-
public Builder readOnlyForReplicas() {
271-
this.readOnlyForReplicas = true;
270+
public Builder readOnlyForRedisClusterReplicas() {
271+
this.readOnlyForRedisClusterReplicas = true;
272272
return this;
273273
}
274274
}
@@ -290,6 +290,6 @@ public static DefaultJedisClientConfig copyConfig(JedisClientConfig copy) {
290290
copy.getBlockingSocketTimeoutMillis(), copy.getCredentialsProvider(),
291291
copy.getDatabase(), copy.getClientName(), copy.isSsl(), copy.getSslSocketFactory(),
292292
copy.getSslParameters(), copy.getHostnameVerifier(), copy.getHostAndPortMapper(),
293-
copy.getClientSetInfoConfig(), copy.isReadOnlyForReplica());
293+
copy.getClientSetInfoConfig(), copy.isReadOnlyForRedisClusterReplicas());
294294
}
295295
}

0 commit comments

Comments
 (0)