Tags: http ar io os using for on file data
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:
To illustrate, the installation of Redis is very simple, there is already a ready-made makefile file, run the make command directly.
Redis consists of four executables: Redis-benchmark, Redis-cli, Redis-server, redis-stat four files, plus a redis.conf that forms 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.
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 (data Structures 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 interfaces to the user to manipulate these 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:
In addition, the author also provides a very intimate Web command line simulation page for beginners to try Redis, address:
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.
The Save seconds Updates,save configuration, indicating how many times the update operation is 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 operating system data cache synchronization to disk, always indicates that each update operation after the manual call Fsync () write data to disk, The everysec indicates synchronization 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