-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't try to connect to redis while making production build.
- Loading branch information
Showing
1 changed file
with
48 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,53 @@ | ||
import { building } from '$app/environment'; | ||
import { env } from '$env/dynamic/private'; | ||
import { createClient } from 'redis'; | ||
import { createClient, type RedisClientType } from 'redis'; | ||
|
||
/** The global redis client used by the Weird server. */ | ||
export const redis = await createClient({ | ||
url: env.REDIS_URL | ||
// EXPERIMENTAL: Currently using transactions, aka MULTI, instead. | ||
// scripts: { | ||
// /** This is meant to claim a new weird username and associate 3 things to each-other: | ||
// * rauthy user ID, iroh namespace pubkey, the actual username */ | ||
// claimUsername: defineScript({ | ||
// SCRIPT: ` | ||
// local usernameKey = KEYS[1] | ||
// local rauthyIdKey = KEYS[2] | ||
// local subspaceKey = KEYS[3] | ||
// local username = ARGV[1] | ||
// local rauthyId = ARGV[2] | ||
// local subspace = ARGV[3] | ||
export let redis: RedisClientType = null as any; | ||
|
||
// if redis.call("EXISTS", usernameKey) > 0 then | ||
// return redis.error_reply(string.format("USER_EXISTS The username '%s' already exists so it cannot be claimed.", username)) | ||
// end | ||
if (!building) { | ||
redis = (await createClient({ | ||
url: env.REDIS_URL | ||
// EXPERIMENTAL: Currently using transactions, aka MULTI, instead. | ||
// scripts: { | ||
// /** This is meant to claim a new weird username and associate 3 things to each-other: | ||
// * rauthy user ID, iroh namespace pubkey, the actual username */ | ||
// claimUsername: defineScript({ | ||
// SCRIPT: ` | ||
// local usernameKey = KEYS[1] | ||
// local rauthyIdKey = KEYS[2] | ||
// local subspaceKey = KEYS[3] | ||
// local username = ARGV[1] | ||
// local rauthyId = ARGV[2] | ||
// local subspace = ARGV[3] | ||
|
||
// redis.call("HSET", usernameKey, "subspace", subspace) | ||
// redis.call("HSET", usernameKey, "rauthyId", rauthyId) | ||
// redis.call("HSET", rauthyIdKey, "username", username) | ||
// redis.call("HSET", rauthyIdKey, "subspace", subspace) | ||
// redis.call("HSET", subspaceKey, "username", username) | ||
// redis.call("HSET", subspaceKey, "rauthyId", rauthyId) | ||
// redis.call("HSET", "testing", "dummy", "something") | ||
// `, | ||
// NUMBER_OF_KEYS: 3, | ||
// FIRST_KEY_INDEX: 1, | ||
// transformArguments(username: string, rauthyId: string, subspace: string) { | ||
// return [ | ||
// 'weird:users:names:' + username, | ||
// 'weird:users:rauthyIds:' + rauthyId, | ||
// 'weird:users:subspaces:' + subspace, | ||
// username, | ||
// rauthyId, | ||
// subspace | ||
// ]; | ||
// } | ||
// }) | ||
// } | ||
}) | ||
.on('error', (err) => console.error('Redis client error', err)) | ||
.connect(); | ||
// if redis.call("EXISTS", usernameKey) > 0 then | ||
// return redis.error_reply(string.format("USER_EXISTS The username '%s' already exists so it cannot be claimed.", username)) | ||
// end | ||
|
||
// redis.call("HSET", usernameKey, "subspace", subspace) | ||
// redis.call("HSET", usernameKey, "rauthyId", rauthyId) | ||
// redis.call("HSET", rauthyIdKey, "username", username) | ||
// redis.call("HSET", rauthyIdKey, "subspace", subspace) | ||
// redis.call("HSET", subspaceKey, "username", username) | ||
// redis.call("HSET", subspaceKey, "rauthyId", rauthyId) | ||
// redis.call("HSET", "testing", "dummy", "something") | ||
// `, | ||
// NUMBER_OF_KEYS: 3, | ||
// FIRST_KEY_INDEX: 1, | ||
// transformArguments(username: string, rauthyId: string, subspace: string) { | ||
// return [ | ||
// 'weird:users:names:' + username, | ||
// 'weird:users:rauthyIds:' + rauthyId, | ||
// 'weird:users:subspaces:' + subspace, | ||
// username, | ||
// rauthyId, | ||
// subspace | ||
// ]; | ||
// } | ||
// }) | ||
// } | ||
}) | ||
.on('error', (err) => console.error('Redis client error', err)) | ||
.connect()) as RedisClientType; | ||
} |