Redis Development-1. Meet Redis

Source: Internet
Author: User
Tags install redis redis server

1. What is Redis?

Redis is a very fast non-relational database, stores a mapping of keys to five different types of values.

(Redis is a very fast, non-relational database, a nosql one that stores data in the form of key-value pairs, with 5 types of values.) )

Redis is an abbreviation for Remote Dictionary server (a long-range dictionary server).

Redis supports in-memory persistent storage on disk, replication to scale read performance, and Client-side sharding to SC Ale Write performance.

(Redis supports memory persistence to disk, extending read performance in the form of replication to extend write performance in a client-fragmented (client-side sharding) manner.) )

Sharding is a method by which you partition your data into different pieces.

Partition your data based on IDs embedded in the keys, based on the hash of keys, or some combination of The other.

Through partitioning your data, you can store and fetch the data from multiple machines, which can allow a linear scaling In performance for certain problem domains.

(fragmentation is a technique that divides your data into different parts.)

In this way, each data fragment will have an ID as its key, based on the hash code, so that you can store your data on different machines and then scale the performance linearly. )

2. Data types supported by Redis

Strings (String)

Listing (list)

Collection (SET)

Hash (hash)

Ordered set (Zset)

3. Storage format

All data in the Redis database is stored in memory.

Advantage: Because memory reads and writes much faster than the hard disk, Redis has a significant performance advantage over other hard disk-based databases.

eg

Redis can read and write 100,000 + key values per second on a normal PC.

Disadvantage: Because the data is stored in memory, the data in memory is lost after the program exits.

To compensate for this shortcoming, Redis provides persistent functionality for writing in-memory data asynchronously to the hard disk.

Because it is asynchronous, it does not affect its continued provision of other services.

4. Application Scenarios

In many cases, Redis is applied to caches , queue Systems , and so on.

When applied to a cached scene, Redis sets the time-to-live for each key value (Ttl-time to live), which is the key value after the time-to-live expires

will be deleted automatically.

5. Installing Redis

Redis compatible with most POSIX systems (Linux, OS X, BSD)

:

http://download.redis.io/

1) installation under Linux

Download the installation package first

Tar xzf redis-stable.tar.gz

CD redis-stable

Make (source code is compiled first)

Make test (test source code is compiled successfully)

Make Install (installer)

The actual setup procedure is to copy the executable program to the/usr/local/bin directory so that you do not have to enter the full path at a later time to execute the program.

2) OS x under Installation

Under OS x through the package management tool Homevrew.

A. Installing the Homebrew

Enter Terminal:

Ruby-e "$ (curl-fsskl raw.github.com/mxcl/homebrew/go)"

B. installing Redis via Homebrew

Brew Install Redis

C. Configure LAUNCHD to let the Redis-year-old system run automatically

Under Terminal, enter the following command:

Ln-sfv/usr/local/opt/redis/*.plist ~/library/launchagents

Launchctl Load ~/library/launchagents/homebrew.mxcl.redis.plist

6. Start Redis

1) Direct Start

$ redis-server

Redis Server uses 6379 port by default after startup

You can also customize the boot port as follows:

$ redis-server--port 8918

2) Start Redis with init script

In a production environment, we recommend this method of starting Redis (for stability)

A. First, enter the Utils directory of the Redis source directory

B. Find the init script file called Redis_init_script

C. Copy the initialization script to the/ETC/INIT.D directory and rename it to the Redis_ port number

This port number indicates the port number that Redis will listen on

D. Modify the value of the Redisport variable in the script to the port number you set

E. Creating the required folders

/etc/redis here to store Redis configuration files

/var/redis/Port number This is where the Redis persistence file is stored

F. Modifying a configuration file

Download the file template online and copy it to the/etc/redis directory

Name the file as the port number. conf

Then configure some of the parameters in the configuration file according to the following information

Daemonize Yes enables Redis to run in daemon mode

Pidfile/var/run/redis_ port number. PID this is 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

G. Use the following command to start Redis

/etc/init.d/redis_ Port number Start

H. Enable Redis to start automatically with the system

$ sudo update-rc.d redis_ port number Defaults

7. Stop Redis

$ redis-cli Shutdown

Redis Development-1. Meet Redis

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.