Search in sources :

Example 1 with BasicCommands

use of redis.clients.jedis.BasicCommands in project YCSB by brianfrankcooper.

the class RedisClient method init.

public void init() throws DBException {
    Properties props = getProperties();
    int port;
    String portString = props.getProperty(PORT_PROPERTY);
    if (portString != null) {
        port = Integer.parseInt(portString);
    } else {
        port = Protocol.DEFAULT_PORT;
    }
    String host = props.getProperty(HOST_PROPERTY);
    boolean clusterEnabled = Boolean.parseBoolean(props.getProperty(CLUSTER_PROPERTY));
    if (clusterEnabled) {
        Set<HostAndPort> jedisClusterNodes = new HashSet<>();
        jedisClusterNodes.add(new HostAndPort(host, port));
        jedis = new JedisCluster(jedisClusterNodes);
    } else {
        String redisTimeout = props.getProperty(TIMEOUT_PROPERTY);
        if (redisTimeout != null) {
            jedis = new Jedis(host, port, Integer.parseInt(redisTimeout));
        } else {
            jedis = new Jedis(host, port);
        }
        ((Jedis) jedis).connect();
    }
    String password = props.getProperty(PASSWORD_PROPERTY);
    if (password != null) {
        ((BasicCommands) jedis).auth(password);
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) Jedis(redis.clients.jedis.Jedis) JedisCluster(redis.clients.jedis.JedisCluster) Properties(java.util.Properties) BasicCommands(redis.clients.jedis.BasicCommands) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 BasicCommands (redis.clients.jedis.BasicCommands)1 HostAndPort (redis.clients.jedis.HostAndPort)1 Jedis (redis.clients.jedis.Jedis)1 JedisCluster (redis.clients.jedis.JedisCluster)1