Skip to content

Commit db6a86e

Browse files
Merge pull request #157 from DIG-Network/release/v0.0.1-alpha.172
Release/v0.0.1 alpha.172
2 parents 0daf62b + 5947eee commit db6a86e

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [0.0.1-alpha.172](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.171...v0.0.1-alpha.172) (2024-10-26)
6+
7+
8+
### Bug Fixes
9+
10+
* redis ttl ([70161fd](https://github.com/DIG-Network/dig-chia-sdk/commit/70161fd6a08550dcaf1a557fe1674b0ac4a90cd5))
11+
512
### [0.0.1-alpha.171](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.170...v0.0.1-alpha.171) (2024-10-26)
613

714

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/dig-sdk",
3-
"version": "0.0.1-alpha.171",
3+
"version": "0.0.1-alpha.172",
44
"description": "",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/utils/DigCache.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface ICache {
99
has(key: string): Promise<boolean>;
1010
flushAll(): Promise<boolean>;
1111
keys(pattern?: string): Promise<string[]>;
12-
ttl(key: string): Promise<number>;
12+
ttl(key: string, ttl?: number): Promise<boolean>;
1313
// Add other NodeCache methods as needed
1414
}
1515

@@ -209,28 +209,28 @@ class DigCache implements ICache {
209209
}
210210
}
211211

212-
async ttl(key: string): Promise<number> {
212+
async ttl(key: string, ttl?: number): Promise<boolean> {
213213
if (this.useRedis) {
214214
try {
215-
const result = await (this.cache as RedisClientType).ttl(key);
216-
return result; // TTL in seconds. -2: key does not exist, -1: no TTL
217-
} catch (error) {
215+
if (ttl === undefined || ttl === 0) {
216+
return (await (this.cache as RedisClientType).del(key)) > 0;
217+
} else {
218+
return await (this.cache as RedisClientType).expire(key, ttl);
219+
}
220+
} catch (error: any) {
218221
console.error(`Redis ttl error for key "${key}":`, error);
219-
return -2;
222+
return false;
220223
}
221224
} else {
222-
const ttlMs = (this.cache as NodeCache).getTtl(key);
223-
224-
if (ttlMs === undefined || ttlMs === 0) {
225-
return -1; // No TTL set
226-
}
227-
228-
if (ttlMs < 0) {
229-
return ttlMs; // Key does not exist or other Redis-specific responses
225+
try {
226+
if (ttl === undefined || ttl === 0) {
227+
return (this.cache as NodeCache).del(key) > 0;
228+
}
229+
return (this.cache as NodeCache).ttl(key, ttl);
230+
} catch (error: any) {
231+
console.error(`NodeCache ttl error for key "${key}":`, error);
232+
return false;
230233
}
231-
232-
const ttlSec = Math.floor((ttlMs - Date.now()) / 1000);
233-
return ttlSec > 0 ? ttlSec : -2;
234234
}
235235
}
236236

0 commit comments

Comments
 (0)