All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.litongjava.tio.utils.dsn.RedisUrlParser Maven / Gradle / Ivy

There is a newer version: 3.7.3.v202400213-RELEASE
Show newest version
package com.litongjava.tio.utils.dsn;

import java.net.URI;
import java.net.URISyntaxException;

public class RedisUrlParser {

  public RedisInfo parse(String redisUrl) {
    URI uri;
    try {
      uri = new URI(redisUrl);
      String host = uri.getHost();
      int port = uri.getPort();
      String userInfo = uri.getUserInfo();

      String password = null;
      if (userInfo != null) {
        String[] userInfoParts = userInfo.split(":", 2);

        if (userInfoParts.length > 1 && !"default".equals(userInfoParts[0])) {
          password = userInfoParts[1];
        }
      }
      return new RedisInfo(host, port, password);
    } catch (URISyntaxException e) {
      new RuntimeException(e);
    }

    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy