REDIS Data Structure Server

Source: Internet
Author: User

RDIs and jquery are purely for applications, and here is a primer on CentOS 5.7:

1.Redis Introduction

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

2.Redis of performance

Here's the official Bench-mark data:

  • The test was did with a simultaneous clients performing 100000 requests.
  • The value SET and GET is a bytes string.
  • The Linux box is running Linux 2.6, it's Xeon X3320 2.5Ghz.
  • Text executed using the loopback interface (127.0.0.1).

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

See the Official Bench-mark page (Http://code.google.com/p/redis/wiki/Benchmarks) for more detailed data.

3. Installing Redis

The Redis code follows ANSI-C and can be installed on all POSIX systems (such as Linux, *BSD, Mac OS X, Solaris, etc.). And Redis does not rely on any nonstandard libraries, and no compilation parameters are required to be added. The installation of Redis is surprisingly simple, which may also be a reason for his popularity, making it easy to get started, unlike something that can make people completely desperate.

First go to the official website to download the source:

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

Extract:

TAR–ZXVF redis-2.4.6.tar.gz

Compile

To illustrate, the installation of Redis is very simple, there is already a ready-made makefile file, run the make command directly.

Make

Make install

Redis consists of four executables:redis-benchmark,redis-cli,redis-server,redis-stat four files, plus a The redis.conf constitutes the final available package for the entire redis. Their role is as follows:

    • Redis-server:redis Server Daemon Startup program
    • Redis-cli:redis command-line operation tool. Of course, you can also use Telnet to operate on its plain text protocol.
    • Redis-benchmark:redis Performance testing tools to test the read and write performance of Redis in your system and in your configuration
    • Redis-stat:redis Status Detection Tool to detect Redis current status parameters and delay status

Redis can now be started, and Redis has only one boot parameter, which is his profile path.

Redis-server/etc/redis.conf

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

The following are the meanings of the main configuration parameters of redis.conf:

    • Daemonize: Whether to run daemon mode later
    • Pidfile:pid File Location
    • Port: Port number for listening
    • Timeout: Request time-out
    • Loglevel:log Information level
    • Logfile:log File Location
    • Databases: number of open databases
    • Save *: How often the snapshot is saved, the first * indicates how long, and the third * indicates how many times the write operation is performed. Snapshots are automatically saved when a certain number of writes are performed within a certain amount of time. You can set multiple conditions.
    • Rdbcompression: Whether to use compression
    • Dbfilename: Data Snapshot file name (only file name, excluding directory)
    • Dir: Save directory for Data snapshot (this is the directory)
    • AppendOnly: If the appendonlylog is turned on, each write will record a log, which will improve the data anti-risk ability, but affect the efficiency.
    • Appendfsync:appendonlylog How to sync to disk (three options, each write is forced to call Fsync, Fsync per second, do not call Fsync wait for the system to synchronize 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 for testing

[Email protected] ~]# REDIS-CLI
Could not connect to Redis at 127.0.0.1:6379:connection refused
Not connected> exit
[Email protected] ~]# redis-server/etc/redis.conf
[Email protected] ~]# REDIS-CLI
Redis 127.0.0.1:6379> quit

4.REDIS Data Structure

The Redis author, Antirez, once called it a data structure server (datastructures Server), which is a very accurate statement that all of Redis's functions are to store data in several of its inherent structures, and provide the interface to the user to manipulate these kinds of structures. We can imagine those 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, you can understand it 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 versatile.
    • List is a linked list structure, the main function is push, pop, get all the values of a range and so on. Key in operation is understood as the name of the linked list.
    • set is a set, and we are similar to the concept of the set in mathematics, the operation of the set has added delete elements, there are multiple sets of orthogonal and poor operation. In Operation Key is understood as the name of the collection.
    • Zset is an upgraded version of set, and he adds a sequential attribute on the set, which can be specified when adding a modified element, and Zset automatically re-adjusts the order of the new values after each assignment. It can be understood that there are two columns of MySQL table, one column of value, and one in the order of storage. Key in operation is understood as the name of Zset.
    • The hash data type allows users to use Redis to store object types, and one important advantage of the hash data type is that when you store data objects with very few key values, the memory consumption of the data store is small. For more information on Hash data types, see:/http Code.google.com/p/redis/wiki/hashes

A list of all supported interfaces is given on the official website, accompanied by a detailed description of the following, 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 memory storage, disk storage, and log files, which are configured with three parameters in the configuration file.

Save seconds Updates,save Configuration, indicates how many times the update operation has been synchronized to the data file. This can be a combination of multiple conditions, such as the default configuration file settings, set three conditions.

appendonly Yes/no ,appendonly configuration, indicates whether logging occurs after each update operation and, if not turned on, may result in data loss over a period of time when power is lost. Because the Redis itself synchronizes data files in sync with the save conditions above, some data will only exist in memory for a period of time.

Appendfsync no/always/everysec ,appendfsync configuration,no indicates that the data cache of the operating system is synchronized to disk, always means to manually call Fsync() to write data to disk after each update operation,everysec to synchronize once per second.

6.redis master-slave configuration

Redis supports Master-slave 's master-slave configuration by specifying the slaveof parameter as the host's IP and port in the slave's configuration file

7.redis Start (link finishing)

Project homepage, below is a list of various language support:

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

The author gives a very good example in the wiki so that we can get started quickly, address:

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

At the same time the author recommends another tutorial, address:

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

A Redis enthusiast-created related issues discussion site:

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

REDIS Data Structure Server

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.