Skip to content

Commit

Permalink
fix: resolve redis issue
Browse files Browse the repository at this point in the history
  • Loading branch information
james-a-morris committed Oct 10, 2023
1 parent 09a7c9d commit e3507d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
13 changes: 2 additions & 11 deletions src/caching/RedisCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { interfaces, constants } from "@across-protocol/sdk-v2";
import { RedisClient, objectWithBigNumberReviver, setRedisKey, winston } from "../utils";
import { RedisClient, objectWithBigNumberReviver, setRedisKey } from "../utils";

/**
* RedisCache is a caching mechanism that uses Redis as the backing store. It is used by the
Expand All @@ -8,14 +8,6 @@ import { RedisClient, objectWithBigNumberReviver, setRedisKey, winston } from ".
* drop-in in the SDK without the SDK needing to reason about the implementation details.
*/
export class RedisCache implements interfaces.CachingMechanismInterface {
/**
* The logger is optional, but if it is provided, it will be used to log debug messages
*/
private readonly logger: winston.Logger | undefined;
/**
* The redisUrl is the URL of the redis server to connect to.
*/
private readonly redisUrl: string;
/**
* The redisClient is the redis client that is used to communicate with the redis server.
* It is instantiated lazily when the `instantiate` method is called.
Expand All @@ -27,8 +19,7 @@ export class RedisCache implements interfaces.CachingMechanismInterface {
* @param redisUrl The URL of the redis server to connect to.
* @param logger The logger to use to log debug messages.
*/
constructor(redisClient: RedisClient, logger?: winston.Logger) {
this.logger = logger;
constructor(redisClient: RedisClient) {
this.redisClient = redisClient;
}

Expand Down
9 changes: 5 additions & 4 deletions src/scripts/testUBAClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getBlockForTimestamp,
disconnectRedisClient,
REDIS_URL,
getRedisCache,
} from "../utils";
import {
constructSpokePoolClientsForFastDataworker,
Expand All @@ -25,8 +26,8 @@ import {
import { updateClients } from "../common";
import { clients as sdkClients, utils as sdkUtils } from "@across-protocol/sdk-v2";
import { createDataworker } from "../dataworker";
import { RedisCache } from "../caching/RedisCache";
import { ConfigStoreClient } from "../clients";
import { CachingMechanismInterface } from "../interfaces";

config();

Expand Down Expand Up @@ -117,10 +118,10 @@ export async function testUBAClient(_logger: winston.Logger, baseSigner: Wallet)
);

// Now, simply update the UBA client:
const redisCache = new RedisCache(REDIS_URL);
let redisCache: CachingMechanismInterface | undefined;
let successfullyInstantiated = false;
try {
await redisCache.instantiate();
redisCache = await getRedisCache(logger, REDIS_URL);
successfullyInstantiated = true;
} catch (error) {
logger.warn({
Expand All @@ -136,7 +137,7 @@ export async function testUBAClient(_logger: winston.Logger, baseSigner: Wallet)
clients.hubPoolClient,
spokePoolClients,
// Pass in no redis client for now as testing with fresh state is easier to reason about
successfullyInstantiated ? new RedisCache(REDIS_URL) : undefined
successfullyInstantiated ? redisCache : undefined
);
await ubaClient.update();
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/RedisUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function getRedisCache(
): Promise<CachingMechanismInterface | undefined> {
const client = await getRedis(logger, url);
if (client) {
return new RedisCache(client, logger);
return new RedisCache(client);
}
}

Expand Down

0 comments on commit e3507d2

Please sign in to comment.