1. Nosql&redis Introduction
Nosql,not only SQL, a non-relational database. Traditional relational database can not meet the application of ultra-large scale and high concurrency.
is stored in the form of key-value (for example, json,xml) and does not necessarily follow some of the basic requirements of traditional databases, such as SQL standard, ACID properties (atomicity/consistency/isolation/durability), Table structure and so on. The main features are: non-relational, step-by, open-source, horizontally extensible (refers to the ability to connect multiple hardware and software features).
NoSQL Application Scenarios:
1), high performance-highly concurrent read and write to data
2), Huge storage-efficient storage and access to massive amounts of data
3), HI scalability && highavailability-high scalability and high availability for data
Open source NoSQL database: Redis, MongoDB, Cassandra ...
Introduction to Redis
Redis is a key-value storage System. It supports stored value types such as:string(String),list(linked list), set(unordered collection), zset(sorted set ordered set), and hash , you can also think of Redis as a data structure server. These data types support pust/pop,add/remove , and intersection, set, and difference operations, and Redis supports sorting in a variety of different ways. The data is cached in memory , it can also periodically write the updated data to disk or write the modified operation to the appended record file , and implement the Master-slave (Master-slave) Synchronous.
The API languages provided by Redis include C, C + +, C #, Java, JavaScript, Lua, Objective-c, Perl, PHP, Python, Ruby, Go, Tcl, and more.
Using Redis: Sina Weibo, 200+ Server, Port 4G, data.
How to use: Same as Memcache
1. Application direct access to the Redis database;
2. Application direct access to Redis, only access to MySQL if access to Redis fails
Application:
1. Take the latest N data operation
2. Leaderboard Application
3. Applications that need to set the expiration time accurately
4. Counter Application
5. Uniq operation, get all data weight values for a certain period of time
6. Real-time system, anti-spam system
7. Pub/sub building a real-time messaging system
8. Build a queue system
9. Caching
10. Store Weibo attention relationship
Redis has a library without tables, no fields, no columns. MongoDB has a library with a collection (corresponding to the table in MySQL)
2. Installation of Redis
Official website: Http://redis.io
Step One:
To download the installation package:
wget http://redis.googlecode.com/files/redis-2.4.17.tar.gz
Step Two:
Compiling the source code:
TARZXVF redis-2.4.17.tar.gz
cdredis-2.4.17
Make
Cdsrc
Makeinstall
Note: When make is complete, there is an executable file generated
Redis-server:redis Server Start-up program
The Redis-cli:redis command-line tool can also be used for client
Redis-benchmark:redis Performance test Tool (read/write)
Redis-stat:redis Status Detection Tool (status parameter delay)
Step three: (not required)
Move files for easy management
Mkdir–p/usr/local/redis/bin
Mkdir–p/usr/local/redis/etc
MV Redis-2.4.17/redis.conf/usr/local/redis/etc
mvmkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server/usr/lcoal/redis/bin
Step Four:
Start Redis Service
/usr/local/redis/bin/redis-server (with warning, no configuration file loaded)
/usr/local/redis/bin/redis-server/usr/local/redis/etc/redis.conf
The default connection port on the Redis server is 6379
Redis is not running in the background by default
Step Five:
Client connections
/usr/local/redis/bin/redis-cli
or other clients: such as Phpredis
[PHP]View Plaincopy print?
- $redis = new Redis ();
- $redis->connect ("127.0.0.1", 6379);
Step Six:
Stop Redis
/usr/local/redis/bin/redis-clishutdown
Or
Pkill Redis-server
3. Configuration of Redis
Daemonize If you need to run in the background, change the item to Yes
Pidfile Configure multiple PID addresses, default in/var/run/redis.pid
Bind bind IP, set only to accept requests from that IP
Port Listener, default = 6379
Timeout setting time-out for client connections in seconds
LogLevel is divided into 4 levels, debug, verbose, notice, warning
LogFile Configuring the log file address
Databases set the number of databases, the default database used is 0
Save sets the frequency with which Redis performs database mirroring, how often a snapshot is saved, how long the first * represents, 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 compress during a mirrored backup
Dbfilename file name for image backup
Dir file placement path for database mirroring backup
Slaveof setting the database to a different database from the database
Masterauth password verification required for primary database connection
Requirepass setting the password to use when logging in
MaxClients limit the number of simultaneous customers
MaxMemory set the maximum memory that Redis can use
AppendOnly Open Append Only mode
Appendfsync Setting the frequency of synchronization for appendonly.aof files
vm-enabled whether virtual memory is supported
Vm-swap-file setting the swap file path for virtual memory
Vm-max-memory Setting the maximum physical memory size used by Redis
Vm-page-size setting the page size for virtual memory
Vm-pages set the total page number of the swap file
Vm-max-threads setting the number of simultaneous threads used by Vmio
GLUEOUTPUTBUF Store small output caches together
Hash-max-zipmap-entries setting the critical value of a hash
Activerehashing re-hash
Redis Build and install