Skip to content

Commit

Permalink
Merge branch 'master' into stream-entry-support-binary
Browse files Browse the repository at this point in the history
  • Loading branch information
thachlp authored Sep 28, 2024
2 parents 5c11bf7 + 5442642 commit c39c17f
Show file tree
Hide file tree
Showing 162 changed files with 9,843 additions and 588 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

2 changes: 2 additions & 0 deletions .github/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ EVAL
EVALSHA
Failback
Failover
FTCreateParams
FTSearchParams
GSON
GenericObjectPool
GenericObjectPoolConfig
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
env:
JVM_OPTS: -Xmx3200m
TERM: dumb
- name: Codecov
run: |
bash <(curl -s https://codecov.io/bash)
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
46 changes: 42 additions & 4 deletions docs/redisearch.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RediSearch Jedis Quick Start

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

## Creating the RediSearch client

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

## Indexing and querying

### Indexing

Defining a schema for an index and creating it:

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

Alternatively, we can create the same index using FTCreateParams:

```java
client.ftCreate("item-index",

FTCreateParams.createParams()
.prefix("item:", "product:")
.filter("@price>100"),

TextField.of("title").weight(5.0),
TextField.of("body"),
NumericField.of("price")
);
```

### Inserting

Adding documents to the index:

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

Another way to insert documents:

```java
client.hsetObject("item:hw", fields);
```

### Querying

Searching the index:

```java
// creating a complex query
Query q = new Query("hello world")
.addFilter(new Query.NumericFilter("price", 0, 1000))
.limit(0, 5);

// actual search
SearchResult sr = client.ftSearch("item-index", q);
```

Alternative searching using FTSearchParams:

// aggregation query
```java
SearchResult sr = client.ftSearch("item-index",
"hello world",
FTSearchParams.searchParams()
.filter("price", 0, 1000)
.limit(0, 5));
```

Aggregation query:

```java
AggregationBuilder ab = new AggregationBuilder("hello")
.apply("@price/1000", "k")
.groupBy("@state", Reducers.avg("@k").as("avgprice"))
Expand Down
20 changes: 18 additions & 2 deletions docs/redisjson.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,37 @@ If we want to be able to query this JSON, we'll need to create an index. Let's c
3. Then we actually create the index, called "student-index", by calling `ftCreate()`.

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

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

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

Alternatively creating the same index using FTCreateParams:

```java
client.ftCreate("student-index",
FTCreateParams.createParams().on(IndexDataType.JSON).prefix("student:"),
TextField.of("$.firstName"), TextField.of("$.lastName"));
```

With an index now defined, we can query our JSON. Let's find all students whose name begins with "maya":

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

Same query can be done using FTSearchParams:

```java
SearchResult mayaSearch = client.ftSearch("student-index",
"@\\$\\.firstName:maya*",
FTSearchParams.searchParams());
```

We can then iterate over our search results:

```java
Expand Down
33 changes: 21 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<jedis.module.name>redis.clients.jedis</jedis.module.name>
<slf4j.version>1.7.36</slf4j.version>
<resilience4j.version>1.7.1</resilience4j.version>
<jackson.version>2.17.1</jackson.version>
<maven.surefire.version>3.2.5</maven.surefire.version>
<jackson.version>2.17.2</jackson.version>
<maven.surefire.version>3.5.0</maven.surefire.version>
</properties>

<dependencies>
Expand All @@ -72,24 +72,27 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
<version>2.11.0</version>
</dependency>

<!-- Optional dependencies -->

<!-- UNIX socket connection support -->
<dependency>
<groupId>com.kohlschutter.junixsocket</groupId>
<artifactId>junixsocket-core</artifactId>
<version>2.9.1</version>
<version>2.10.0</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<!-- Well-known text representation of geometry in RediSearch support -->
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.19.0</version>
<version>1.20.0</version>
<scope>test</scope>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
Expand All @@ -100,7 +103,7 @@
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -130,7 +133,13 @@
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit</artifactId>
<version>2.38.0</version> <!-- 3.x requires Java 17 -->
<version>2.40.1</version> <!-- 3.x requires Java 17 -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5-fluent</artifactId>
<version>5.4</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -231,7 +240,7 @@
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.3</version>
<version>3.10.0</version>
<configuration>
<source>8</source><!-- Until JDK 11+ -->
<detectJavaApiLink>false</detectJavaApiLink><!-- Until JDK 11+ -->
Expand All @@ -249,12 +258,12 @@
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.1</version>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -272,7 +281,7 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
Expand Down Expand Up @@ -306,7 +315,7 @@
<!--Sign the components - this is required by maven central for releases -->
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.4</version>
<version>3.2.6</version>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/redis/clients/jedis/AbstractTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

public abstract class AbstractTransaction extends PipeliningBase implements Closeable {

@Deprecated
protected AbstractTransaction() {
super(new CommandObjects());
}
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ public Object build(Object data) {

if (data instanceof List) {
final List list = (List) data;
if (list.isEmpty()) return Collections.emptyMap();
if (list.isEmpty()) {
return list == Protocol.PROTOCOL_EMPTY_MAP ? Collections.emptyMap() : Collections.emptyList();
}

if (list.get(0) instanceof KeyValue) {
return ((List<KeyValue>) data).stream()
Expand All @@ -397,8 +399,9 @@ public Object build(Object data) {
}
} else if (data instanceof byte[]) {
return STRING.build(data);
} else {
return data;
}
return data;
}
};

Expand Down Expand Up @@ -595,10 +598,9 @@ public String toString() {
@Override
@SuppressWarnings("unchecked")
public KeyValue<String, Tuple> build(Object data) {
List<Object> l = (List<Object>) data; // never null
if (l.isEmpty()) {
return null;
}
if (data == null) return null;
List<Object> l = (List<Object>) data;
if (l.isEmpty()) return null;
return KeyValue.of(STRING.build(l.get(0)), new Tuple(BINARY.build(l.get(1)), DOUBLE.build(l.get(2))));
}

Expand All @@ -612,10 +614,9 @@ public String toString() {
@Override
@SuppressWarnings("unchecked")
public KeyValue<byte[], Tuple> build(Object data) {
List<Object> l = (List<Object>) data; // never null
if (l.isEmpty()) {
return null;
}
if (data == null) return null;
List<Object> l = (List<Object>) data;
if (l.isEmpty()) return null;
return KeyValue.of(BINARY.build(l.get(0)), new Tuple(BINARY.build(l.get(1)), DOUBLE.build(l.get(2))));
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/redis/clients/jedis/ClusterCommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public class ClusterCommandObjects extends CommandObjects {

@Override
protected ClusterCommandArguments commandArguments(ProtocolCommand command) {
return new ClusterCommandArguments(command);
ClusterCommandArguments comArgs = new ClusterCommandArguments(command);
if (keyPreProcessor != null) comArgs.setKeyArgumentPreProcessor(keyPreProcessor);
return comArgs;
}

private static final String CLUSTER_UNSUPPORTED_MESSAGE = "Not supported in cluster mode.";
Expand Down
Loading

0 comments on commit c39c17f

Please sign in to comment.