Skip to content

Conversation

@xav-developer
Copy link
Contributor

@xav-developer xav-developer commented Sep 30, 2025

Description

  • The forever method passed $seconds as 0, Spiral\RoadRunner\KeyValue summed timestamp + 0, and forever was not forever

  • Fixed the $ttl in the increment method

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I wrote unit tests for my code (if tests is required for my changes)
  • I have made changes in CHANGELOG.md file

Summary by CodeRabbit

  • Bug Fixes

    • Fixed TTL handling in cache increment so values update without unintentionally changing or losing their expiration.
    • Corrected “forever” cache entries to truly never expire, preventing unexpected expirations caused by zero-second TTL behavior.
    • Improved consistency of cache operations to ensure predictable read/write behavior and reliable expiration semantics.
  • Documentation

    • Updated changelog to reflect fixes for increment TTL handling and the corrected behavior of “forever” cache entries.

…lue` summed `timestamp + 0`, and `forever` was not `forever`

Fixed the `increment' method
…lue` summed `timestamp + 0`, and `forever` was not `forever`

Fixed the `$ttl` in the `increment` method
@coderabbitai
Copy link

coderabbitai bot commented Sep 30, 2025

Walkthrough

Fixes RoadRunnerStore increment to perform read-modify-write via get/put and correct TTL handling. Updates forever to use null TTL (no expiration) instead of 0. Adds corresponding notes to CHANGELOG. No public API signatures changed.

Changes

Cohort / File(s) Summary
Docs: Changelog
CHANGELOG.md
Added notes: fixed $ttl handling in increment; corrected forever to use non-expiring TTL (null instead of 0).
Cache Store Logic
src/Cache/RoadRunnerStore.php
increment now reads via get($key) and writes via put($key, ...), centralizing key prefixing and TTL application; forever now stores with null TTL to ensure no expiration.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant S as RoadRunnerStore
  participant KV as RoadRunner KV

  rect rgb(235,245,255)
  note over S: increment(key, value, ttl)
  C->>S: increment(key, step=1, ttl?)
  S->>S: get(key)
  S->>KV: fetch current value
  KV-->>S: value (or 0)
  S->>S: newValue = current + step
  S->>S: resolve TTL (existing or provided)
  S->>S: put(key, newValue, ttl)
  S->>KV: store with TTL
  KV-->>S: ok
  S-->>C: newValue
  end
Loading
sequenceDiagram
  autonumber
  participant C as Client
  participant S as RoadRunnerStore
  participant KV as RoadRunner KV

  rect rgb(240,255,240)
  note over S: forever(key, value)
  C->>S: forever(key, value)
  S->>S: put(key, value, ttl=null)
  S->>KV: store with no expiration
  KV-->>S: ok
  S-->>C: ok
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

type:bug

Suggested reviewers

  • butschster

Poem

I hop through keys with TTL in tow,
A nibble of null—forever we go.
Increment’s dance: get, add, put—delight!
No clock to chase in moonlit byte.
With whisker-twitch and cache made right,
My burrow hums all through the night. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title clearly summarizes the primary change by indicating that the “increment” and “forever” methods are being fixed, which directly aligns with the code modifications detailed in the diff. It is concise, focused on the main change, and avoids vague or unrelated wording.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 231a23f and a688484.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • src/Cache/RoadRunnerStore.php (2 hunks)
🔇 Additional comments (4)
CHANGELOG.md (1)

21-22: LGTM! Clear and accurate changelog entries.

The changelog entries clearly document both fixes: the TTL handling in increment and the forever method's incorrect passing of 0 instead of null for permanent storage.

src/Cache/RoadRunnerStore.php (3)

77-80: LGTM! Correct fix for permanent storage.

Changing the TTL from 0 to null correctly implements permanent storage. The previous behavior where 0 was interpreted as timestamp + 0 would cause immediate expiration, which is now properly resolved by passing null to indicate no expiration.


61-70: Confirm TTL parameter type for put()

The code computes TTL as a DateInterval ($ttl->diff(new \DateTimeImmutable())) but passes it directly to put(), which calls StorageInterface::set(). Verify whether Spiral\RoadRunner\KeyValue\StorageInterface::set() accepts a DateInterval or expects an integer (seconds); if it requires seconds, convert the DateInterval accordingly before passing.


68-68: Verify getTtl() return type and diff() direction
The StorageInterface::getTtl() method lives outside this repo—please confirm whether it returns a future DateTimeInterface (expiration timestamp) or an integer TTL.

  • If it returns a DateTimeInterface, swap the diff parameters to compute “now → expiry”:
    $this->put($key, $newValue, (new \DateTimeImmutable())->diff($ttl));
  • If it returns seconds, pass that integer directly to put().

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.28)

Path /fixes does not exist


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

@xav-developer xav-developer changed the title Fix/increment forever Fix : increment and forever Sep 30, 2025
@butschster butschster merged commit e57e856 into roadrunner-php:master Sep 30, 2025
1 check passed
@butschster butschster self-assigned this Sep 30, 2025
@butschster butschster added github_actions Pull requests that update Github_actions code type:bug Something isn't working and removed github_actions Pull requests that update Github_actions code labels Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants