I am using iron-session
to handle the sessions on my nextjs app, but some of the sessions were too big so I created only a key with the iron-session
and getting the result using Redis.
I have a really basic connector
import { createClient } from 'redis';
import { logError } from './logger';
const client = createClient({ url: process.env.REDIS_URL });
client.on('error', (error) => {
logError(error)
});
export async function connect() {
if (!client.isOpen) await client.connect()
return client
}
But I have a lot Socket closed unexpectedly
error, should be because I am never calling the quit
function.
I do not know if this is a big issue for the Redis server to have this kind of error all the time, if not, I could just ignore this it.
The other solution would be to call quit
at the end of each my api
and getServerSideProps
which are using sessions from Redis, but I do not find it spotless, it will be a lot of code and complexity