Redis Common operations

Source: Internet
Author: User
Tags glob delete cache redis server

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.