Skip to content

Commit

Permalink
fix: allow to use Redis without user/pass
Browse files Browse the repository at this point in the history
  • Loading branch information
esroyo committed Jan 21, 2025
1 parent d533c36 commit 42af58f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CachePersistenceDenoKv,
CachePersistenceFactory,
CachePersistenceRedis,
type CachePersistenceRedisOptions,
CacheStorage,
} from '@esroyo/web-cache-api-persistence';

Expand All @@ -30,21 +31,25 @@ if (config.CACHE) {
let persistenceFactory: CachePersistenceFactory | undefined;
if (
config.CACHE_REDIS_HOSTNAME &&
config.CACHE_REDIS_PORT &&
config.CACHE_REDIS_PASSWORD &&
config.CACHE_REDIS_USERNAME
config.CACHE_REDIS_PORT
) {
persistenceFactory = {
create: async () =>
new CachePersistenceRedis({
create: async () => {
const redisOptions: CachePersistenceRedisOptions = {
hostname: config.CACHE_REDIS_HOSTNAME!,
port: config.CACHE_REDIS_PORT,
username: config.CACHE_REDIS_USERNAME,
password: config.CACHE_REDIS_PASSWORD,
tls: config.CACHE_REDIS_TLS,
max: config.CACHE_CONN_MAX,
min: config.CACHE_CONN_MIN,
}),
};
if (config.CACHE_REDIS_USERNAME) {
redisOptions.username = config.CACHE_REDIS_USERNAME;
}
if (config.CACHE_REDIS_PASSWORD) {
redisOptions.password = config.CACHE_REDIS_PASSWORD;
}
return new CachePersistenceRedis(redisOptions);
},
};
} else {
persistenceFactory = {
Expand Down

0 comments on commit 42af58f

Please sign in to comment.