[hadoop][redis]#74_jedis


    <dependency>
      <groupId>redis.clientsgroupId>
      <artifactId>jedisartifactId>
      <version>3.0.1version>
    dependency>

简单的操作

jedis = new Jedis(host, port);
jedis.set("info","a ball");
jedis.close();

通常使用

public class RedisUtils {

    private static JedisPool jedisPool = null;

    private static final String HOST = "VM_16_17_centos";
    private static final int PORT = 6379;

    public static synchronized Jedis getJedis(){

        if(null == jedisPool) {
            GenericObjectPoolConfig config = new JedisPoolConfig();
            config.setMaxIdle(10);
            config.setMaxTotal(100);
            config.setMaxWaitMillis(1000);
            config.setTestOnBorrow(true);

            jedisPool = new JedisPool(config, HOST, PORT);
        }

        return jedisPool.getResource();
    }

}

jedis = new Jedis(host, port);
Jedis jedis = RedisUtils.getJedis();
jedis.set("user","piig");
jedis.close();

tip:
redis.conf中bind 127.0.0.1 注释掉,否则无法连接

你可能感兴趣的:(hadoop)