Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/redis-haskey-missing-await.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nostream": patch
---

fix: await Redis EXISTS call in RedisAdapter.hasKey() so it reflects actual key presence instead of always returning true
2 changes: 1 addition & 1 deletion src/adapters/redis-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class RedisAdapter implements ICacheAdapter {
public async hasKey(key: string): Promise<boolean> {
await this.connection
logger('has %s key', key)
return Boolean(this.client.exists(key))
return (await this.client.exists(key)) > 0
}

public async getKey(key: string): Promise<string> {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/adapters/redis-adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('RedisAdapter', () => {

describe('hasKey', () => {
it('awaits connection and calls client.exists with the key', async () => {
client.exists.returns(1)
client.exists.resolves(1)

const result = await adapter.hasKey('test-key')

Expand All @@ -85,7 +85,7 @@ describe('RedisAdapter', () => {
})

it('returns false when key does not exist', async () => {
client.exists.returns(0)
client.exists.resolves(0)

const result = await adapter.hasKey('missing-key')

Expand Down
Loading