Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/redis/lettucemod
Java client for Redis Modules
https://github.com/redis/lettucemod
client java lettuce modules redis redisearch redisgears redisjson redismod redistimeseries spring
Last synced: about 6 hours ago
JSON representation
Java client for Redis Modules
- Host: GitHub
- URL: https://github.com/redis/lettucemod
- Owner: redis
- License: apache-2.0
- Created: 2020-11-25T06:04:35.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-17T01:43:19.000Z (3 months ago)
- Last Synced: 2025-01-03T21:10:00.823Z (7 days ago)
- Topics: client, java, lettuce, modules, redis, redisearch, redisgears, redisjson, redismod, redistimeseries, spring
- Language: Java
- Homepage:
- Size: 1.86 MB
- Stars: 52
- Watchers: 5
- Forks: 21
- Open Issues: 16
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= LettuceMod
:linkattrs:
:icons: font
:project-owner: redis
:project-name: lettucemod
:project-group: com.redis
:project-version: 4.1.2image:https://github.com/{project-owner}/{project-name}/actions/workflows/early-access.yml/badge.svg["Build Status",link="https://github.com/{project-owner}/{project-name}/actions/workflows/early-access.yml"]
image:https://img.shields.io/maven-central/v/{project-group}/{project-name}[Download,link="https://search.maven.org/#search|ga|1|{project-name}"]
image:https://img.shields.io/github/license/{project-owner}/{project-name}["License",link="https://github.com/{project-owner}/{project-name}"]
image:https://codecov.io/gh/{project-owner}/{project-name}/branch/master/graph/badge.svg["Coverage", link="https://codecov.io/gh/{project-owner}/{project-name}"]LettuceMod is a Java client for https://redis.io/docs/about/about-stack/[Redis Stack] based on https://lettuce.io[Lettuce].
It supports the following Redis Stack features:* https://redis.io/docs/data-types/json/[JSON data type] (storing, updating, and fetching)
* https://redis.io/docs/interact/search-and-query/[Search and query] of hashes and JSON documents
* https://redis.io/docs/data-types/timeseries/[Time series] data support
* https://redis.io/docs/data-types/probabilistic/[Probabilistic data structures]
** https://redis.io/docs/data-types/probabilistic/bloom-filter/[Bloom filter]
** https://redis.io/docs/data-types/probabilistic/cuckoo-filter/[Cuckoo filter]
** https://redis.io/docs/data-types/probabilistic/t-digest/[t-digest]
** https://redis.io/docs/data-types/probabilistic/top-k/[Top-K]
** https://redis.io/docs/data-types/probabilistic/count-min-sketch/[Count-min sketch]== Getting Started
=== Java
.Maven
[source,xml,subs="verbatim,attributes"]
----{project-group}
{project-name}
{project-version}----
.Gradle
[source,groovy,subs="verbatim,attributes"]
----
dependencies {
implementation '{project-group}:{project-name}:{project-version}'
}
----=== Spring
.Maven
[source,xml,subs="verbatim,attributes"]
----{project-group}
lettucemod-spring
{project-version}----
.Gradle
[source,groovy,subs="verbatim,attributes"]
----
dependencies {
implementation '{project-group}:lettucemod-spring:{project-version}'
}
----=== Snapshot Releases
For early-access releases use the following repository:
https://s01.oss.sonatype.org/content/repositories/snapshots/
.Maven
[source,xml]
----
oss.sonatype.org-snapshot
https://s01.oss.sonatype.org/content/repositories/snapshots
false
true
----
.Gradle
[source,groovy]
----
repositories {
maven {
url "https://s01.oss.sonatype.org/content/repositories/snapshots/"
}
}
----== Usage
=== Java
==== Standalone Client
[source,java]
----
RedisModulesClient client = RedisModulesClient.create("redis://localhost:6379"); // <1>
StatefulRedisModulesConnection connection = client.connect(); // <2>
RedisModulesCommands commands = connection.sync(); // <3>
----<1> Create a modules client
<2> Connect to Redis server==== Cluster Client
[source,java]
----
List uris = Arrays.asList(RedisURI.create("node1", 6379), RedisURI.create("node2", 6379)); // <1>
RedisModulesClusterClient client = RedisModulesClusterClient.create(uris); // <2>
StatefulRedisModulesClusterConnection connection = client.connect(); // <3>
RedisModulesAdvancedClusterCommands commands = connection.sync(); // <4>
----<1> Create list of cluster node URIs
<2> Create a cluster client
<3> Connect to Redis servers
<4> Use the sync, async, or reactive API==== Connection Pool
[source,java]
----
GenericObjectPoolConfig> config = new GenericObjectPoolConfig<>();
config.setMaxTotal(4); // <1>
// ...
GenericObjectPool> pool = ConnectionPoolSupport.createGenericObjectPool(client::connect, config); // <2>
----<1> Create a pool configuration
<2> Create the connection pool=== Spring
==== Client
[source,java]
----
@Component
public class MyComponent {@Autowired
StatefulRedisModulesConnection connection;// ...
}
----==== Connection Pool
[source,java]
----
@Component
public class MyComponent {@Autowired
GenericObjectPool> pool;// ...
}
----=== Commands
[source,java]
----
RedisModulesCommands commands = connection.sync();// JSON.SET
commands.jsonSet("arr", ".", "[1,2,3]");// FT.CREATE
commands.ftCreate("beers", Field.text("name").build(), Field.numeric("ibu").build());// FT.SEARCH
commands.ftSearch("beers", "chou*");// TS.ADD
commands.tsAdd("temp:3:11", Sample.of(1548149181, 30));// BF.EXISTS
commands.bfExists("bloom:1", "test");// CF.EXISTS
commands.cfExists("cuckoo:1", "one");// CMS.QUERY
commands.cmsQuery("cms:1", "one", "two", "three");// TDIGEST.RANK
commands.tDigestRank("tdigest:1", -5, 100, 5.3);// TOPK.QUERY
commands.topKQuery("topk:1", "four", "three", "two", "foo");
----=== Pipelining
[source,java]
----
RedisModulesAsyncCommands commands = connection.async();
commands.setAutoFlushCommands(false); // <1>
List> futures = new ArrayList<>(); // <2>
for (MyEntity element : entities()) {
futures.add(commands.ftSugadd("names", Suggestion.of(element.getName(), element.getScore())));
}
commands.flushCommands(); // <3>
boolean result = LettuceFutures.awaitAll(5, TimeUnit.SECONDS,
futures.toArray(new RedisFuture[0])); // <4>
connection.close(); // <5>
----<1> Disable auto-flushing
<2> Perform a series of independent calls
<3> Write all commands to the transport layer
<4> Synchronization example: Wait until all futures complete
<5> Later=== Connection Pooling
[source,java]
----
GenericObjectPoolConfig> config = new GenericObjectPoolConfig<>(); // <1>
config.setMaxTotal(16);
// ...
GenericObjectPool> pool = ConnectionPoolSupport.createGenericObjectPool(client::connect, config); // <2>
try (StatefulRedisModulesConnection connection = pool.borrowObject()) { // <3>
RedisModulesAsyncCommands commands = connection.async(); // <4>
// ...
} catch (Exception e) {
log.error("Could not get a connection from the pool", e);
}
----<1> Create a pool configuration
<2> Create the connection pool
<3> Get connection from pool. Try-with automatically closes connection which returns it to pool
<4> Use sync, async, or reactive commands