NoSQL之redis(Jedis链接 API)

  1. 工程搭建:php

    (1)介绍:redis不只使用命令能够操做,如今基本上主流的语言都有客户端支持,好比:java、C、C#、C++、php、Node.js、Go等。java

        这里介绍的是Jedis地址:https://github.com/xetorthio/jedisgit

    (2)依赖github

                <dependency>
                     <groupId>redis.clients</groupId>
                     <artifactId>jedis</artifactId>
                     <version>3.0.0</version>
                </dependency>ide

2.APIoop

   (1)单实例链接redisspa

public class JedisUtils {
    public void jedisClient(){
        /**
         * new Jedis(pars1,pars2);
         * pars1:hostname:String
         * port:int
         */
        Jedis jedis=new Jedis("hadoop03",6379);
        //经过redis赋值
        jedis.set("name","zs");
        //经过redis获取值
        String name=jedis.get("name");

        //释放资源
        jedis.close();
    }
}

                (2)使用jedis链接池链接redis服务hadoop

public void jedisPoolClient(){
    /**
     * new JedisPool(pars1,pars2);
     * pars1:String,能够写入一个集群如:redis01,redis03...
     * port:int 端 口
     */
    JedisPool pool=new JedisPool("hadoop03",6379);
    //获取Jedis实例
    Jedis jedis=pool.getResource();

    //释放资源
    jedis.close();
    pool.close();
}
相关文章
相关标签/搜索