1- import { redis } from "../libs/redis"
1+ import { getRedis } from "../libs/redis"
22import { getDatasetWorker } from "../libs/datalad-service"
33import {
44 getPresignedUrl ,
@@ -184,7 +184,7 @@ export async function entryToDatasetFile(
184184 }
185185 let url : string
186186 if ( entry . p && entry . k && entry . v ) {
187- url = await getPresignedUrl ( redis , entry . b , entry . k , entry . v )
187+ url = await getPresignedUrl ( getRedis ( ) , entry . b , entry . k , entry . v )
188188 } else if ( entry . k && entry . v ) {
189189 url = publicS3Url ( entry . b , entry . k , entry . v )
190190 } else {
@@ -260,15 +260,15 @@ async function cacheWorkerTrees(
260260 ( f ) => f . directory || f . urls [ 0 ] ?. includes ( "s3.amazonaws.com" ) ,
261261 )
262262 if ( allExported ) {
263- void setTree ( redis , hash , entries )
263+ void setTree ( getRedis ( ) , hash , entries )
264264 permanentHashes . push ( hash )
265265 } else {
266- void setTree ( redis , hash , entries , 600 )
266+ void setTree ( getRedis ( ) , hash , entries , 600 )
267267 }
268268 }
269269 }
270270 if ( permanentHashes . length > 0 ) {
271- void addDatasetTrees ( redis , datasetId , permanentHashes )
271+ void addDatasetTrees ( getRedis ( ) , datasetId , permanentHashes )
272272 }
273273 return result
274274}
@@ -283,7 +283,10 @@ export const resolveGitRef = async (
283283 datasetId : string ,
284284 treeish : string ,
285285) : Promise < string > => {
286- const cache = new CacheItem ( redis , CacheType . gitRef , [ datasetId , treeish ] )
286+ const cache = new CacheItem ( getRedis ( ) , CacheType . gitRef , [
287+ datasetId ,
288+ treeish ,
289+ ] )
287290 return cache . get ( async ( ) => {
288291 const url = `http://${
289292 getDatasetWorker ( datasetId )
@@ -324,7 +327,7 @@ export const getFiles = async (
324327 }
325328 }
326329 // Try cache first
327- const cached = await getTree ( redis , treeish )
330+ const cached = await getTree ( getRedis ( ) , treeish )
328331 if ( cached ) {
329332 return entriesToDatasetFiles ( cached , datasetId )
330333 }
@@ -354,10 +357,10 @@ export async function getFilesRecursive(
354357) : Promise < DatasetFile [ ] > {
355358 const needsPresign = await datasetNeedsPresign ( datasetId )
356359 // Check for cached commit-to-trees mapping
357- const cachedTreeHashes = await getCommitTrees ( redis , tree )
360+ const cachedTreeHashes = await getCommitTrees ( getRedis ( ) , tree )
358361 if ( cachedTreeHashes ) {
359362 // Bulk-fetch all trees in one pipeline
360- const treesMap = await getTreesBulk ( redis , cachedTreeHashes )
363+ const treesMap = await getTreesBulk ( getRedis ( ) , cachedTreeHashes )
361364 if ( treesMap . size < cachedTreeHashes . length ) {
362365 // Batch-fetch all missing trees from the worker in one request
363366 const missingHashes = cachedTreeHashes . filter ( ( h ) => ! treesMap . has ( h ) )
@@ -381,7 +384,7 @@ export async function getFilesRecursive(
381384
382385 while ( pendingHashes . length > 0 ) {
383386 // Check cache for all pending hashes
384- const cached = await getTreesBulk ( redis , pendingHashes )
387+ const cached = await getTreesBulk ( getRedis ( ) , pendingHashes )
385388 const uncached = pendingHashes . filter ( ( h ) => ! cached . has ( h ) )
386389
387390 // Fetch all uncached trees in one worker request
@@ -417,8 +420,8 @@ export async function getFilesRecursive(
417420 // Cache the commit-to-trees mapping for next time
418421 if ( collectedHashes . size > 0 ) {
419422 const hashArray = [ ...collectedHashes ]
420- void setCommitTrees ( redis , tree , hashArray )
421- void addDatasetTrees ( redis , datasetId , hashArray )
423+ void setCommitTrees ( getRedis ( ) , tree , hashArray )
424+ void addDatasetTrees ( getRedis ( ) , datasetId , hashArray )
422425 }
423426
424427 return reconstructFromTrees ( treesMap , tree , path , datasetId )
@@ -485,7 +488,7 @@ async function reconstructFromTrees(
485488 // Bulk-resolve presigned URLs in minimal Redis requests
486489 if ( presignIndices . length > 0 ) {
487490 const urls = await getPresignedUrlsBulk (
488- redis ,
491+ getRedis ( ) ,
489492 presignIndices . map ( ( i ) => ( {
490493 bucket : fileEntries [ i ] . entry . b ,
491494 s3Key : fileEntries [ i ] . entry . k ,
0 commit comments