Skip to content

Commit

Permalink
rework on get connect function
Browse files Browse the repository at this point in the history
  • Loading branch information
kane50613 committed Mar 4, 2024
1 parent 8c5004a commit 519aacd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redis-on-workers",
"version": "0.2.2",
"version": "0.2.3",
"description": "Connect to your Redis server using cloudflare:sockets",
"scripts": {
"build": "tsup",
Expand Down
12 changes: 10 additions & 2 deletions src/get-connect-fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ export async function getConnectFn(fn?: CreateRedisOptions["connectFn"]) {
if (fn) return fn;

try {
return await import("cloudflare:sockets").then((r) => r.connect);
const { connect } = await import("cloudflare:sockets");

return connect;
} catch (e) {
return await import("@arrowood.dev/socket").then((r) => r.connect);
try {
const { connect } = await import("@arrowood.dev/socket");

return connect;
} catch (e) {
throw new Error("No socket provider found");
}
}
}

0 comments on commit 519aacd

Please sign in to comment.