day034redis*jedis
jedis
jedis.jar fastjson.jar包导入
package redis0;
import com.alibaba.fastjson.JSONObject;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
Jedis jedis = new Jedis("127.0.0.1",6379);
System.out.println( "Hello World!****redis**"+jedis.ping() );
// jedis.set("moey","55");
// jedis.set("out","0");
// jedis.lpush("list","li1","li2");
// jedis.sadd("sset","sset","3333");
// jedis.zadd("zset",11,"nn");
jedis.hset("hash1","h1","hhh1");
System.out.println(jedis.get("out")+"***lrange:"+jedis.lrange("list",0,-1)+"*****smembers:"+jedis.smembers("sset")
+"***zrange"+jedis.zrange("zset",0,-1)+"****hgetall"+jedis.hgetAll("hash1")
);
jedis.select(2);
JSONObject jsonObject = new JSONObject();
jsonObject.put("one","1111");
jsonObject.put("two","2222");
String res = jsonObject.toJSONString();
System.out.println("res:"+res);
Transaction transaction = jedis.multi();//开启事务
transaction.set("user1",res);
transaction.set("user2",res);
// transaction.discard();//放弃事务
transaction.exec();//提交事务
System.out.println(jedis.get("user1"));
System.out.println(jedis.get("user2"));
jedis.close();
}
}
rdb fork进程将最近一次的数据持久化到rdb文件 唯一缺点最后一次宕机前可能没保存 快照
save 60 10 如果60秒内修改了10次触发快照 redis database
aof 将所有执行过的sql全部持久化到文件 恢复需要全部执行一次 效率低
append onlu file 追加文件