Coder Social home page Coder Social logo

lettucemod's Introduction

LettuceMod

Build Status Download License Coverage forum

LettuceMod is a Java client for Redis Modules based on Lettuce. It supports the following modules in standalone or cluster configurations:

Getting Started

Java

Maven
<dependency>
    <groupId>com.redis</groupId>
    <artifactId>lettucemod</artifactId>
    <version>3.5.0</version>
</dependency>
Gradle
dependencies {
    implementation 'com.redis:lettucemod:3.5.0'
}

Spring

Maven
<dependency>
    <groupId>com.redis</groupId>
    <artifactId>spring-lettucemod</artifactId>
    <version>3.5.0</version>
</dependency>
Gradle
dependencies {
    implementation 'com.redis:spring-lettucemod:3.5.0'
}

Snapshot Releases

For early-access releases use the following repository:

Maven
<repositories>
   <repository>
      <id>oss.sonatype.org-snapshot</id>
         <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
         <releases>
            <enabled>false</enabled>
         </releases>
         <snapshots>
           <enabled>true</enabled>
         </snapshots>
   </repository>
</repositories>
Gradle
repositories {
    maven {
        url "https://s01.oss.sonatype.org/content/repositories/snapshots/"
    }
}

Usage

Java

Standalone Client

RedisModulesClient client = RedisModulesClient.create("redis://localhost:6379"); // (1)

StatefulRedisModulesConnection<String, String> connection = client.connect(); // (2)

RedisModulesCommands<String, String> commands = connection.sync(); // (3)
  1. Create a modules client

  2. Connect to Redis server

Cluster Client

List<RedisURI> uris = Arrays.asList(RedisURI.create("node1", 6379), RedisURI.create("node2", 6379)); // (1)

RedisModulesClusterClient client = RedisModulesClusterClient.create(uris); // (2)

StatefulRedisModulesClusterConnection<String, String> connection = client.connect(); // (3)

RedisModulesAdvancedClusterCommands<String, String> 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

GenericObjectPoolConfig<StatefulRedisModulesConnection<String, String>> config = new GenericObjectPoolConfig<>();
config.setMaxTotal(4); // (1)
// ...
GenericObjectPool<StatefulRedisModulesConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(client::connect, config); // (2)
  1. Create a pool configuration

  2. Create the connection pool

Spring

Client

@Component
public class MyComponent {

    @Autowired
    StatefulRedisModulesConnection<String, String> connection;

    // ...
}

Connection Pool

@Component
public class MyComponent {

    @Autowired
    GenericObjectPool<StatefulRedisModulesConnection<String, String>> pool;

    // ...
}

RedisGears

RedisGearsCommands<String, String> gears = connection.sync(); // (1)

gears.rgPyexecute("GearsBuilder().run('person:*')"); // (2)
  1. Use sync, async, or reactive RedisGears commands

  2. Execute a RedisGears Python function

RedisJSON

RedisJSONCommands<String, String> json = connection.sync(); // (1)

json.jsonSet("arr", ".", "[1,2,3]"); // (2)
  1. Use sync, async, or reactive RedisJSON commands

  2. Set a JSON value

RediSearch

RediSearchCommands<String, String> search = connection.sync(); // (1)

search.ftCreate("beers", Field.text("name").build(), Field.numeric("ibu").build()); // (2)

SearchResults<String, String> results = search.ftSearch("beers", "chou*"); // (3)
  1. Use sync, async, or reactive RediSearch commands

  2. Create an index

  3. Search the index

RedisTimeSeries

RedisTimeSeriesCommands<String, String> ts = connection.sync(); // (1)

ts.tsAdd("temp:3:11", Sample.of(1548149181, 30)); // (2)
  1. Use sync, async, or reactive RedisTimeSeries commands

  2. Append a new sample to the series

Pipelining

RedisModulesAsyncCommands<String, String> commands = connection.async();

commands.setAutoFlushCommands(false); // (1)

List<RedisFuture<?>> 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

GenericObjectPoolConfig<StatefulRedisModulesConnection<String, String>> config = new GenericObjectPoolConfig<>(); // (1)

config.setMaxTotal(16);

// ...

GenericObjectPool<StatefulRedisModulesConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(client::connect, config); // (2)

try (StatefulRedisModulesConnection<String, String> connection = pool.borrowObject()) { // (3)

	RedisModulesAsyncCommands<String, String> 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

lettucemod's People

Contributors

jruaux avatar github-actions[bot] avatar anirbanupstox avatar jgleitz avatar tianming2018 avatar vikrammoule-redislabs avatar zcw159357 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.