Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aih): redis adapter initialization error with turbopack #385

Merged
merged 5 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions apps/ai-hero/src/flags/flags-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,26 @@ export const getFlagKey = (key: string): string => {
return `${FLAG_PREFIX}${env}:${key}`
}

let defaultRedisAdapter: ReturnType<typeof createRedisAdapter>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we weren't doing anything with it as far as I could tell 🤔

function createRedisAdapter(): Adapter<boolean, any> {
return {
origin(key: string) {
return `${env.COURSEBUILDER_URL}/admin/flags/${key}`
},
async decide({ key }: { key: string }): Promise<boolean> {
// Strip environment prefix if present since getFlagKey will add it
const [, baseKey = key] = key.split(':')
const redisKey = getFlagKey(baseKey)
const value = await redis.get(redisKey)

function createRedisAdapter() {
return function redisAdapter(): Adapter<boolean, any> {
return {
origin(key: string) {
return `${env.COURSEBUILDER_URL}/admin/flags/${key}`
},
async decide({ key }: { key: string }): Promise<boolean> {
// Strip environment prefix if present since getFlagKey will add it
const [, baseKey = key] = key.split(':')
const redisKey = getFlagKey(baseKey)
const value = await redis.get(redisKey)

// Handle both string and boolean values
return value === true || value === 'true' || value === '1'
},
}
// Handle both string and boolean values
return value === true || value === 'true' || value === '1'
},
}
}

/**
* A default Redis adapter that can be used directly
*/
export function redisAdapter(): Adapter<boolean, any> {
if (!defaultRedisAdapter) {
defaultRedisAdapter = createRedisAdapter()
}

return defaultRedisAdapter()
return createRedisAdapter()
}
Loading