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

How to switch between Redis dbs? #16

Closed
RickoNoNo3 opened this issue Aug 23, 2022 · 7 comments
Closed

How to switch between Redis dbs? #16

RickoNoNo3 opened this issue Aug 23, 2022 · 7 comments

Comments

@RickoNoNo3
Copy link

As we know Redis has a concept called db, which provides 16(by default) different storage spaces seperated from each other. I'm using 0-3 of them, and I want my Log4J2 append its logs to the 3rd.

I can't find a configuration property in this library's doc, does it supports?

@vy
Copy link
Owner

vy commented Aug 23, 2022

@RickoNoNo3, log4j2-redis-appender internally uses jedis, the official Java client for Redis, for interacting with Redis. There I don't see the mention of a feature similar to what you are describing. Mind providing some pointers for that feature, please?

@RickoNoNo3
Copy link
Author

I finally find something about it in the code.

private void connect() {
LOGGER.debug("{} connecting", logPrefix);
int connectionTimeoutMillis = 1_000 * connectionTimeoutSeconds;
int socketTimeoutMillis = 1_000 * socketTimeoutSeconds;
boolean sentinel = isNotBlank(sentinelNodes);
if (sentinel) {
Set<String> sentinelNodesAsSet = Stream.of(sentinelNodes.split("\\s*,\\s*"))
.filter(Strings::isNotBlank)
.collect(Collectors.toSet());
jedisPool = new JedisSentinelPool(
sentinelMaster,
sentinelNodesAsSet,
poolConfig.getJedisPoolConfig(),
connectionTimeoutMillis,
socketTimeoutMillis,
password,
0, // database
null); // clientName
} else {
jedisPool = new JedisPool(
poolConfig.getJedisPoolConfig(),
host,
port,
connectionTimeoutMillis,
socketTimeoutMillis,
password,
0, // database
null, // clientName
false, // ssl
null, // sslSocketFactory
null, // sslParameters,
null); // hostnameVerifier
}
}

The parameter is set to 0 (L243 and L253). It may be customizable.

@vy
Copy link
Owner

vy commented Aug 24, 2022

@RickoNoNo3, got it, thanks! I will try to add that.

vy added a commit that referenced this issue Aug 25, 2022
@vy
Copy link
Owner

vy commented Aug 25, 2022

@RickoNoNo3, I have added database parameter to the appender in the most recent 0.11.0-SNAPSHOT release. Would you mind confirming the fix, please?

@RickoNoNo3
Copy link
Author

RickoNoNo3 commented Aug 27, 2022

Nice work! It works fine in my SpringBoot project. I also tried to fork and modify the tests of this library, the RedisAppenderTest passed in database 10. But Embedded Redis Server was not fully effective on my Mac, so other two had not past yet. I don't think it is for the Appender.

In brief, well done!

@vy
Copy link
Owner

vy commented Aug 28, 2022

Thanks for confirming the fix! I am trying to overhaul the project. I have one more (graceful shutdown) bug in my list to process. I will probably wrap up my work this week and cut a new release. I will let you know of the new release here via dropping a comment.

@vy
Copy link
Owner

vy commented Sep 2, 2022

@RickoNoNo3, I have just released 0.11.0, enjoy while it is still hot! ☕

@vy vy closed this as completed Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants