From 0c78acd39364c90b1772dced4d1e36ba3df4605c Mon Sep 17 00:00:00 2001 From: malandis Date: Tue, 17 Sep 2024 18:11:00 +0000 Subject: [PATCH] Update templated README.md file --- README.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/README.md b/README.md index 027b1d0..d5249cc 100644 --- a/README.md +++ b/README.md @@ -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 @@ -24,16 +26,89 @@ The Momento Lettuce compatibility client is [available on Maven Central](https:/ ``` +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 + + software.momento.java + sdk + 1.15.0 + +``` + +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 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 redisClient = + MomentoRedisReactiveClient.create(cacheClient, cacheName); + } + } +} + ``` ## Current Redis API support