Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3306703
D13639.id45061.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
D13639.id45061.diff
View Options
diff --git a/keyserver/src/utils/redis-cache.js b/keyserver/src/utils/redis-cache.js
--- a/keyserver/src/utils/redis-cache.js
+++ b/keyserver/src/utils/redis-cache.js
@@ -4,6 +4,7 @@
import redis from 'redis';
import type { NeynarChannel } from 'lib/types/farcaster-types.js';
+import type { Identity } from 'lib/types/identity-service-types.js';
import { redisConfig } from '../socket/redis.js';
@@ -47,6 +48,37 @@
});
});
}
+
+ setUserIdentity(userID: string, userIdentity: Identity): Promise<void> {
+ const stringifiedUserIdentity = JSON.stringify(userIdentity);
+ return new Promise((resolve, reject) => {
+ this.cacheClient.set(
+ `user:${userID}`,
+ stringifiedUserIdentity,
+ 'EX',
+ 60, // item expires after 1 minute
+ err => {
+ if (err) {
+ return reject(err);
+ }
+ return resolve();
+ },
+ );
+ });
+ }
+
+ getUserIdentity(userID: string): Promise<?Identity> {
+ return new Promise((resolve, reject) => {
+ this.cacheClient.get(`user:${userID}`, (err, result) => {
+ if (err) {
+ return reject(err);
+ }
+ // Reset the expiration when the cached data is successfully retrieved
+ this.cacheClient.expire(`user:${userID}`, 60);
+ return resolve(result ? JSON.parse(result) : null);
+ });
+ });
+ }
}
const redisCache: RedisCache = new RedisCache();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 19, 9:34 PM (22 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2540494
Default Alt Text
D13639.id45061.diff (1 KB)
Attached To
Mode
D13639: [keyserver] extend redis cache to store user identities returned by findUserIdentities
Attached
Detach File
Event Timeline
Log In to Comment