Common Redis commands and master-slave Database Configuration

Source: Internet
Author: User
Tags echo name redis cluster install redis redis server

Common Redis commands and master-slave Database Configuration

Redis provides a variety of commands to operate databases and various data types.

(1) keys

Returns all key values that meet the specified pattern. For example, to return all keys, use: keys *

(2) exists

Check whether a key exists.

(3) del

Delete a key. Example: del name

(4) expire

Set the expiration time of a key. For example, expire age 10 expires after 10 s.

(5) ttl

Check the expiration time. For example, ttl age, returns-1 after expiration.

(6) move

Transfers keys in the current database to other databases. Before that, of course, we need to select the database and use the select statement.

For example, select 0 indicates that the database is 0. In Redis, there are a total of 16 databases, which are 0 ~ 15. Generally, enter the data

The default database number is 0. If you want to enter the specified database, you can use the select statement. select 1 indicates entering the database numbered 1.

Now, if we want to move the age in database 0 to database 1, move age 1 directly.

(7) persist

Removes the expiration time of a given key. Example: persist age

(8) randomkey

Returns a random key from the database. Example: randomkey

(9) rename

Rename the key. For example, rename age age1 indicates renaming age to age1.

(10) type

Type of the Return key value. For example, type age

(11) echo

Print some content. For example, if echo name is used, "name" is output ".

(12) quit

Exit the connection.

(13) dbsize

Returns the number of all keys in the current database.

(14) info

Obtain server information and statistics.

(15) config get

The request received by the real-time storage. Example: config get dir

(16) flushdb

Delete all keys in the current database.

(17) flushall

Clear all keys in all databases.

Advanced applications of apsaradb for Redis

(1) set a password for the Redis Database

You only need to add your own password after requirepass in the redis configuration file. Specify the configuration again at startup

File. After entering the client, we find that all operations can be entered, but all operations are rejected. Therefore, we need to authorize them and use the auth statement to keep up

Password. You can also enter the password when logging on to the client, for example, redis-cli-a 88888888.

(2) redis master-slave Replication

Features of redis master-slave replication:

1. One master can have multiple slave instances

2. Multiple Server Load balancer instances can be connected to the same master or other Server Load balancer instances.

3. master-slave replication does not block the master. During data synchronization, the master can continue to process client requests.

4. Improve system scalability

Redis master-slave replication process:

1. establish a connection between the slave and the master and send the sync synchronization command.

2. The master starts a background process, saves database snapshots to files, and the master process starts to collect new write commands.

And cache.

3. After saving the file in the background, send the file to slave.

4. Save the file to the hard disk.

Configure the Master/Slave Server:

It is easy to configure the slave server. You only need to add the following configurations to the slave configuration file:

Slaveof 222.27.174.98 6379 // specify the IP address and port number of the master host.

Masterauth 888888 // host Database Password

We can run the info command to check whether the local redis server is the master server or slave server.

Install and test Redis in Ubuntu 14.04

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

Redis details: click here
Redis: click here

This article permanently updates the link address:

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.