Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(memorystore): added valkey caching practical source-code samples #9986

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

dackers86
Copy link

@dackers86 dackers86 commented Jan 22, 2025

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@dackers86 dackers86 requested review from yoshi-approver and a team as code owners January 22, 2025 17:15
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Jan 22, 2025
Copy link
Contributor

@code-review-assist code-review-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dackers86 and reviewers,

I'm currently reviewing this pull request and will provide my feedback in a few minutes. In the meantime, I'm providing this summary to help everyone quickly understand the changes and intent.

This pull request, "docs(memorystore): added valkey practical source-code samples", aims to add practical source code samples for Memorystore for Valkey. I've analyzed the changes and here's a breakdown:

Intent: Add new, practical code samples demonstrating various Memorystore for Valkey functionalities.

Changes:

  • New README.md (memorystore/valkey/caching/samples/README.md): A new README file was added, providing instructions on prerequisites (Java installation, Memorystore for Valkey instance setup), compiling the code via Maven, and running the sample code. The file is 31 lines long.
  • New pom.xml (memorystore/valkey/caching/samples/pom.xml): A new pom.xml file was added, defining project dependencies (Jedis, Google Cloud Client Libraries, and JUnit for testing). The file is 100 lines long.
  • New Java source code files: Four new Java files were added under memorystore/valkey/caching/samples/src/main/java/samples/:
    • MemorystoreDeleteItem.java (40 lines): Demonstrates deleting an item from the cache.
    • MemorystoreReadItem.java (37 lines): Demonstrates reading an item from the cache.
    • MemorystoreTTLItem.java (63 lines): Demonstrates caching an item with a Time-To-Live (TTL).
    • MemorystoreWriteItem.java (33 lines): Demonstrates writing an item to the cache.

Checklist: The pull request includes a checklist confirming adherence to the sample format guide, updates to the README, and successful test and lint execution.

I will be checking the code for correctness, style, and adherence to best practices during my review. I'll also verify that the tests pass and that the code is well-documented.


And now, a little haiku to lighten the mood:

Code flows like a stream,
Tests pass, a joyful green light,
Bugs flee in the night.

Copy link
Contributor

@code-review-assist code-review-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request adds practical source code samples for Memorystore for Valkey, which is a valuable addition. The samples cover basic operations like writing, reading, deleting, and setting TTL for cached items. The provided README.md is helpful and provides clear instructions.

Here's a summary of the feedback based on the Google Java Style Guide:

  • Use descriptive variable names.
  • Ensure consistent spacing and indentation.
  • Add Javadoc comments for classes and methods.
  • Handle potential exceptions.
  • Use try-with-resources for resource management.

@iennae
Copy link
Contributor

iennae commented Jan 22, 2025

@dackers86 you need to make sure that all files have the appropriate Apache 2 header please.


### MemoryStore for Valkey Instance

A working instance of memorystore for valkey must be available. You can run the [Valkey CLI](https://valkey.io/topics/cli/) for a local instance, or create an instance through the [GCP Platform](https://console.cloud.google.com/memorystore/valkey/instances?).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caps on Memorystore, Valkey?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valkey CLI -> maybe indicate they should use the 'create' command? Or provide a 'local instance' snippet?

## Run the sample code

```bash
mvn exec:java -Dexec.mainClass=MemorystoreTTLItem //Replace the main class as needed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash comment should be '#' instead of '//'?

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>samples</groupId>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

/** Close the Redis connection */
jedis.close();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try-with-resources ? this guaranatees proper resource closure.

jedis.set(itemId, itemValue);

/** Print out the cached result */
System.out.println("Item cached with ID: " + itemId + " and value: " + itemValue);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a 'get' call to confirm it?

@dackers86 dackers86 changed the title docs(memorystore): added valkey practical source-code samples docs(memorystore): added valkey caching practical source-code samples Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: memorystore samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants