-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from BJS-kr/fix/v11compat
Fix/v11compat
- Loading branch information
Showing
8 changed files
with
34 additions
and
214 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,5 @@ | ||
import { Cache } from "../cache"; | ||
import { createClient } from "redis"; | ||
import { ICacheStorage } from "../types"; | ||
import { DefaultStorage } from "../default.storage"; | ||
|
||
export const defaultStorage = new DefaultStorage(); | ||
export const InMemCache = Cache({ storage: defaultStorage }); | ||
|
||
export class RedisCacheStorage implements ICacheStorage { | ||
private client; | ||
|
||
constructor() { | ||
this.client = createClient({ | ||
url: "redis://localhost:6379", | ||
name: "class", | ||
}); | ||
this.client.connect(); | ||
} | ||
|
||
async get(key: string): Promise<any> { | ||
const value = await this.client.get(key); | ||
try { | ||
return JSON.parse(value); | ||
} catch (error) { | ||
// 파싱에 실패한 경우, 원래의 문자열 값 반환 | ||
return value; | ||
} | ||
} | ||
|
||
async set(key: string, value: any, ttl?: number): Promise<void> { | ||
const stringValue = JSON.stringify(value); | ||
if (ttl) { | ||
await this.client.setEx(key, ttl, stringValue); | ||
} else { | ||
await this.client.set(key, stringValue); | ||
} | ||
} | ||
|
||
async delete(key: string): Promise<boolean> { | ||
const result = await this.client.del(key); | ||
return result === 1; | ||
} | ||
|
||
async has(key: string): Promise<boolean> { | ||
const result = await this.client.exists(key); | ||
return result === 1; | ||
} | ||
} | ||
|
||
export const RedisCache = Cache({ storage: new RedisCacheStorage() }); | ||
export const AnotherRedisCache = Cache({ storage: new RedisCacheStorage() }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.