-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 add and improve typings from DT (#126)
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Type definitions for @hapi/catbox-redis 7.0 | ||
// Project: https://github.com/hapijs/catbox-redis | ||
// Definitions by: Simon Schick <https://github.com/SimonSchick> | ||
// Silas Rech <https://github.com/lenovouser> | ||
// Danilo Alonso <https://github.com/damusix> | ||
// TypeScript Version: 5 | ||
|
||
import { EnginePrototype, ClientOptions, Client } from '@hapi/catbox'; | ||
import Redis, { Cluster } from 'ioredis'; | ||
|
||
export interface CatboxRedisOptions extends ClientOptions { | ||
|
||
/** | ||
* Raw client. | ||
*/ | ||
client?: Redis | Cluster | undefined; | ||
/** | ||
* the Redis server URL (if url is provided, host, port, and socket are ignored) | ||
*/ | ||
url?: string | undefined; | ||
/** | ||
* the Redis server hostname. | ||
* Defaults to '127.0.0.1'. | ||
*/ | ||
host?: string | undefined; | ||
/** | ||
* the Redis server port or unix domain socket path. | ||
* Defaults to 6379. | ||
*/ | ||
port?: number | undefined; | ||
/** | ||
* the unix socket string to connect to (if socket is provided, host and port are ignored) | ||
*/ | ||
socket?: string | undefined; | ||
/** | ||
* the Redis authentication password when required. | ||
*/ | ||
password?: string | undefined; | ||
/** | ||
* the Redis database. | ||
*/ | ||
database?: string | undefined; | ||
/** | ||
* an array of redis sentinel addresses to connect to. | ||
*/ | ||
sentinels?: Array<{ | ||
host: string; | ||
}> | undefined; | ||
/** | ||
* the name of the sentinel master. | ||
* (Only needed when sentinels is specified) | ||
*/ | ||
sentinelName?: string | undefined; | ||
} | ||
|
||
export class Engine<T> extends Client<T> { | ||
|
||
constructor (opts: CatboxRedisOptions); | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"node": ">=14.0.0" | ||
}, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib" | ||
], | ||
|
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Engine } from '..'; | ||
import Redis, { Cluster } from 'ioredis'; | ||
|
||
const cache = new Engine<string>({ | ||
client: new Redis(), | ||
host: 'localhost', | ||
partition: 'test', | ||
port: 2018, | ||
}); | ||
|
||
cache.get({ | ||
segment: 'test', | ||
id: 'test', | ||
}); | ||
|
||
cache.set({ | ||
segment: 'test', | ||
id: 'test', | ||
}, 'test', 123); | ||
|
||
|
||
new Engine({ | ||
client: new Cluster([new Redis(), new Redis()]) | ||
}); |