[Hadoopの] [Redisの]#74_jedis

<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
    <dependency>
      <groupId>redis.clients</groupId>
      <artifactId>jedis</artifactId>
      <version>3.0.1</version>
    </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();

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

公開された78元の記事 ウォンの賞賛0 ビュー1386

おすすめ

転載: blog.csdn.net/qq_30782921/article/details/103753191