-
Notifications
You must be signed in to change notification settings - Fork 121
feat: add driver context access in createVars function #2841
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
feat: add driver context access in createVars function #2841
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Merge activity
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
<!-- Please make sure there is an issue that this PR is correlated to. --> ## Changes <!-- If there are frontend changes, please include screenshots. -->
const myActor = actor(, | ||
|
||
// Access Redis connection through driver context | ||
createVars: (ctx, driver: DriverContext) => ; | ||
}, | ||
|
||
actions: `, value, 'EX', 3600); | ||
|
||
// Also store locally for fast access | ||
c.vars.cacheData.set(key, value); | ||
|
||
return "Cached successfully"; | ||
}, | ||
|
||
// Example: Get cached value | ||
getCachedValue: async (c, key: string) => | ||
|
||
// Fallback to Redis | ||
const value = await c.vars.redis.get(`cache:$`); | ||
if (value) | ||
|
||
return value; | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Redis example code contains several syntax errors and incomplete sections:
- The
actor()
function is missing its first parameter (likely an object with configuration) - The
createVars
function has an incomplete return statement - The Redis
set
operation is missing its beginning (likelyc.vars.redis.set
) - String interpolation in the Redis key is malformed -
cache:$
should becache:${key}
- The conditional after checking the Redis value is incomplete
These issues would prevent the example from working as intended. Consider providing a complete, syntactically correct example to demonstrate the Redis driver context functionality.
const myActor = actor(, | |
// Access Redis connection through driver context | |
createVars: (ctx, driver: DriverContext) => ; | |
}, | |
actions: `, value, 'EX', 3600); | |
// Also store locally for fast access | |
c.vars.cacheData.set(key, value); | |
return "Cached successfully"; | |
}, | |
// Example: Get cached value | |
getCachedValue: async (c, key: string) => | |
// Fallback to Redis | |
const value = await c.vars.redis.get(`cache:$`); | |
if (value) | |
return value; | |
} | |
} | |
}); | |
const myActor = actor({ | |
name: 'CacheActor', | |
}, { | |
// Access Redis connection through driver context | |
createVars: (ctx, driver: DriverContext) => { | |
return { | |
redis: driver.redis, | |
cacheData: new Map() | |
}; | |
}, | |
actions: { | |
// Example: Cache a value | |
cacheValue: async (c, key: string, value: string) => { | |
// Store in Redis with 1 hour expiration | |
await c.vars.redis.set(`cache:${key}`, value, 'EX', 3600); | |
// Also store locally for fast access | |
c.vars.cacheData.set(key, value); | |
return "Cached successfully"; | |
}, | |
// Example: Get cached value | |
getCachedValue: async (c, key: string) => { | |
// Try local cache first | |
const localValue = c.vars.cacheData.get(key); | |
if (localValue) return localValue; | |
// Fallback to Redis | |
const value = await c.vars.redis.get(`cache:${key}`); | |
if (value) { | |
// Update local cache | |
c.vars.cacheData.set(key, value); | |
} | |
return value; | |
} | |
} | |
}); | |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
kvGet: (c, key: string) => { | ||
const doState = c.vars.state; | ||
return await doState.storage.get(key) | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The kvGet
function is using await
but is not declared as async
. This will cause a syntax error. The function signature should be updated to:
kvGet: async (c, key: string) => {
const doState = c.vars.state;
return await doState.storage.get(key);
}
kvGet: (c, key: string) => { | |
const doState = c.vars.state; | |
return await doState.storage.get(key) | |
}, | |
kvGet: async (c, key: string) => { | |
const doState = c.vars.state; | |
return await doState.storage.get(key) | |
}, |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
Changes