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

feat: adds support for expire command #35

Merged
merged 3 commits into from
May 6, 2024
Merged
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
44 changes: 23 additions & 21 deletions src/momento-redis-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,23 @@

pexpire(key: RedisKey, milliseconds: number): Promise<number | null>;

pexpire(
key: RedisKey,
milliseconds: number,
nx: 'NX'
): Promise<number | null>;
pexpire(key: RedisKey, milliseconds: number, nx: 'NX'): Promise<number>;

pexpire(
key: RedisKey,
milliseconds: number,
xx: 'XX'
): Promise<number | null>;
pexpire(key: RedisKey, milliseconds: number, xx: 'XX'): Promise<number>;

pexpire(
key: RedisKey,
milliseconds: number,
gt: 'GT'
): Promise<number | null>;
pexpire(key: RedisKey, milliseconds: number, gt: 'GT'): Promise<number>;
eaddingtonwhite marked this conversation as resolved.
Show resolved Hide resolved

pexpire(
key: RedisKey,
milliseconds: number,
lt: 'LT'
): Promise<number | null>;
pexpire(key: RedisKey, milliseconds: number, lt: 'LT'): Promise<number>;

expire(key: RedisKey, seconds: number): Promise<number>;

expire(key: RedisKey, seconds: number, nx: 'NX'): Promise<number>;

expire(key: RedisKey, seconds: number, xx: 'XX'): Promise<number>;

expire(key: RedisKey, seconds: number, gt: 'GT'): Promise<number>;

expire(key: RedisKey, seconds: number, lt: 'LT'): Promise<number>;

del(...args: [...keys: RedisKey[]]): Promise<number>;

Expand Down Expand Up @@ -195,7 +189,7 @@
// TODO compile time checks on what methods are supported by the MomentoIORedis
// TODO interface. We could try defining our own ChainableMomento interface
// TODO instead here potentially
pipeline(commands?: Array<Array<any>>): ChainableCommander;

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 16

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 16

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 16

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 16

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 18

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 18

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 16

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 16

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 20

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 20

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 18

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 18

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 18

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 18

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 20

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 20

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 20

Unexpected any. Specify a different type

Check warning on line 192 in src/momento-redis-adapter.ts

View workflow job for this annotation

GitHub Actions / Test on Node 20

Unexpected any. Specify a different type

quit(): Promise<'OK'>;
}
Expand Down Expand Up @@ -785,7 +779,7 @@
key: RedisKey,
milliseconds: number,
ttlFlagIdentifier?: 'NX' | 'XX' | 'GT' | 'LT'
): Promise<number | null> {
): Promise<number> {
let shouldUpdateTtl = true;

if (ttlFlagIdentifier === 'NX') {
Expand Down Expand Up @@ -831,6 +825,14 @@
return 0;
}

async expire(
key: RedisKey,
seconds: number,
ttlFlagIdentifier?: 'NX' | 'XX' | 'GT' | 'LT'
): Promise<number> {
return await this.pexpire(key, seconds * 1000, ttlFlagIdentifier);
}

async unlink(...args: [...keys: RedisKey[]]): Promise<number> {
await this.del(...args);
return args.length;
Expand Down
Loading
Loading