R
Railway10mo ago
Boxer

Connecting to redis service with private url?

anyone using ioredis, is this the correct way to connect to the internal redis service?
import Redis from 'ioredis';

const redis = new Redis(Bun.env.REDIS_PRIVATE_URL);

export default redis;
import Redis from 'ioredis';

const redis = new Redis(Bun.env.REDIS_PRIVATE_URL);

export default redis;
I don't seem to get any errors on my code, but it's not looking at redis at all. my code just stops?
import redis from '@cache/redis';
import { logger } from '@common/logger';

export async function isSuccessChannel(message: Message) {
try {
const { channel_id, guild_id } = selectChannelSchema.parse({
channel_id: BigInt(message.channelId),
guild_id: BigInt(message.guildId as string),
});

const cacheKey = `guild:${guild_id}:channel:${channel_id}:isSuccess`;

// First, check if the result is in the cache
logger.info(`Checking cache for channel (${channel_id})`);
const cachedResult = await redis.get(cacheKey); // CODE STOPS WORKING FROM HERE AND NO LOGS
if (cachedResult !== null) {
logger.info(`Cached channel (${channel_id}) is success: ${cachedResult}`);
return cachedResult === 'true';
}

logger.info(`Channel (${channel_id}) is not cached, checking database`);

....
import redis from '@cache/redis';
import { logger } from '@common/logger';

export async function isSuccessChannel(message: Message) {
try {
const { channel_id, guild_id } = selectChannelSchema.parse({
channel_id: BigInt(message.channelId),
guild_id: BigInt(message.guildId as string),
});

const cacheKey = `guild:${guild_id}:channel:${channel_id}:isSuccess`;

// First, check if the result is in the cache
logger.info(`Checking cache for channel (${channel_id})`);
const cachedResult = await redis.get(cacheKey); // CODE STOPS WORKING FROM HERE AND NO LOGS
if (cachedResult !== null) {
logger.info(`Cached channel (${channel_id}) is success: ${cachedResult}`);
return cachedResult === 'true';
}

logger.info(`Channel (${channel_id}) is not cached, checking database`);

....
Solution:
this is how i do it, the family: 0 is whats important
Jump to solution
5 Replies
Percy
Percy10mo ago
Project ID: f78d75b5-8972-4d61-8517-22bbccefb41e
Solution
Brody
Brody10mo ago
this is how i do it, the family: 0 is whats important
Brody
Brody10mo ago
import Redis from "ioredis";

const redisURL = new URL(process.env.REDIS_PRIVATE_URL);

const redis = new Redis({
family: 0,
host: redisURL.hostname,
port: redisURL.port,
username: redisURL.username,
password: redisURL.password
});

console.log(await redis.ping());
import Redis from "ioredis";

const redisURL = new URL(process.env.REDIS_PRIVATE_URL);

const redis = new Redis({
family: 0,
host: redisURL.hostname,
port: redisURL.port,
username: redisURL.username,
password: redisURL.password
});

console.log(await redis.ping());
Boxer
Boxer10mo ago
That worked also had to add a sleep to my start script
"start": "sleep 3 && bun run ./dist/index.js",
"start": "sleep 3 && bun run ./dist/index.js",
Ty @Brody
Brody
Brody10mo ago
no problem!
Want results from more Discord servers?
Add your server