原文转自:http://www.cnblogs.com/kreo/p/4399612.html
http://www.cnblogs.com/liuling/p/2014-4-19-04.html
二.linux下安装
#下载
wget http://download.redis.io/releases/redis-3.0.0.tar.gz
tar zxvf redis-3.0.0.tar.gz
cd redis-3.0.0
#如果不加参数,linux下会报错
make MALLOC=libc
安装好之后,启动文件
#启动redis
src/redis-server &
#关闭redis
src/redis-cli shutdown
测试redis
$ src/redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
$
测试成功
java main 方法做简单测试
public class TestRedis {
private Jedis jedis;
public void setup() {
//连接redis服务器,192.168.0.100:6379
jedis = new Jedis("192.168.1.146", 6379);
//权限认证
// jedis.auth("admin");
}
/**
* redis存储字符串
*/
public void testString() {
//-----添加数据----------
jedis.set("name","xinxin");//向key-->name中放入了value-->xinxin
System.out.println(jedis.get("name"));//执行结果:xinxin
jedis.append("name", " is my lover"); //拼接
System.out.println(jedis.get("name"));
jedis.del("name"); //删除某个键
System.out.println(jedis.get("name"));
//设置多个键值对
jedis.mset("name","liuling","age","23","qq","476777XXX");
jedis.incr("age"); //进行加1操作
System.out.println(jedis.get("name") + "-" + jedis.get("age") + "-" + jedis.get("qq"));
}
public static void main(String[] args) {
TestRedis redis = new TestRedis();
redis.setup();
redis.testString();
}