What Redis is:
Redis is a open source, BSD licensed, Advanced Key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. (Official website Introduction instructions)
Redis is an open source, BSD licensed, Advanced Key-value storage System.
can be used to store strings, hash structures, linked lists, and collections, so it is commonly used to provide data structure services.
Basic knowledge
1. Redis Data type:
String, list (lists), collection (sets), ordered collection (sorts sets), hash table (HASHS)
2. Unique features compared to Redis and memcache:
(1) Redis can be used for storage (storge), while Memcache is for caching (cache). This feature is mainly due to its "persistent" function
(2) The stored data has "structure", for memcache, stored data, only one type-"string", while Redis can store strings, linked lists, sets, ordered sets, order structure
3. Two ways to persist:
Redis stores data in memory or is configured to use virtual memory.
Two ways to achieve data persistence: (1) the way in which in-memory data is continuously written to disk (high performance, but may cause a certain amount of data loss)
(2) Log every update using MySQL-like method
4. Redis Master-Slave synchronization: Very useful for improving read performance
5. The default port on the Redis server is 6379
--------------------------------------------------------------------------------------------------------------- -
Next, we'll install Redis.
1, first to the Redis official website (redis.io) Download the latest version or the latest stable version
2, download it to my/lamp directory (here/lamp is the source directory, can be arbitrarily specified, such as:/USR/LOCAL/SRC)
3. Unzip and enter the directory
4. Compiling the source program
A. Make
"Make a few questions before you take 1. Direct make without configure---Reason: The source code is the official configure, 2. If it is a 32-bit machine with make 32bit command; 3. Official configure, the generated file has timestamp information, make can only occur after configure, if your virtual machine time is wrong, for example, 2012, solve: Date-s ' yyyy-mm-dd hh:mm:ss ' rewrite time, then clock- W
B. Optional step: Make Test compile
(May appear: Need Tcl >8.4 This situation, yum install TCL)
C. cd src
D. Make install Prefix=/usr/local/redis
5. Move the configuration file (under the source root directory) to the Redis installation directory/usr/local/redis/etc (if the ETC directory does not exist, create this directory in advance)
6. Start Redis Service:/usr/local/redis/bin/redis-server/usr/local/redis/etc/redis.conf
7, by default, Redis is not running in the background, we need to put Redis in the background to run
Vim/usr/local/redis/etc/redis.conf
Change the value of daemonize to Yes
8, the Client connection (REDIS-CLI after the addition of parameters, the default connection to local)
/usr/local/redis/bin/redis-cli
9. Stop Redis Instances
/USR/LOCAL/REDIS/BIN/REDIS-CLI shutdown
Or
Pkill Redis-server
10. Let Redis boot from the start
Vim/etc/rc.local
Join
/usr/local/redis/bin/redis-server/usr/local/redis/etc/redis-conf
-------------------------------------to this step, the installation and startup of Redis has been completed-------------------------------
11, next we look at the/usr/local/redis/bin directory of several files when what
Redis-benchmark:redis Performance Testing Tools
Redis-check-aof: Tools to check AOF logs
Redis-check-dump: Tools to check RDB logs
REDIS-CLI: Client for connection
Redis-server:redis Service Process
--------------------------------------------------------------------------------------------------------------- -------
Configuration of Redis
Daemonize: If you need to run in the background, change the value of the item to Yes
Pdifile: Put PID file in/var/run/redis.pid, can be configured to other address
Bind: Specifies that Redis receives only requests from that IP, and if not set, all requests are processed and it is best to set the item in the production process
Port: Listening ports, default is 6379
Timeout: Time-out when setting client connections in seconds
LogLevel: Grades are divided into 4 levels, debug,revbose,notice and warning. General open notice under production environment
LogFile: Configure the log file address, which is printed on the port of the command line terminal by default using standard output
Database: Set the number of databases, the default database used is 0
Save: Set the frequency of Redis for database mirroring
Rdbcompression: Whether to compress during a mirrored backup
Dbfilename: File name for mirrored backup files
Dir: path to file placement for database mirroring backups
Slaveof: Set the database to be a slave database for other databases
Masterauth: When the primary database connection requires password authentication, set it here
Requirepass: Set the password to be used before any other specified client connection is made
MaxClients: Limit the number of simultaneous clients
MaxMemory: Set the maximum memory that Redis can use
AppendOnly: When AppendOnly mode is turned on, Redis appends each received write to the appendonly.aof file, and when Redis restarts, the previous state is recovered from the file
Appendfsync: How often to set the appendonly.aof file for synchronization
Vm_enabled: Whether to turn on virtual memory support
Vm_swap_file: Set the path of the swap file for virtual memory
Vm_max_momery: Set the maximum amount of physical memory that Redis will use when virtual memory is turned on, default is 0
Vm_page_size: Setting the size of virtual memory pages
Vm_pages: Set the total page number of the swap file
Vm_max_thrrads: Set the number of simultaneous threads used by VM IO
--------------------------------------------------------------------------------------------------------------- ----------
The difference between Redis and memcached (summary)
1. Redis and memcache all store data in memory, which is the memory database. But memcache can also be used to cache other things, such as films, videos and so on;
2, Redis not only supports simple k/v type data, but also provides storage of data structures such as List,set,hash;
3, virtual memory--redis when the physical memory is exhausted, you can swap some long-useless value to disk;
4. Expiration policy--memcache is specified when set, such as set Key1 0 0 8, which never expires. Redis can be set by example expire, for example expire name 10;
5, distributed-set memcache cluster, using Magent to do a master more from; Redis can do a master multi-slave. Can be one master one from;
6, storage data security--memcache hang up, the data is gone; Redis can be saved to disk (persistent) on a regular basis;
7, after the disaster recovery--memcache hangs, the data cannot restore; Redis data can be recovered by aof after loss;
8, Redis support data backup, that is, Master-slave mode of data backup;
9, the application scenario is different: Redis out as a NoSQL database use, but also used for Message Queuing, data stack and data cache; memcached is suitable for caching SQL statements, datasets, temporary user data, deferred query data, and session.
Installing Redis under Linux