redis java api

package com.weeego;
import redis.clients.jedis.Jedis;
/**
* @author 274836
*
*/
public class TestJedis {
/**
* @param args
*/
public static void main(String[] args) {
Jedis jedis = new Jedis(“10.79.6.86″,7777,1000);
jedis.set(“java”, “http://java.androidwhy.com”);
String value = jedis.get(“java”);
System.out.println(value);
jedis.set(“zuaa”, “1212″);
System.out.println(“设置key的有效时间”);
jedis.expire(“zuaa”, 1);
System.out.println(“三秒内读取值”+jedis.get(“zuaa”));
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(“三秒后读取值”+jedis.get(“zuaa”));
}
}
 
 
 
 
———-pom文件———
<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>com.weeego</groupId>
<artifactId>jedis-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!– redis 客户端 –>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>

通过 Wiz 发布

附件列表

     

    Leave a comment

    0 Comments.

    Leave a Reply


    [ Ctrl + Enter ]