Import Org.junit.Before;
Import Org.junit.Test;
Import Redis.clients.jedis.Jedis;
Import Java.util.Set;
Public classRedisutiltest {PrivateJedis Jedis; @Before Public voidSetup () {//Connect to a Redis server, localhost:6379Jedis =NewJedis ("localhost",6379); //Authority authenticationJedis.auth ("123456"); } /** * Delete cache by phone number*/@Test Public voidTestdelbyphonenum () {Set<String>Set= Jedis.keys ("*15555555555*"); System. out. println (Set); for(String key:Set) {Jedis.del (key); System. out. println ("""+key+""The deleted!"); } }}
Keys PublicSet<string>keys (String pattern) Returns all the keys matching the glob-style pattern asSpace separated strings. For exampleifYou haveinchThe database The keys"Foo"and"Foobar"The command"KEYS foo*"Wouldreturn "Foo foobar". Note that whileThe time complexity for ThisOperation isO (n) The constant times is pretty low. For example Redis running in an entry level laptop can scan a1Million Keys databaseinch +Milliseconds. Still it's better to consider this one of the slow commands, that could ruin the DB performance if not used with care.In other words ThisCommand isIntended only forDebugging and special operations like creating a script to change the DB schema. Don't use it in your normal code. Use Redis sets on order to group together a subset of objects.Glob Style Patterns Examples:h?Llo'll match Hello Hallo Hhlloh*Llo would match Hllo Heeeelloh[ae]llo would match hello and Hallo, but not hillouse \ to escape special charsifYou want to match them verbatim.
Redis Common operations