LettuSearch

Java client for RediSearch based on Lettuce

License

License

Categories

Categories

Redis Data Databases Search Business Logic Libraries
GroupId

GroupId

com.redislabs
ArtifactId

ArtifactId

lettusearch
Last Version

Last Version

3.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

LettuSearch
Java client for RediSearch based on Lettuce
Project URL

Project URL

https://github.com/RediSearch/lettusearch
Source Code Management

Source Code Management

https://github.com/RediSearch/lettusearch

Download lettusearch

How to add to project

<!-- https://jarcasting.com/artifacts/com.redislabs/lettusearch/ -->
<dependency>
    <groupId>com.redislabs</groupId>
    <artifactId>lettusearch</artifactId>
    <version>3.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.redislabs/lettusearch/
implementation 'com.redislabs:lettusearch:3.1.2'
// https://jarcasting.com/artifacts/com.redislabs/lettusearch/
implementation ("com.redislabs:lettusearch:3.1.2")
'com.redislabs:lettusearch:jar:3.1.2'
<dependency org="com.redislabs" name="lettusearch" rev="3.1.2">
  <artifact name="lettusearch" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.redislabs', module='lettusearch', version='3.1.2')
)
libraryDependencies += "com.redislabs" % "lettusearch" % "3.1.2"
[com.redislabs/lettusearch "3.1.2"]

Dependencies

compile (1)

Group / Artifact Type Version
io.lettuce : lettuce-core jar 6.1.0.RELEASE

Project Modules

There are no modules declared in this project.

LettuSearch

License Latest Actions Codecov Language grade: Java Known Vulnerabilities

Forum Discord

Java client for RediSearch based on Lettuce

⚠️
LettuSearch has been merged into multi-module client Mesclun. Updates will now happen in Mesclun.

Getting Started

Add LettuSearch to your application dependencies:

Gradle
dependencies {
    implementation 'com.redislabs:lettusearch:x.y.x'
}
Maven
<dependency>
    <groupId>com.redislabs</groupId>
    <artifactId>lettusearch</artifactId>
    <version>x.y.z</version>
</dependency>

Basic Usage

RediSearchClient client = RediSearchClient.create(RedisURI.create(host, port)); // (1)
StatefulRediSearchConnection<String, String> connection = client.connect(); // (2)
RediSearchCommands<String, String> commands = connection.sync(); // (3)
commands.create("beers", Field.text("name").build()); // (4)
commands.hmset("beer:1", Map.of("name", "Chouffe")); // (5)
SearchResults<String, String> results = commands.search("beers", "chou*"); // (6)
System.out.println("Found " + results.getCount() + " documents matching query");
for (Document<String, String> doc : results) {
    System.out.println(doc);
}
  1. Create a RediSearch client

  2. Connect to RediSearch

  3. Use sync, async, or reactive commands

  4. Create an index

  5. Add a document to the index

  6. Search the index

Pipelining

RediSearchAsyncCommands<String, String> commands = connection.async(); // (1)
commands.setAutoFlushCommands(false); // (2)
List<RedisFuture<?>> futures = new ArrayList<>();
for (java.util.Map<String, String> doc : docs) {
    RedisFuture<String> future = commands.hmset(doc.get("id"), doc);// (3)
    futures.add(future); // (4)
}
commands.flushCommands(); // (5)
for (RedisFuture<?> future : futures) {
    try {
        future.get(1, TimeUnit.SECONDS); // (6)
    } catch (InterruptedException e) {
        log.debug("Command interrupted", e);
    } catch (ExecutionException e) {
        log.error("Command execution returned an error", e);
    } catch (TimeoutException e) {
        log.error("Command timed out", e);
    }
}
commands.setAutoFlushCommands(true); // (7)
  1. Use async commands

  2. Disable automatic flushing of commands

  3. Call commands to be executed in the pipeline

  4. Add command execution future to the list

  5. Flush commands

  6. Wait for response from each future

  7. Disable automatic flushing of commands

Connection pooling

GenericObjectPoolConfig<StatefulRediSearchConnection<String, String>> config = new GenericObjectPoolConfig<>(); // (1)
config.setMaxTotal(8);
// config.setX...
GenericObjectPool<StatefulRediSearchConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(client::connect, config); // (2)
try (StatefulRediSearchConnection<String, String> connection = pool.borrowObject()) { // (3)
    RediSearchAsyncCommands<String, String> commands = connection.async(); // (4)
    // ...
}
  1. Create a connection pool configuration

  2. Create the connection pool

  3. In worker threads, get connections in a try-with statement to automatically return them to the pool

  4. Use sync or async commands

com.redislabs
A query and indexing engine for Redis, providing secondary indexing, full-text search, and aggregations.

Versions

Version
3.1.2
3.1.1
3.1.0
3.0.1
3.0.0
2.6.1
2.6.0
2.5.1
2.5.0
2.4.4
2.4.3
2.4.2
2.4.1
2.4.0
2.3.2
2.3.1
2.3.0
2.2.1
2.1.1
2.1.0
2.0.1
2.0.0
1.13.2
1.13.1
1.13.0
1.12.8
1.12.6
1.12.5
1.12.3
1.12.1
1.12.0
1.11.2
1.10.0
1.9.1
1.9.0
1.8.0
1.7.3
1.7.2
1.7.1
1.7.0
1.6.0
1.5.3
1.5.2
1.5.1
1.5.0
1.4.2
1.4.0
1.3.0
1.2.0
1.1.10
1.1.9
1.1.8
1.1.7
1.1.6
1.1.4
1.1.2
1.1.1
1.1.0
1.0.4
1.0.3
1.0.0