Keys,scan,flushdb, wait, where are these orders?

Source: Internet
Author: User
Tags redis

Some of the common recurring problems are:

Don't seem to see such as: Key (...) or Scan (...) method? How can I query which keys are in the database?

Or

There seems to be no Flush (...) method? How can I remove all the keys in my database?

The key word here, oddly enough, was the last one:database. I don't know how to translate this sentence.

Oddly, the last of the keywords here is: database.????

Because the target scenario (or purpose) of the Stackexchange.redis service is a clustered service, it is important to know the database that the command targets (a logical database that can be distributed across multiple nodes) and the server to which the command is directed. The following commands are for a single server:

    • Keys/scan
    • Flushdb/flushall
    • Randomkey
    • CLIENT
    • CLUSTER
    • Config/info/time
    • Slaveof
    • Save/bgsave/lastsave
    • SCRIPT (do not confuse with Eval/evalsha)
    • SHUTDOWN
    • Slowlog
    • PUBSUB (not to be confused with commands such as Publish/subscribe)
    • Some DEBUG operations

(I may have forgotten that many commands are not enumerated) most of them will appear obvious, but the first three lines are less obvious:

    • Keys/scan is not in all logical databases, but only the key of the current server;
    • Flushdb/flushall is not in all logical databases, but only removes the key from the current database;
    • Randomkey is not in all the logical database, but only in the current database to select a key;

In fact, when Stackexchange.redis uses the Idatabase API, it deceives the Randomkey command, which in fact chooses a target server in a random way. But this is not possible for the rest of us.

So how do I use them?

Let's start with a server instead of starting with a database.

Get the target server var server = conn. Getserver (Someserver); //In the database with index 0 showing all keys, the key name must match *foo*foreach ("*foo*")) {Console.WriteLine (key);} //Clears all keyserver from the database indexed to 0. Flushdatabase ();     

Note: This is different from the Idatabase API (the target database has been selected when the Getdatabase () method is called), you can pass an optional parameter to these methods to select the database, default is 0.

Special attention is paid to the Keys (...) method: The method does not have a corresponding *async async method. The reason is that working in the background, the system determines the most appropriate method to use (KEYS vs SCAN, server-based version), and if possible will use the SCAN method to process the IEnumerable parameters of your callback, The parameter is paged out internally: so you never see a detailed implementation of the cursor operation. If SCAN is not available, the KEYS will be used, which may cause blocking on the server. Either way, scan and keys need to be scanned for the entire key space, so it should be avoided on the production server, or at least for the slave server.

So do I need to remember the server I'm connected to? That was awful!

Not exactly, you can use Coon. The Getendpoints () method lists the endpoints (either all known or specified in the original configuration: this is not necessarily the same thing), and you can iterate over the Getserver () method to find the server you want (for example: Select a Slave server).

Keys,scan,flushdb, wait, where are these orders?

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.