zoukankan      html  css  js  c++  java
  • Redis 常用操作

    
    
    import org.junit.Before;
    import org.junit.Test;
    import redis.clients.jedis.Jedis;

    import java.util.Set;

    public
    class RedisUtilTest { private Jedis jedis; @Before public void setup(){ //连接redis服务器,localhost:6379 jedis = new Jedis("localhost", 6379); //权限认证 jedis.auth("123456"); } /** * 通过手机号删除缓存 */ @Test public void testDelByPhoneNum(){ Set<String> set = jedis.keys("*15555555555*"); System.out.println(set); for(String key: set){ jedis.del(key); System.out.println(""+key+"】have deleted!"); } } }
    keys
    
    public Set<String> keys(String pattern)
    Returns all the keys matching the glob-style pattern as space separated strings. For example if you have in the database the keys "foo" and "foobar" the command "KEYS foo*" will return "foo foobar".
    Note that while the time complexity for this operation is O(n) the constant times are pretty low. For example Redis running on an entry level laptop can scan a 1 million keys database in 40 milliseconds. Still it's better to consider this one of the slow commands that may ruin the DB performance if not used with care.
    
    In other words this command is intended only for debugging and special operations like creating a script to change the DB schema. Don't use it in your normal code. Use Redis Sets in order to group together a subset of objects.
    
    Glob style patterns examples:
    
    h?llo will match hello hallo hhllo
    h*llo will match hllo heeeello
    h[ae]llo will match hello and hallo, but not hillo
    Use  to escape special chars if you want to match them verbatim.
  • 相关阅读:
    Java知识体系之基础知识
    002-JavaNIO
    001-四种常见的IO模型
    c/c++面试题(6)运算符重载详解
    c/c++面试题(5)(c++重要的概念详解)
    c/c++面试题(4)字符串翻转/打印任意进制格式/类型转换
    c/c++面试题(3)strcat/strcmp/strlen/strcpy的实现
    c/c++面试题(2)
    c/c++面试题(1)
    cocos2dx 3.0 之 lua 创建类 (二)
  • 原文地址:https://www.cnblogs.com/mengjianzhou/p/6180224.html
Copyright © 2011-2022 走看看