jlthlx 发表于 2016-12-17 08:30:24

redis demo

  环境:CentOS5.x+Redis3.0+Jdk8+Maven3.x
  步骤:
  CentOS5.x安装Redis。这个根据官网的操作即可。
  1.1

$ wget http://download.redis.io/releases/redis-3.0.0.tar.gz
$ tar xzf redis-3.0.0.tar.gz
$ cd redis-3.0.0
$ make
   
  1.2 安装完成后,开启服务:

$src/redis-server
   
  1.3、用自身的客户端测试:

$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
   
  2、用Java来测试
  2.1 新建maven工程(会在附件中给出)
  2.2 引入jedis的maven坐标

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.6.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
  2.3 引入junit4的坐标

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
  2.4 运行以下Java代码,set一个值进去,再get出来。

@Test
public void testRedis(){
Jedis jedis = new Jedis("192.168.0.107", 6379);
jedis.set("foo", "bar");
String value = jedis.get("foo");
System.out.println(value);
}
  2.5 运行结果:
  foo.
  参考资料:http://redis.io/download   redis官网
  https://github.com/xetorthio/jedis jedis客户端的gitHub
  http://blog.csdn.net/vv_demon/article/details/7676415 网上的Redis例子1
  http://www.cnblogs.com/liuling/p/2014-4-19-04.html 网上的Redis例子2
页: [1]
查看完整版本: redis demo