Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3515195
D13636.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D13636.diff
View Options
diff --git a/keyserver/src/utils/redis-cache.js b/keyserver/src/utils/redis-cache.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/utils/redis-cache.js
@@ -0,0 +1,51 @@
+// @flow
+
+import type { RedisClient } from 'redis';
+import redis from 'redis';
+
+import type { NeynarChannel } from 'lib/types/farcaster-types.js';
+
+import { redisConfig } from '../socket/redis.js';
+
+class RedisCache {
+ cacheClient: RedisClient;
+
+ constructor() {
+ this.cacheClient = redis.createClient(redisConfig);
+ }
+
+ setChannelInfo(fcChannelID: string, fcChannel: NeynarChannel): Promise<void> {
+ const stringifiedChannelInfo = JSON.stringify(fcChannel);
+ return new Promise((resolve, reject) => {
+ this.cacheClient.set(
+ `channel:${fcChannelID}`,
+ stringifiedChannelInfo,
+ 'EX',
+ 600, // item expires after 10 minutes
+ err => {
+ if (err) {
+ return reject(err);
+ }
+ return resolve();
+ },
+ );
+ });
+ }
+
+ getChannelInfo(fcChannelID: string): Promise<?NeynarChannel> {
+ return new Promise((resolve, reject) => {
+ this.cacheClient.get(`channel:${fcChannelID}`, (err, result) => {
+ if (err) {
+ return reject(err);
+ }
+ // Reset the expiration when the cached data is successfully retrieved
+ this.cacheClient.expire(`channel:${fcChannelID}`, 600);
+ return resolve(result ? JSON.parse(result) : null);
+ });
+ });
+ }
+}
+
+const redisCache: RedisCache = new RedisCache();
+
+export { redisCache };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 7:57 AM (18 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2694061
Default Alt Text
D13636.diff (1 KB)
Attached To
Mode
D13636: [keyserver] redis cache
Attached
Detach File
Event Timeline
Log In to Comment