skip to Main Content

I implemented ratelimit with redis in my spring cloud api gateway. Here is part of application.yml:

spring:  
  cloud:
    gateway:
      httpclient:
        ssl:
          useInsecureTrustManager: true
      discovery:
        locator:
          enabled: true
      routes:
        - id: test-rest-service
          uri: lb://test-rest-service
          predicates:
            - Path=/test/**
          filters:
            - RewritePath=/test/(?<path>.*), /${path}
            - name: RequestRateLimiter
              args:
                key-resolver: "#{@userRemoteAddressResolver}"
                redis-rate-limiter.replenishRate: 2
                redis-rate-limiter.burstCapacity: 3

I called a GET API via postman and checked response header.

X-RateLimit-Remaining -1
X-RateLimit-Burst-Capacity 3
X-RateLimit-Replenish-Rate 2

The rate limit is not working. Why am I getting negative value for X-RateLimit-Remaining? What does it mean? How do I fix it?

3

Answers


  1. This happened to me because there was no Redis instance launched. You have two options:

    1) Download and run a Redis instance using docker:

    docker run --name redis -d redis
    

    2) You can use in testing an Embedded Redis Server as it is explained in the following article by adding the maven dependency:

    <dependency>
      <groupId>it.ozimov</groupId>
      <artifactId>embedded-redis</artifactId>
      <version>0.7.2</version>
      <scope>test</scope>
    </dependency>
    

    And including the following snippet:

    @TestConfiguration
    public class TestRedisConfiguration {
    
        private RedisServer redisServer;
    
        public TestRedisConfiguration() {
            this.redisServer = new RedisServer(6379);
        }
    
        @PostConstruct
        public void postConstruct() {
            redisServer.start();
        }
    
        @PreDestroy
        public void preDestroy() {
            redisServer.stop();
        }
    }
    
    Login or Signup to reply.
  2. I faced the same issue recently. In my case, there was an older version of Redis installed which caused X-RateLimit-Remaining to be set to -1 constantly.

    redis-cli shutdown
    
    Login or Signup to reply.
  3. Cause: SCG (Spring Cloud Gateway) is not able to connect with redis server

    Fix: Connect SCG to redis server to get correct headers

    Details

    Check debug logs to verify the issue

    You may check logs by adding the following property in application.yml

    logging:
        level:
            root: DEBUG
    

    You will see the following logs when you will execute a request (and that request response will come with X-RateLimit-Remaining -1).

    2023-04-02T15:56:19.293+05:00 DEBUG 860131 --- [or-http-epoll-3] io.lettuce.core.RedisClient              : Trying to get a Redis connection for: redis://localhost:50989?timeout=1s
    2023-04-02T15:56:19.545+05:00 DEBUG 860131 --- [or-http-epoll-3] i.l.c.r.DefaultEventLoopGroupProvider    : Allocating executor io.netty.channel.epoll.EpollEventLoopGroup
    2023-04-02T15:56:19.545+05:00 DEBUG 860131 --- [or-http-epoll-3] i.l.c.r.DefaultEventLoopGroupProvider    : Creating executor io.netty.channel.epoll.EpollEventLoopGroup
    2023-04-02T15:56:19.547+05:00 DEBUG 860131 --- [or-http-epoll-3] i.l.c.r.DefaultEventLoopGroupProvider    : Adding reference to io.netty.channel.epoll.EpollEventLoopGroup@5231db1e, existing ref count 0
    2023-04-02T15:56:19.620+05:00 DEBUG 860131 --- [or-http-epoll-3] io.lettuce.core.RedisClient              : Resolved SocketAddress localhost/<unresolved>:50989 using redis://localhost:50989?timeout=1s
    2023-04-02T15:56:19.620+05:00 DEBUG 860131 --- [or-http-epoll-3] io.lettuce.core.AbstractRedisClient      : Connecting to Redis at localhost/<unresolved>:50989
    2023-04-02T15:56:19.656+05:00 DEBUG 860131 --- [llEventLoop-5-1] i.lettuce.core.protocol.CommandHandler   : [channel=0x1c09eca5, [id: 0x63790b3a] (inactive), epid=0x1, chid=0x1] channelRegistered()
    2023-04-02T15:56:19.673+05:00 DEBUG 860131 --- [llEventLoop-5-1] io.lettuce.core.AbstractRedisClient      : Connecting to Redis at localhost/<unresolved>:50989: localhost/<unresolved>:50989
    
    io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:50989
    Caused by: java.net.ConnectException: finishConnect(..) failed: Connection refused
        at io.netty.channel.unix.Errors.newConnectException0(Errors.java:164) ~[netty-transport-native-unix-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.unix.Errors.handleConnectErrno(Errors.java:129) ~[netty-transport-native-unix-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.unix.Socket.finishConnect(Socket.java:359) ~[netty-transport-native-unix-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:710) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:687) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:567) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:489) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:397) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.90.Final.jar:4.1.90.Final]
        at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
    
    2023-04-02T15:56:19.678+05:00 DEBUG 860131 --- [llEventLoop-5-1] io.lettuce.core.RedisChannelHandler      : closeAsync()
    2023-04-02T15:56:19.678+05:00 DEBUG 860131 --- [llEventLoop-5-1] i.lettuce.core.protocol.DefaultEndpoint  : [unknown, epid=0x1] closeAsync()
    2023-04-02T15:56:19.680+05:00 DEBUG 860131 --- [llEventLoop-5-1] i.lettuce.core.protocol.CommandHandler   : [channel=0x1c09eca5, [id: 0x63790b3a] (inactive), epid=0x1, chid=0x1] channelUnregistered()
    2023-04-02T15:56:19.685+05:00 DEBUG 860131 --- [or-http-epoll-3] o.s.c.g.f.ratelimit.RedisRateLimiter     : Error calling rate limiter lua
    
    org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis
        at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.translateException(LettuceConnectionFactory.java:1602) ~[spring-data-redis-3.0.4.jar:3.0.4]
        at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1533) ~[spring-data-redis-3.0.4.jar:3.0.4]
        at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1358) ~[spring-data-redis-3.0.4.jar:3.0.4]
        at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1341) ~[spring-data-redis-3.0.4.jar:3.0.4]
        at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedReactiveConnection(LettuceConnectionFactory.java:1083) ~[spring-data-redis-3.0.4.jar:3.0.4]
        at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getReactiveConnection(LettuceConnectionFactory.java:479) ~[spring-data-redis-3.0.4.jar:3.0.4]
        at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getReactiveConnection(LettuceConnectionFactory.java:105) ~[spring-data-redis-3.0.4.jar:3.0.4]
        at reactor.core.publisher.MonoSupplier.call(MonoSupplier.java:67) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxUsingWhen.subscribe(FluxUsingWhen.java:81) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.Mono.subscribe(Mono.java:4485) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:200) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoFlatMap.subscribeOrReturn(MonoFlatMap.java:53) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:57) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.5.4.jar:3.5.4]
        at io.github.resilience4j.reactor.circuitbreaker.operator.MonoCircuitBreaker.subscribe(MonoCircuitBreaker.java:38) ~[resilience4j-reactor-2.0.2.jar:2.0.2]
        at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxRetryWhen.subscribe(FluxRetryWhen.java:77) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoRetryWhen.subscribeOrReturn(MonoRetryWhen.java:46) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoFromFluxOperator.subscribe(MonoFromFluxOperator.java:74) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.Mono.subscribe(Mono.java:4485) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.subscribeNext(MonoIgnoreThen.java:263) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:51) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:165) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:74) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.Operators$BaseFluxToMonoOperator.completePossiblyEmpty(Operators.java:2071) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxDefaultIfEmpty$DefaultIfEmptySubscriber.onComplete(FluxDefaultIfEmpty.java:134) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onComplete(FluxContextWrite.java:126) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxMapFuseable$MapFuseableConditionalSubscriber.onComplete(FluxMapFuseable.java:350) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxFilterFuseable$FilterFuseableConditionalSubscriber.onComplete(FluxFilterFuseable.java:391) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.Operators$BaseFluxToMonoOperator.completePossiblyEmpty(Operators.java:2072) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.MonoCollect$CollectSubscriber.onComplete(MonoCollect.java:145) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:144) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:260) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:144) ~[reactor-core-3.5.4.jar:3.5.4]
        at reactor.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:415) ~[reactor-netty-core-1.1.5.jar:1.1.5]
        at reactor.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:431) ~[reactor-netty-core-1.1.5.jar:1.1.5]
        at reactor.netty.http.server.HttpServerOperations.onInboundNext(HttpServerOperations.java:663) ~[reactor-netty-http-1.1.5.jar:1.1.5]
        at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:113) ~[reactor-netty-core-1.1.5.jar:1.1.5]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at reactor.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:274) ~[reactor-netty-http-1.1.5.jar:1.1.5]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[netty-codec-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) ~[netty-codec-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:800) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:499) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:397) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.90.Final.jar:4.1.90.Final]
        at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
    Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost/<unresolved>:50989
        at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78) ~[lettuce-core-6.2.3.RELEASE.jar:6.2.3.RELEASE]
        at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56) ~[lettuce-core-6.2.3.RELEASE.jar:6.2.3.RELEASE]
        at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:350) ~[lettuce-core-6.2.3.RELEASE.jar:6.2.3.RELEASE]
        at io.lettuce.core.RedisClient.connect(RedisClient.java:216) ~[lettuce-core-6.2.3.RELEASE.jar:6.2.3.RELEASE]
        at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:111) ~[spring-data-redis-3.0.4.jar:3.0.4]
        at java.base/java.util.Optional.orElseGet(Optional.java:364) ~[na:na]
        at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:111) ~[spring-data-redis-3.0.4.jar:3.0.4]
        at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1531) ~[spring-data-redis-3.0.4.jar:3.0.4]
        ... 69 common frames omitted
    Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:50989
    Caused by: java.net.ConnectException: finishConnect(..) failed: Connection refused
        at io.netty.channel.unix.Errors.newConnectException0(Errors.java:164) ~[netty-transport-native-unix-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.unix.Errors.handleConnectErrno(Errors.java:129) ~[netty-transport-native-unix-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.unix.Socket.finishConnect(Socket.java:359) ~[netty-transport-native-unix-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.doFinishConnect(AbstractEpollChannel.java:710) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:687) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:567) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:489) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:397) ~[netty-transport-classes-epoll-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.90.Final.jar:4.1.90.Final]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.90.Final.jar:4.1.90.Final]
        at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
    

    Spin Up Redis Server

    Spin up a Redis server by executing the following docker-compose script using docker compose -f {file-name} up -d

    version: "3.8"
    services:
        polar-redis:
            image: "redis:latest"
            container_name: "polar-redis"
            ports:
              - "127.0.0.1:50988:6379"
    

    Add redis props in spring application

    Add the following props in application.yml to connect with redis server (I deliberately changed the default port of redis to 50988)

    spring:
        data:
            redis:
                connect-timeout: 2s
                host: localhost
                port: 50988
                timeout: 1s
    

    Now, restart your application. SCG should be able to connect with redis server.

    Thanks

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search