-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a93449
commit b9b4ff9
Showing
12 changed files
with
153 additions
and
18 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Redis, RedisOptions } from 'ioredis' | ||
|
||
import { stringify } from '../lib/stringify' | ||
|
||
import { AbiCache, AbiInformation } from './abi-cache' | ||
|
||
export class RedisAbiCache extends AbiCache { | ||
private redis: Redis | ||
private cachePrefix = 'ABICACHE:' | ||
|
||
constructor(redisOptions: RedisOptions) { | ||
super() | ||
this.redis = new Redis({ ...redisOptions, keyPrefix: this.cachePrefix }) | ||
} | ||
|
||
public override async init(): Promise<AbiCache> { | ||
const keys = await this.redis.keys(`${this.cachePrefix}*`) | ||
|
||
await Promise.all( | ||
keys.map(async (key: string) => { | ||
const abiKey = key.replace(`${this.cachePrefix}`, '') | ||
const abi = await this.redis.get(abiKey) | ||
|
||
if (abi) { | ||
this.loadFromString(abiKey, abi) | ||
} | ||
}) | ||
) | ||
|
||
return Promise.resolve(this) | ||
} | ||
|
||
protected override async persist( | ||
key: string, | ||
abi: AbiInformation | ||
): Promise<void> { | ||
await this.redis.set(key, stringify(abi)) | ||
} | ||
} |
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
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