Redis Java客户端Jedis入门

Linux 下 redis 的安装及运行可以参考随笔 (redis 入门与安装)

一、jedis 下载

https://github.com/xetorthio/jedis/downloads上下载 jedis-2.0.0.jar

二、将 jedis-2.0.0.jar 放入 eclipse\plugins 的目录中

打开 Window->Preferences->Java->Install JREs

在 jre6->Edit->Add External JARs 把 eclipse\plugins\jedis-2.0.0.jar 添加进来。

三、进入Maven 生成 Helloworld编辑 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.marshal</groupId>
<artifactId>helloworld</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>helloworld</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

四、编辑 App.java

package org.marshal;
import redis.clients.jedis.Jedis;
/**
* Hello world!
*
*/
public class App
{
public static void main(String[] args )
{
System.out.println("Hello World!");
Jedis jedis = new Jedis("redis-server.ipaddress");//redis 服务器地址
jedis.auth("requiepass");// 验证密码
jedis.set("java", "java hello world");
String value = jedis.get("java");
System.out.println(value);
}
}

五、运行 App 程序

Hello World!
java hello world

六、Eclipse 上 jedis javadoc 的关联

1、jedis-Javadoc 的下载地址:

http://www.jarvana.com/jarvana/view/redis/clients/jedis

2、eclipse 中 javadoc 的关联