Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents 8e731e8 + af9d3d8 commit 3caa857
Show file tree
Hide file tree
Showing 19 changed files with 700 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -64,6 +64,6 @@ jobs:
run: make build

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
31 changes: 31 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,34 @@ jobs:

- name: Run tests vs redis
run: make test-redis

build-examples:
runs-on: ubuntu-latest
env:
MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}

steps:
- name: Checkout project
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'corretto'

- name: Build examples
id: validation
continue-on-error: true
run: make build-examples

- name: Send CI failure mail
if: ${{ steps.validation.outcome == 'failure' }}
uses: momentohq/standards-and-practices/github-actions/error-email-action@gh-actions-v1
with:
username: ${{secrets.MOMENTO_ROBOT_GMAIL_USERNAME}}
password: ${{secrets.MOMENTO_ROBOT_GMAIL_PASSWORD}}

- name: Flag Job Failure
if: ${{ steps.validation.outcome == 'failure' }}
run: exit 1
32 changes: 6 additions & 26 deletions .github/workflows/on-push-to-main-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,9 @@ jobs:
with:
token: ${{ secrets.MOMENTO_MACHINE_USER_GITHUB_TOKEN }}

# - name: Generate README
# uses: momentohq/standards-and-practices/github-actions/generate-and-commit-oss-readme@gh-actions-v2
# with:
# project_status: official
# project_stability: stable
# project_type: sdk
# sdk_language: Java
# dev_docs_slug: java
#
# - name: Verify Storage examples README generation
# uses: momentohq/standards-and-practices/github-actions/generate-and-commit-oss-readme@gh-actions-v2
# with:
# project_status: official
# project_stability: beta
# project_type: other
# template_file: ./examples/storage/README.template.md
# output_file: ./examples/storage/README.md
#
# - name: Verify examples README generation
# uses: momentohq/standards-and-practices/github-actions/generate-and-commit-oss-readme@gh-actions-v2
# with:
# project_status: official
# project_stability: beta
# project_type: other
# template_file: ./examples/README.template.md
# output_file: ./examples/README.md
- name: Generate README
uses: momentohq/standards-and-practices/github-actions/generate-and-commit-oss-readme@gh-actions-v2
with:
project_status: official
project_stability: alpha
project_type: other
3 changes: 1 addition & 2 deletions .github/workflows/on-push-to-release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ jobs:
ORG_GRADLE_PROJECT_version: ${{ needs.release.outputs.version }}
uses: gradle/gradle-build-action@v2
with:
# Note that this will require manual release from Sonatype
arguments: publishToSonatype closeSonatypeStagingRepository
arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository
16 changes: 2 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

# Package Files #
*.jar
!gradle/wrapper/gradle-wrapper.jar
!examples/gradle/wrapper/gradle-wrapper.jar
*.war
*.nar
*.ear
Expand All @@ -31,18 +33,4 @@ build
*.iml
.idea

# Ignore Gradle project-specific cache directory
examples/.gradle

# Ignore Gradle build output directory
examples/build

# Ignore IDE
examples/.idea
examples/.project
examples/.settings
examples/lib/.settings
examples/lib/.classpath
examples/lib/.project
examples/lib/bin
.vscode/
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ clean:
build:
./gradlew assemble

## Build the examples
build-examples:
cd ./examples && ./gradlew assemble

## Run all the tests
test: test-momento test-redis

Expand Down
121 changes: 119 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,119 @@
# momento-java-lettuce-client
Momento-backed implementation of [@lettuce](https://github.com/redis/lettuce) client
<img src="https://docs.momentohq.com/img/momento-logo-forest.svg" alt="logo" width="400"/>

[![project status](https://momentohq.github.io/standards-and-practices/badges/project-status-official.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md)
[![project stability](https://momentohq.github.io/standards-and-practices/badges/project-stability-alpha.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md)


# Momento Lettuce Compatibility Client

## What and why?

This project provides a Momento-backed implementation of [lettuce](https://github.com/redis/lettuce)
The goal is to provide a drop-in replacement for [lettuce](https://github.com/redis/lettuce) so that you can
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
<dependency>
<groupId>software.momento.java</groupId>
<artifactId>momento-lettuce</artifactId>
<version>0.1.0</version>
</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

This library supports the most popular Redis APIs, but does not yet support all Redis APIs. We currently support the most common APIs related to string values (`get`, `set`, `unlink`), as well as list (`lpush`, `lrange`, `ltrim`). We will be adding support for additional APIs in the future. If there is a particular API that you need support for, please drop by our [Discord](https://discord.com/invite/3HkAKjUZGq) or e-mail us at [[email protected]](mailto:[email protected]) and let us know!

----------------------------------------------------------------------------------------
For more info, visit our website at [https://gomomento.com](https://gomomento.com)!
55 changes: 55 additions & 0 deletions README.template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{{ ossHeader }}

# Momento Lettuce Compatibility Client

## What and why?

This project provides a Momento-backed implementation of [lettuce](https://github.com/redis/lettuce)
The goal is to provide a drop-in replacement for [lettuce](https://github.com/redis/lettuce) so that you can
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
<dependency>
<groupId>software.momento.java</groupId>
<artifactId>momento-lettuce</artifactId>
<version>0.1.0</version>
</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
{% include "./examples/src/main/java/momento/lettuce/example/doc_examples/ReadmeExample.java" %}
```

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
{% include "./examples/src/main/java/momento/lettuce/example/doc_examples/LimitedApiExample.java" %}
```

## Current Redis API support

This library supports the most popular Redis APIs, but does not yet support all Redis APIs. We currently support the most common APIs related to string values (`get`, `set`, `unlink`), as well as list (`lpush`, `lrange`, `ltrim`). We will be adding support for additional APIs in the future. If there is a particular API that you need support for, please drop by our [Discord](https://discord.com/invite/3HkAKjUZGq) or e-mail us at [[email protected]](mailto:[email protected]) and let us know!

{{ ossFooter }}
21 changes: 21 additions & 0 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id("java")
id("com.diffplug.spotless") version "5.15.1"
}

repositories {
mavenCentral()
}

dependencies {
implementation("io.lettuce:lettuce-core:6.4.0.RELEASE")
implementation("software.momento.java:momento-lettuce:0.1.0")
implementation("software.momento.java:sdk:1.15.0")
}

spotless {
java {
removeUnusedImports()
googleJavaFormat("1.11.0")
}
}
8 changes: 8 additions & 0 deletions examples/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Needed for https://github.com/diffplug/spotless/issues/834
# Google's Java Fromat has compatibility issues with JDK 16 -
# https://github.com/google/google-java-format#jdk-16
org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
Binary file added examples/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions examples/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Mon Sep 16 10:36:21 PDT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 3caa857

Please sign in to comment.