Skip to content

Commit

Permalink
add redis client library options usage for full control, redis storag…
Browse files Browse the repository at this point in the history
…e unit tests
  • Loading branch information
havsar committed Dec 15, 2018
1 parent a8327d9 commit 2a49910
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 106 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,16 @@ Cached items expire after a given amount of time.
- `isCachedForver`: *(Default: false)* If true, cache entry has no expiration.

# Storages

*Note: For specific storages, client libraries must be installed:*

| Storage | Needed client library |
|--------------|:---------------------:|
| RedisStorage | `npm install redis` |

#### MemoryStorage()
#### FsJsonStorage(`fileName: string`)
#### RedisStorage(`host: string, port: number, password: string`)
#### RedisStorage(`clientOpts:` [RedisClientOptions](https://github.com/NodeRedis/node_redis#options-object-properties))


# Test
Expand Down
150 changes: 89 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@
"@types/bluebird": "3.5.24",
"@types/mocha": "5.2.5",
"@types/node": "10.12.9",
"@types/redis": "2.8.7",
"@types/sinon": "5.0.5",
"bluebird": "3.5.3",
"redis": "2.8.0"
"@types/redis": "^2.8.8",
"bluebird": "3.5.3"
},
"devDependencies": {
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^5.0.5",
"mocha": "5.2.0",
"sinon": "7.1.1",
"proxyquire": "^2.1.0",
"sinon": "^7.2.2",
"ts-node": "7.0.1",
"typescript": "3.1.6"
}
},
"optionalDependencies": {}
}
11 changes: 11 additions & 0 deletions src/custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Redis from 'redis';

interface RedisClient extends Redis.RedisClient {
getAsync?(arg: string): Promise<string>;

delAsync?(arg: string): Promise<void>;

setAsync?<T>(arg: string, arg2: string): Promise<void>;

flushdbAsync?(): Promise<void>;
}
2 changes: 2 additions & 0 deletions src/storages/IStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ interface ICacheEntry {

export interface IStorage {
getItem<T>(key: string): Promise<T>;

setItem(key: string, content: ICacheEntry): Promise<void>;

clear(): Promise<void>;
}
Loading

0 comments on commit 2a49910

Please sign in to comment.