热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Redis常用命令和Jedis常用方法

基本数据类型及常用命令: String SET name 'penn' GET name 'penn' Hash(哈希) HMSET penn name
基本数据类型及常用命令:


String


SET name 'penn'


GET name


'penn'


Hash(哈希)


HMSET penn name zhangxiaopeng age 27 email xinqing5130@163.com


HGETALL penn


HGET penn name


HKEYS penn


HVALS penn


List(列表)


LPUSH books java nosql jms dubbo zookeeper activeMQ


LPUSH books bigdata


LLEN books


LRANGE books 0 5


LINDEX books 2


Set(集合)


SADD mobile iphone meizu xiaomi huawei


SADD mymobile iphone meizu oppon


SMEMBERS mobile


SCARD mobile


SDIFF mobile mymobile //注意顺序


SINTER mobile mymobile


SUNION mobile mymobile


Sorted Set(有序集合)


ZADD weeks 0 sunday 1 monday 2 tuesday 3 wednesday 4 thurday 5 friday 6 saturday 


ZRANGE weeks 0 10 

ZRANGE weeks 0 10 WITHSCORES


Jedis
Jedis jedis = new Jedis("192.168.0.100", 6379); 
jedis.auth("admin");  


jedis.set("name","xinxin");
System.out.println(jedis.get("name"));//执行结果:xinxin  
jedis.append("name", " is my lover");
System.out.println(jedis.get("name")); //执行结果:xinxin is my lover
jedis.del("name");
System.out.println(jedis.get("name"));




jedis.mset("name","liuling","age","23","qq","476777XXX");
System.out.println(jedis.get("name") + "-" + jedis.get("age") + "-" + jedis.get("qq"));
jedis.incr("age");


//map 
//h
Map map = new HashMap();
map.put("name", "xinxin");
map.put("age", "22");
map.put("qq", "123456");
jedis.hmset("user",map);


System.out.println(jedis.exists("user"));
System.out.println(jedis.hlen("user")); 
System.out.println(jedis.hmget("user", "age"));
jedis.hdel("user","age");
System.out.println(jedis.hkeys("user"));
System.out.println(jedis.hvals("user"));


        Iterator iter=jedis.hkeys("user").iterator();  
        while (iter.hasNext()){  
             String key = iter.next();  
             System.out.println(key+":"+jedis.hmget("user",key));  
         } 


//list
//l
jedis.lpush("java framework","spring"); 
jedis.lpush("java framework","struts"); 
jedis.lpush("java framework","hibernate");  
System.out.println(jedis.lrange("java framework",0,-1));  
jedis.rpush("java framework","spring"); 
System.out.println(jedis.lrange("java framework",0,-1));





jedis.del("a");
jedis.lpush("a",1);
jedis.lpush("a",3);
jedis.lpush("a",6);
jedis.lpush("a",9);
System.out.println(jedis.lrange("a",0,-1));
System.out.println(jedis.sort("a"));
System.out.println(jedis.lrange("a",0,-1));




//set
//s
jedis.sadd("user","liuling"); 
jedis.sadd("user","xinxin");
jedis.sadd("user","ling");  
jedis.sadd("user","zhangxinxin");
jedis.sadd("user","who");  


System.out.println(jedis.smembers("user"));
System.out.println(jedis.sismember("user","xinxin"));
System.out.println(jedis.srandmember("user"));//返回一个随机数
System.out.println(jedis.scard("user"));
System.out.println(jedis.srem("user","xinxin"));


推荐阅读
author-avatar
jojo
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有