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

RedisPersistence not using provided configuration #37

Open
tyler-mccarthy opened this issue Dec 26, 2024 · 0 comments
Open

RedisPersistence not using provided configuration #37

tyler-mccarthy opened this issue Dec 26, 2024 · 0 comments
Assignees
Labels

Comments

@tyler-mccarthy
Copy link

I am trying to use the RedisPersistence class from the y-redis library to connect to a Redis server with custom host, port, and password. Despite providing the correct configuration, the connection defaults to localhost:6379.

Issue - passing variables directly to RedisPersistence:


require('dotenv').config();
const http = require('http');
const WebSocket = require('ws');
const setupWSConnection = require('y-websocket/bin/utils').setupWSConnection;
const RedisPersistence = require('y-redis').RedisPersistence;

// Redis Configuration without TLS
const redisConfig = {
  host: REDIS_HOST,
  port: REDIS_PORT,
  password: REDIS_PASSWORD,
};

console.log('Redis Config:', redisConfig);

const redisPersistence = new RedisPersistence(redisConfig);

// Debug: Verify the RedisPersistence configuration
console.log('Redis Persistence:', redisPersistence);

// WebSocket Server Configuration
const port = 1234;
const server = http.createServer();
const wss = new WebSocket.Server({ server });

wss.on('connection', (ws, request) => {
  const roomName = request.url.slice(1); // Remove leading "/"

  setupWSConnection(ws, request, {
    docName: roomName,
    gc: false, // Disable garbage collection for persistence
    persistence: redisPersistence, // Use Redis persistence
  });
});

server.listen(port, () => {
  console.log(`✅ y-websocket server running on http://localhost:${port} with Redis persistence enabled`);
});

Output of redis persistence showing config despite passing unique values to host, port and password it defaults to localhost:6379:

Redis Persistence:  RedisPersistence {
  _observers: Map(0) {},
  redis: Redis {
    options: {
      port: 6379,
      host: 'localhost',
      ...
    }
  }
}

Node.js version: Node.js v22.11.0
y-redis version: "^1.0.3"
Operating System: MacOS (Local Dev)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants