How to configure lettuce client IP

61 views
Skip to first unread message

Gaurav Singh

unread,
Aug 11, 2020, 11:10:05 AM8/11/20
to lettuce-redis-client-users
Hello folks,

As there is an obvious requirement to communicate via a particular VLAN (from lettuce client to Redis DB), we need to set/configure client IP to lettuce before initiating connection towards DB server. As lettuce is built on Netty , what are the options to set client socket IP (if not port)?

Usually in **Netty** we can pass localAddress in addition to remoteAddress while calling connect() on bootstrap.

How we can set the loacalAddress here in lettuce?

Gaurav Singh

unread,
Aug 12, 2020, 1:59:08 AM8/12/20
to lettuce-redis-client-users
I can see the  DefaultNettyCustomizer  doesn't have implementation for  afterBootstrapInitialized(Bootstrap bootstrap) .  

Mark Paluch

unread,
Aug 12, 2020, 9:19:11 AM8/12/20
to lettuce-redis-client-users
You can register a NettyCustomizer object in ClientResources. Implement the afterBoostrapInitialized(…) method to add your netty customizations.

Gaurav Singh

unread,
Aug 13, 2020, 10:46:45 AM8/13/20
to lettuce-redis-client-users
Thanx Mark.

I have registered the NettyCustomizer object and its working. Just one query - I can see the  afterBoostrapInitialized () method was invoked many times. Is this a correct behavior.

Mark Paluch

unread,
Aug 13, 2020, 11:50:50 AM8/13/20
to lettuce-redis-client-users
Great to hear. The expectation is that the customizer gets invoked for each connection that is made once. If you're calling RedisClient.connect() once, then afterBootstrapInitialized(…) should be called once. If you're RedisClusterClient or call multiple times(), then you should see the method being called multiple times, once for each connection attempt.

Further down the lifecycle, Lettuce has an auto-reconnect feature. If the connection gets disconnected, then afterBoostrapInitialized(…) should be called again for reconnection purposes.

Reply all
Reply to author
Forward
0 new messages