Java使用redis
1.下载安装redis
首先,官网不建议在windows上下载redis,官网上的是linux版,但是官网在github上有windows版本下载
Github:https://github.com/MicrosoftArchive/redis/releases
下载之后直接解压就行,解压后点redis-server.exe就启动了
图片说明
2.创建一个maven项目,这里不赘述了
在pom.xml里加入

<dependencies>
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>3.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.62</version>
    </dependency>
</dependencies>

3.测试

  Jedis jedis=new Jedis("127.0.0.1",6379);//前面参数为本地地址,后面为端口号
        System.out.println(jedis.ping());

图片说明
这里输出了pong代表连接成功。