Redis Learning Notes

Source: Internet
Author: User
Tags password protection

Basic installation and Usage: http://www.tuicool.com/articles/QzMRNb

Redis access mode:./src/redis-cli-h [Host]-P [port] or directly./src/redis-server redis.conf

Reis basic usage-database: Although Redis is stored according to Key-value, Redis introduces the concept of "databse":

    • Reids installation Key-value the way to store data, each key belongs to a databses;
    • The default is Redis Open 16 database, numbered 0~15;
    • After logging in to Redis via REDIS-CLI, the default is the No. 0 databases;

Toggle databases with >select [DB INDEX] such as: Select 12

View the keys statistics for each Redis databases: >info keyspace

Redis Basic usage:

Strings:set QQ tecent;

Get QQ;

exists QQ;

Integer

INCR tresss;

INCR adds key a value stored in the number one, if it key does not exist, then key the value is initialized first 0 , and then the INCR operation is performed. If the value contains the wrong type, or if the value of the string type cannot be represented as a number, an error is returned.

DESR trees;

Lists

Rpush MyList item1;

Rpush one or more valuesvalueInsert to ListkeyEnd of the table (rightmost). If there are multiplevalueValue, then eachvalueValues are inserted in a left-to-right order at the end of the footer: for example, an empty listmylistPerformRPUSH mylist a b c, the resulting list of results isa b c, which is equivalent to executing the commandRPUSH mylist aRPUSH mylist bRPUSH mylist c。 IfkeyDoes not exist, an empty list is created and the Rpush operation is performed.

Lpush MyList item3; inserts one or more values value into key the table header of the list

Lrange mylist 0-1; returns key the element within the specified range in the list, with an offset start and a specified interval stop .

The subscript (index) parameter start and stop both are the 0 bottom, that is, to 0 represent the first element of the list, to 1 represent the second element of the list, and so on. You can also use a negative subscript to -1 represent the last element of the list, which -2 represents the second-lowest element of the list, and so on.

Lpop mylist; Remove and return key the head element of the list

Rpop MyList;

Hash

Hset Myhash key value1;

Hset Myhash key values2;

Hget myhash key2;==> "value2";

Hgetall myhash;==> "Key1" "value1" "Key2" "value2"

Hvals myhash;==> "Values1" "value2";

Hkeys myhash;==> "Key1" "Key2"

Sets:

Sadd MySet Sky;

Sadd MySet Moon;

Sismember MySet Sky; Determines whether the sky element is a member of the collection Myst. How does return 1 not return 0;

Smembers myset;==> "Key" "Moon". Returns key all members in the collection.

Sinter MySet Myset2; intersection: Seeking the common elements of MySet and Myset2;

Sdiff MySet Myset2; differential set: Myset-myset2;

Sunion MySet Myset2; set: MySet U Myset2;

Sorted Sets:

Zadd Z1 1 Mon;

Zadd Z1 2 tur;

Zadd Z1 3 Wen;

Zscore Z1 tur==> "2"

Zcard z1==> "3

Zrange Z1 Increment sort

Zrevrange Z1 0 2==> "Wen" "Tur" "Mon"

   zrevrange key start stop [withscores], returns the member in the ordered set key , within the specified interval. The positions of the members are arranged in descending order of score value (from large to small). Members with score the same value are arranged in reverse order of the dictionary (reverse lexicographical order). scoreother aspects of the Zrevrange command are the same as the Zrange command, except that the members are ordered in descending order of value.

Pub/sub:

Puber>publish ch1 "HelloWorld" ==>2 sends information message to the number of subscribers to the specified channel channel。返回值为 receiving message the information.

Subscribe CH1

    SUBSCRIBE Channel [channel ...] Subscribe to the information for one or more channels given. The return values are as follows:

    

Redis Management:

Auth:auth password==> requirepass CONFIG SET requirepass password You can use a password to protect the Redis server by setting the value of the item in the configuration file (using the command). If password protection is turned on, after each connection to the Redis server, use the command to unlock AUTH and unlock before you can use other Redis commands. If the AUTH command is given a password that password matches the password in the configuration file, the server returns OK and starts accepting command input.

    

Ping:ping==> uses the client to send one to the Redis server PING and returns one if the server is functioning properly PONG .

SELECT [NUMBER]: switch to the database of the specified index;

Quit: Exits the current connection;

Dbsize: Statistics The number of keys in the current database;

Info memory==>info [section] gets the status and statistics of the current server.

Section includes: Server/client/memory/persistence/stats/replication/cpu/keyspace;

The Save==>save command performs a synchronous save operation that saves all the data snapshots (snapshot) of the current Redis instance to the hard disk as an RDB file, and in general, rarely performs a save operation in a production environment because it blocks all clients. The task of saving a database is typically performed asynchronously by the BGSAVE command. However, save can be used as the last resort to save data if the background child process that is responsible for saving the data unfortunately has a problem.

Bgsave==> in the background asynchronously (asynchronously) saves the current database's data to disk, returns immediately after the Bgsave command executes, OK and then Redis fork out a new subprocess, the original Redis process (parent process) The client request continues to be processed, and the child process is responsible for saving the data to disk and then exiting.

Flushdb==> clears all keys in the current database.

Flushall==> clears the data for the entire Redis server (all keys for all databases are deleted). This command never fails.

Monitor==> listens to requests received by all Redis servers, prints out the commands received by the Redis server in real-time, and tries to adjust them.

The Shutdown==>shutdown command performs the following actions:

      • Stop all Clients
      • If there is at least one save point waiting, execute the Save command
      • If the AOF option is open, update the AOF file
      • Turn off Redis server (server)

The slaveof host port==>slaveof command is used to dynamically modify the behavior of the Replication (replication) feature at the Redis runtime.

By executing a SLAVEOF host port command, you can turn the current server into a subordinate server (slave server) for the specified server.

If the current server is already a secondary server for a primary server, execution SLAVEOF host port will cause the current server to stop synchronizing with the old primary server, discard the old data set, and start synchronizing the new primary server instead.

In addition, executing a command on a subordinate server SLAVEOF NO ONE causes the secondary server to turn off replication and transition from the subordinate server back to the primary server, and the original data set that was synchronized will not be discarded.

Help==> such as: Help ASDD

     

Redis Learning Notes

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.