简体   繁体   中英

Jedis connection with proxy

I'm using Jedis, I cannot connect directly to Redis, I have to use a proxy. Can I connect to Redis with Jedis using a socks proxy?

Can you help me, please.

Regards.

I was looking for a solution but could n't find any. So I have done the following changes to fix this issue:

 @NotNull
    private ProxySelector proxySelector() {
        return new ProxySelector() {
            @Override
            public List<Proxy> select(URI uri) {
                List<Proxy> proxies = new LinkedList<>();
                InetSocketAddress socketAddress =
                    new InetSocketAddress(proxyHost, proxyPort);
                proxies.add(new Proxy(Type.HTTP, socketAddress));
                return proxies;
            }

            @Override
            public void connectFailed(URI uri, SocketAddress sa, IOException e) {
                log.error(String.format(
                    "Connection to proxy server %s with socket address %s failed with error. %s",
                    uri, sa, e));
            }
        };
    }

and then set the default proxy selector: ProxySelector.setDefault(proxySelector());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM