RDIs Basic Knowledge

Source: Internet
Author: User
Tags benchmark memcached install redis redis server



Official English site

http://www.redis.io/


Chinese official site

http://redis.cn/



RDIs, like jquery, is purely for application, and here is a record of getting started on CentOS 5.7: 1.Redis Introduction

Redis is a key-value storage system. Similar to memcached, it solves the situation where data is completely lost after a power outage, and she supports more untyped value types, and supports lists (list), sets (set), and Zsets (ordered sets) of data types, in addition to string. These data types support Push/pop, Add/remove and intersection-set and differential sets and richer operations, and these operations are atomic. 2.Redis of Performance

Here is the official Bench-mark data: The test was done with a simultaneous clients performing 100000 requests. The value SET and get is a 256 bytes string. The Linux box is running Linux 2.6, it ' s Xeon X3320 2.5Ghz. The Text executed using the loopback interface (127.0.0.1).

Results: About 110000 SETs per second, about 81000 GETs per second.

For more detailed data, see Official Bench-mark page (Http://code.google.com/p/redis/wiki/Benchmarks) 3. Install Redis

Redis code is written in Ansi-c and can be installed on all POSIX systems (such as Linux, *bsd, Mac OS X, Solaris, and so on). Also, Redis does not rely on any non-standard libraries, and no compilation parameters are required to add. The installation of Redis is surprisingly simple, which may be a reason for his popularity, it is easy to get started, unlike some things, the compilation phase can make people completely hopeless.

First go to the official website download source code:

wget http://redis.googlecode.com/files/redis-2.4.6.tar.gz

Extract:

TAR–ZXVF redis-2.4.6.tar.gz

Compile

What needs to be explained, the Redis installation is very simple, already has the ready-made makefile file, runs directly the Make command.

Make

Make install

The Redis is composed of four executables:redis-benchmark,redis-cli,redis-server,redis-stat , and the four files, plus a The redis.conf constitutes the final available package for the entire redis. They function as follows: The Redis-server:redis server's daemon launcher redis-cli:redis the command-line operation tool. Of course, you can also use Telnet to operate the Redis-benchmark:redis Performance test tool based on its plain text protocol, and test the read-write Performance Redis-stat:redis State Detection Tool Redis your system and your configuration. Can detect Redis current state parameters and latency conditions

Now you can start Redis, Redis has only one startup parameter, and that's his profile path.

Redis-server/etc/redis.conf

Note that the default copy of the past redis.conf file daemonize parameter is no, so Redis does not run in the background, then to test, we need to reopen a terminal. Modify to Yes to run Redis for the background. In addition, the configuration file specified the PID file, log files and data file address, if necessary to modify first, the default log information directed to stdout.

The following is the meaning of the main configuration parameters of redis.conf: daemonize: Whether to run the Pidfile:pid file location in daemon mode port: Listener port Number timeout: Request Timeout Loglevel:log information level Logfile:log file Location Databases: Open the number of databases save * *: How often the snapshot is saved, the first * represents how long, and the third * indicates how many writes are performed. Automatically saves snapshots when a certain number of writes are performed within a certain amount of time. Multiple conditions can be set. Rdbcompression: Whether to use compressed dbfilename: Data Snapshot file name (just filename, excluding directory) dir: Save directory for Data snapshots (this is directory) appendonly: Open Appendonlylog, When opened, a log will be recorded for each write operation, which will increase the risk-resistant capability of the data, but affect efficiency. Appendfsync:appendonlylog How to sync to disk (three options, each write is forced to call Fsync, enable once per second Fsync, do not call Fsync wait for the system to sync itself)

At this point you can open a terminal for testing, the default listening port in the configuration file is 6379

We can open a Redis client to test

[Root@snda-192-168-1-114 ~]# Redis-cli
Could not connect to Redis at 127.0.0.1:6379:connection refused
Not connected> exit
[Root@snda-192-168-1-114 ~]# redis-server/etc/redis.conf
[Root@snda-192-168-1-114 ~]# Redis-cli
Redis 127.0.0.1:6379> quit 4.REDIS data structure

Redis's author Antirez once called it a data structure server (data Structuresserver), which is a very accurate representation of the fact that all the functions of redis are to preserve the data in its inherent structure, and provides the interface for users to operate these structures. We can imagine the intrinsic data types and their operations in various languages.

Redis currently offers four types of data:string,list,set , and zset(sorted set) and Hash. string is the simplest type, one that you can understand as a type with memcached, a key corresponds to a value, and the operation supported on it is similar to the operation of Memcached. But it's more functional. list is a list structure, the main function is push, pop, get a range of all the values, and so on. The key in the operation is understood as the name of the list. set is a set, which is similar to the concept of set in our mathematics, which has the added deletion element to the operation of the set, and the orthogonal and poor operation of multiple sets. The key in the operation is understood as the name of the collection. Zset is an upgraded version of Set, which adds a sequential attribute to the set, which can be specified when modifying elements are added, and Zset automatically adjusts the order of the new values each time it is specified. You can understand that there are two columns of MySQL table, a list of stored value, a list of stored order. The key in the operation is understood as Zset's name. The hash data type allows users to store object types with Redis, and an important advantage of hash data types is that when you store only a few key values for a data object, the memory consumption of the data store is minimal. For more information on the Hash data type, see: http ://code.google.com/p/redis/wiki/hashes

A list of all supported interfaces is given on the official web site, with a detailed introduction to the deputy, address:

Http://code.google.com/p/redis/wiki/CommandReference

In addition, the author also provides a very intimate Web command line simulation page for beginners to try Redis, address:

http://try.redis-db.com/ 5.redis Data storage

The Redis storage is divided into three parts: memory storage, disk storage and log files, and three parameters are configured in the configuration file.

The save seconds Updates,save Configuration, indicates how many update operations have been done over a long period of time, synchronizing the data to the data file. This can be a combination of conditions, such as the default configuration file settings, set three conditions.

appendonly Yes/no ,appendonly configuration that indicates whether logging is performed after each update operation and, if not, may result in loss of data over time during a power outage. Because the Redis itself synchronizes data files according to the save condition above, some data will only exist in memory for a period of time.

Appendfsync No/always/everysec ,appendfsync configuration,no Indicates that the operating system synchronizes the data cache to disk, andalways indicates that fsync() is manually invoked after each update operation to write the data to disk,Everysec is synchronized once per second. 6.redis master-slave configuration

Redis support master-slave master-slave configuration, the configuration method is in the configuration file from the machine specified slaveof parameters for the host IP and port can 7.redis start (link collation)

Project home page, below is a variety of language support list:

http://code.google.com/p/redis/

The author gives a very good example in the wiki to enable us to get started quickly, address:

Http://code.google.com/p/redis/wiki/TwitterAlikeExample

The author also recommends another tutorial, address:

Http://labs.alcacoop.it/doku.php?id=articles:redis_land

A Redis enthusiasts create related issues discussion website:

http://www.rediscookbook.org/

Why use Redis and its product positioning

Http://www.infoq.com/cn/articles/tq-why-choose-redis

Redis memory usage optimization and storage

Http://www.infoq.com/cn/articles/tq-redis-memory-usage-optimization-storage

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.