Redis Research (ii)-Preparation

Source: Internet
Author: User
Tags install redis redis server

I. Installing Redis

To install Redis see here: http://blog.csdn.net/wtyvhreal/article/details/40980167


Two. Start and stop Redis

Redis executable File Description:

Redis-server Redis Server

REDIS-CLI Redis command-line Client

Redis-benchmark Redis Performance Testing Tool

Redis-check-aof aof File Repair Tool

Redis-check-dump rdb File Check tool


Starting Redis has a direct start and is initiated by initializing the script two ways, respectively, for the development environment and production environment.

2.1 Direct Start

This method is recommended for use in the development environment.

Redis-server
The server uses 6379 ports by default (6379 Merz on the phone keypad, Merz is an Italian showgirl name), and the port number can be customized by--port parameters

Redis-server--port 6380


2.2 Starting Redis by initializing scripts

In a Linux system, Redis can be started with an init script that enables Redis to run automatically with the system and is recommended for use in production environments (student practice is not necessary).

We need to configure how Redis runs and persist files, where log files are stored, and so on, in the following steps:

(1) Configure initialization scripts:

In the Utils file in the Redis source directory, there is an initialization script file named Redis_init_script, which first copies the file to the/ETC/INIT.D directory, the file name Redis_ the port number, and the client connects to Redis through that port number. Then modify the value of the Redisport variable on line 6th of the script file to the same port number.

(2) Create the desired folder:

/etc/redis the configuration file that holds the Redis

/var/redis/Port number holds Redis persistent files

(3) Modify the configuration file:

Copy the configuration file to the/etc/redis directory, name it with the port number (6379.conf), and then edit some of the parameters as follows

Daemonize Yes enables Redis to run in daemon mode

Pidfile/var/run/redis_ port number. PID setting of the PID file location for Redis

Port port number sets the port number of the Redis listener

dir/var/redis/port number Setting persistent file storage location


You can now use the following command to start Redis,

/etc/init.d/redis_ Port number Start
Then you need to do the following to enable Redis to automatically start with the system

sudo update-rc.d redis_ port number Defaults

2.3 Stop Redis
When you stop Redis, you may be synchronizing the in-memory data to your hard disk, and forcing the Redis process to terminate can result in data loss. The correct way to stop is to send the shutdown command to Redis. After Redis receives the shutdown command, it disconnects all client connections, then performs persistence based on the configuration and finally completes the exit.

REDIS-CLI SHUTDOWN

Redis can handle sigterm signals, so the PID using the kill Redis process can also be a normal technical Redis, with the same effect as sending the shutdown command.


Three. Redis command-line Client

3.1 Sending commands

(1) The first way to execute the command as a REDIS-CLI parameter

Redis-cli-h 127.0.0.1-p 6379

You can customize the address and port number by using the-H and-p parameters

(2) The second way, run REDIS-CLI without parameters, will enter the interactive mode, you can freely enter the command



3.2 Command return value

1. Status reply

Display status information directly


2. Error response

Error reply starts with (error) and adds a message after it


3. Integer reply

Start with an integer and follow the whole number in the back


4. String reply

Bulk reply can get a string reply when requesting a key value


5. Multi-line string reply



Four. Redis Multi-database

Each database in Redis is a 0-based incremental number named, and Redis supports 16 databases by default, which can be modified by configuring the parameter databases. When a client connects to Redis, the No. 0 database is automatically selected, but the database can be replaced at any time using the Select command.

Redis does not support setting different access passwords for each data volume, so a client can either access all of the databases or have no access to a database. The most important point is that multiple databases are not completely isolated, for example, the Flushall command can empty data from all databases in a Redis instance.

So these databases are more like a command space, and they are not suitable for storing data from different applications.

Different applications should use different Redis instances to store data.


Because Redis is very lightweight, an empty Redis instance consumes only about 1MB of memory, so don't worry that multiple Redis instances will take up a lot of memory.

Redis Research (ii)-Preparation

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.