合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
public class TestReidsCommon { ​ public static void main(String\[\] args) { // 创建连接 Jedis jedis = new Jedis("192.168.120.129", 6379); // 设置密码 如果没有密码可以不设置 jedis.auth("123456"); // key Set<String> keys = jedis.keys("\*"); for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); System.out.println(key); } System.out.println("jedis.exists====>" + jedis.exists("k2")); System.out.println(jedis.ttl("k1")); // String // jedis.append("k1","myreids"); System.out.println(jedis.get("k1")); jedis.set("k4", "k4\_redis"); System.out.println("----------------------------------------"); jedis.mset("str1", "v1", "str2", "v2", "str3", "v3"); System.out.println(jedis.mget("str1", "str2", "str3")); // list System.out.println("----------------------------------------"); // jedis.lpush("mylist","v1","v2","v3","v4","v5"); List<String> list = jedis.lrange("mylist", 0, -1); for (String element : list) { System.out.println(element); } // set jedis.sadd("orders", "jd001"); jedis.sadd("orders", "jd002"); jedis.sadd("orders", "jd003"); Set<String> set1 = jedis.smembers("orders"); for (Iterator<String> iterator = set1.iterator(); iterator.hasNext();) { String string = (String) iterator.next(); System.out.println(string); } jedis.srem("orders", "jd002"); System.out.println(jedis.smembers("orders").size()); // hash jedis.hset("hash1", "userName", "lisi"); System.out.println(jedis.hget("hash1", "userName")); Map<String, String> map = new HashMap<String, String>(); map.put("telphone", "15902738715"); map.put("address", "whsxt"); map.put("email", "leijharvin@163.com"); jedis.hmset("hash2", map); List<String> result = jedis.hmget("hash2", "telphone", "email"); for (String element : result) { System.out.println(element); } // zset jedis.zadd("zset01", 60d, "v1"); jedis.zadd("zset01", 70d, "v2"); jedis.zadd("zset01", 80d, "v3"); jedis.zadd("zset01", 90d, "v4"); ​ Set<String> s1 = jedis.zrange("zset01", 0, -1); for (Iterator<String> iterator = s1.iterator(); iterator.hasNext();) { String string = (String) iterator.next(); System.out.println(string); } jedis.close(); } }