MCPcopy Index your code
hub / github.com/simstudioai/sim / createStorageAdapter

Function createStorageAdapter

apps/sim/lib/core/rate-limiter/storage/factory.ts:21–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19}
20
21export function createStorageAdapter(): RateLimitStorageAdapter {
22 if (g._rlCachedAdapter) {
23 return g._rlCachedAdapter
24 }
25
26 if (!g._rlReconnectListenerRegistered) {
27 onRedisReconnect(() => {
28 g._rlCachedAdapter = null
29 })
30 g._rlReconnectListenerRegistered = true
31 }
32
33 const storageMethod = getStorageMethod()
34
35 if (storageMethod === 'redis') {
36 const redis = getRedisClient()
37 if (!redis) {
38 logger.warn(
39 'Redis configured but client unavailable - falling back to PostgreSQL for rate limiting'
40 )
41 g._rlCachedAdapter = new DbTokenBucket()
42 } else {
43 logger.info('Rate limiting: Using Redis')
44 g._rlCachedAdapter = new RedisTokenBucket(redis)
45 }
46 } else {
47 logger.info('Rate limiting: Using PostgreSQL')
48 g._rlCachedAdapter = new DbTokenBucket()
49 }
50
51 return g._rlCachedAdapter!
52}
53
54export function getAdapterType(): StorageMethod {
55 return getStorageMethod()

Callers 3

constructorMethod · 0.90
factory.test.tsFile · 0.90
constructorMethod · 0.90

Calls 5

onRedisReconnectFunction · 0.90
getStorageMethodFunction · 0.90
getRedisClientFunction · 0.90
infoMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected