Skip to content

Commit

Permalink
Update templated README.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
malandis authored and Momento GitHub Actions Bot committed Sep 17, 2024
1 parent 671793a commit 0c78acd
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use the same code with either a Redis server or with the Momento Cache service!

## Installation

To use the compatiblity client, you will need three dependencies in your project: the Momento Lettuce compatibility client, the Momento Cache client, and the lettuce client.

The Momento Lettuce compatibility client is [available on Maven Central](https://search.maven.org/artifact/software.momento.java/momento-lettuce). You can add it to your project via:

```xml
Expand All @@ -24,16 +26,89 @@ The Momento Lettuce compatibility client is [available on Maven Central](https:/
</dependency>
```

You will also need to add the Momento Cache client library to your project. You can find the latest version of the Momento Cache client library [on Maven Central](https://central.sonatype.com/artifact/software.momento.java/sdk) as well:

```xml
<dependency>
<groupId>software.momento.java</groupId>
<artifactId>sdk</artifactId>
<version>1.15.0</version>
</dependency>
```

As well as the lettuce client also [on Maven Central](https://central.sonatype.com/artifact/io.lettuce/lettuce-core).

## Usage

To switch your existing `lettuce` application to use Momento Cache, you only need to change the code where you construct your client object. Here is an example of constructing a Momento lettuce client:

```java
package momento.lettuce.example.doc_examples;

import io.lettuce.core.api.reactive.RedisReactiveCommands;
import java.time.Duration;
import momento.lettuce.MomentoRedisReactiveClient;
import momento.sdk.CacheClient;
import momento.sdk.auth.CredentialProvider;
import momento.sdk.config.Configurations;

class ReadmeExample {
public static void main(String[] args) {
// Create a Momento cache client
try (final CacheClient cacheClient =
CacheClient.create(
CredentialProvider.fromEnvVar("MOMENTO_API_KEY"),
Configurations.Laptop.v1(),
Duration.ofSeconds(60))) {
final String cacheName = "cache";

// Create a Redis client backed by the Momento cache client over the cache
RedisReactiveCommands<String, String> redisClient =
MomentoRedisReactiveClient.create(cacheClient, cacheName);

// Perform operations vs Momento as if using a regular Redis client
var setResult = redisClient.set("key", "value").block();
System.out.println("Set result: " + setResult);

var getResult = redisClient.get("key").block();
System.out.println("Get result: " + getResult);
}
}
}

```

Additionally, to understand what APIs are supported, you can use the interface `MomentoRedisReactiveCommands` which contains only those APIs that are supported by this compatibility client:

```java
package momento.lettuce.example.doc_examples;

import java.time.Duration;
import momento.lettuce.MomentoRedisReactiveClient;
import momento.lettuce.MomentoRedisReactiveCommands;
import momento.sdk.CacheClient;
import momento.sdk.auth.CredentialProvider;
import momento.sdk.config.Configurations;

class LimitedApiExample {
public static void main(String[] args) {
// Create a Momento cache client
try (final CacheClient cacheClient =
CacheClient.create(
CredentialProvider.fromEnvVar("MOMENTO_API_KEY"),
Configurations.Laptop.v1(),
Duration.ofSeconds(60))) {
final String cacheName = "cache";

// This interface provides type safety as it only allows the user to interact with the
// RedisReactiveCommands
// commands that are supported by the MomentoRedisReactiveCommands class
MomentoRedisReactiveCommands<String, String> redisClient =
MomentoRedisReactiveClient.create(cacheClient, cacheName);
}
}
}

```

## Current Redis API support
Expand Down

0 comments on commit 0c78acd

Please sign in to comment.