您的位置:首页 > 数据库 > Redis

Java操作Redis--Jedis

2016-04-14 22:35 471 查看
新建一个Mevean控制台项目 RedisDemo



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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.foundjet</groupId>
<artifactId>RedisDemo</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>RedisDemo Maven Webapp</name>
<url>http://maven.apache.org</url>
<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>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>RedisDemo</finalName>
</build>
</project>


RedisProgram.java

package com.foundjet.console;

import redis.clients.jedis.Jedis;

public class RedisProgram {

public static void main(String[] args) {
System.out.println("Hello");

// 连接本地的 Redis 服务
Jedis jedis = new Jedis("localhost");
System.out.println("Connection to server sucessfully");

jedis.flushDB();
// 设置 redis 字符串数据
jedis.set("tom", "Tom --->7");
// 获取存储的数据并输出
System.out.println("Stored string in redis:: " + jedis.get("tom"));
//		jedis.disconnect();
jedis.disconnect();
jedis = null;
System.gc();
}

}


oschina上也有我的repositor

https://git.oschina.net/foundjet/RedisDemo.git




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: