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的关联

posted @ 2011-12-27 16:51  ybtyoyo  阅读(4206)  评论(0编辑  收藏  举报