Skip to content

refactor(idempotency): replace Redis name with Cache and add valkey-glide support #6685

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

Merged
merged 6 commits into from
May 19, 2025

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #6666

Summary

This PR implements an alias from RedisCachePersistenceLayer to CachePersistenceLayer. This change aligns our naming convention with the Powertools TypeScript implementation.

This change improves naming consistency across Powertools implementations while highlighting Valkey-glide library, which brings significant performance optimizations for cache operations. These optimizations improve response times and resource utilization when using the cache persistence layer.

Changes

  • Added CachePersistenceLayer class as an alias to RedisCachePersistenceLayer
  • Updated documentation to use the new class name
  • Included Valkey Glide examples as the primary implementation reference
  • Maintained backward compatibility with the original class name

User experience

import os
from dataclasses import dataclass, field
from uuid import uuid4

from glide import GlideClient, GlideClientConfiguration, NodeAddress

from aws_lambda_powertools.utilities.idempotency import (
    idempotent,
)
from aws_lambda_powertools.utilities.idempotency.persistence.cache import (
    CachePersistenceLayer,
)
from aws_lambda_powertools.utilities.typing import LambdaContext

cache_endpoint = os.getenv("CACHE_CLUSTER_ENDPOINT", "localhost")
client_config = GlideClientConfiguration(
    addresses=[
        NodeAddress(
            host="localhost",
            port=6379,
        ),
    ],
)
client = GlideClient.create(config=client_config)

persistence_layer = CachePersistenceLayer(client=client)  # type: ignore[arg-type]


@dataclass
class Payment:
    user_id: str
    product_id: str
    payment_id: str = field(default_factory=lambda: f"{uuid4()}")


class PaymentError(Exception): ...


@idempotent(persistence_store=persistence_layer)
def lambda_handler(event: dict, context: LambdaContext):
    try:
        payment: Payment = create_subscription_payment(event)
        return {
            "payment_id": payment.payment_id,
            "message": "success",
            "statusCode": 200,
        }
    except Exception as exc:
        raise PaymentError(f"Error creating payment {str(exc)}")


def create_subscription_payment(event: dict) -> Payment:
    return Payment(**event)

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@leandrodamascena leandrodamascena requested a review from a team as a code owner May 19, 2025 16:48
@boring-cyborg boring-cyborg bot added dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation internal Maintenance changes labels May 19, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 19, 2025
@leandrodamascena leandrodamascena changed the title refactor(idempotency): replace Redis with Cache refactor(idempotency): replace Redis name with Cache and add valkey-glide support May 19, 2025
@github-actions github-actions bot removed documentation Improvements or additions to documentation internal Maintenance changes labels May 19, 2025
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label May 19, 2025
@github-actions github-actions bot added enhancement and removed documentation Improvements or additions to documentation labels May 19, 2025
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation internal Maintenance changes labels May 19, 2025
@github-actions github-actions bot removed documentation Improvements or additions to documentation internal Maintenance changes labels May 19, 2025
Copy link

codecov bot commented May 19, 2025

Codecov Report

Attention: Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.09%. Comparing base (56a70cf) to head (1f4935a).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
...ertools/utilities/idempotency/persistence/cache.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6685      +/-   ##
===========================================
- Coverage    96.11%   96.09%   -0.02%     
===========================================
  Files          253      254       +1     
  Lines        12170    12177       +7     
  Branches       904      904              
===========================================
+ Hits         11697    11702       +5     
- Misses         371      373       +2     
  Partials       102      102              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation internal Maintenance changes labels May 19, 2025
@github-actions github-actions bot removed documentation Improvements or additions to documentation internal Maintenance changes labels May 19, 2025
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label May 19, 2025
@boring-cyborg boring-cyborg bot added the internal Maintenance changes label May 19, 2025
@github-actions github-actions bot removed documentation Improvements or additions to documentation internal Maintenance changes labels May 19, 2025
Copy link
Contributor

@anafalcao anafalcao left a comment

Choose a reason for hiding this comment

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

APPROVED!

@leandrodamascena leandrodamascena merged commit 49d3e96 into develop May 19, 2025
14 of 16 checks passed
@leandrodamascena leandrodamascena deleted the idempotency/use-glide branch May 19, 2025 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: Rename the RedisCachePersistenceLayer to CachePersistenceLayer in idempotency utility
2 participants