Skip to content

fix: apply keyPrefix in Redis handler delete methods#1067

Open
JeongGeun wants to merge 4 commits intocaching-tools:canaryfrom
JeongGeun:fix/cache-handler-delete-key-prefix
Open

fix: apply keyPrefix in Redis handler delete methods#1067
JeongGeun wants to merge 4 commits intocaching-tools:canaryfrom
JeongGeun:fix/cache-handler-delete-key-prefix

Conversation

@JeongGeun
Copy link

Background

While studying this repository and learning about cache handlers, I noticed an inconsistency in the handler code. Although not critical for production use, I decided to submit this PR to fix the bug for completeness and consistency.

Summary

Fixed a bug in the delete method of Redis cache handlers where keyPrefix was not being applied to cache keys, causing deletion attempts to target incorrect keys. This brings the delete method implementation in line with get and set methods.

Issue

All three Redis handlers had the same bug in their delete method:

  • redis-strings.ts
  • redis-stack.ts
  • experimental-redis-cluster.ts
// ❌ Before
async delete(key: string) {
  await client.unlink(getTimeoutRedisCommandOptions(timeoutMs), key);
}

While the get and set methods correctly use keyPrefix + key, the delete method was only using key, causing it to attempt deletion with an incorrect key.

// ✅ After
async delete(key: string) {
  await client.unlink(getTimeoutRedisCommandOptions(timeoutMs), keyPrefix + key);
}

Impact

Low impact in production - Redis handlers use TTL-based auto-eviction (EXAT/EXPIREAT), so expired entries are automatically removed by Redis itself. The delete method is optional and only intended for cache stores that don't support time-based key eviction (see Handler interface documentation).

However, this bug prevented manual deletion from working correctly when the delete method was explicitly called with a keyPrefix configuration.

Changes

  • Added keyPrefix to the key parameter in all three Redis handler delete methods
  • Ensures consistency with get and set method implementations
  • Maintains backward compatibility (no breaking changes)

@changeset-bot
Copy link

changeset-bot bot commented Feb 1, 2026

⚠️ No Changeset found

Latest commit: 459ef13

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant