PHP database operation 3: redis Usage Analysis, php database redis usage
This article describes how to operate redis in a PHP database. We will share this with you for your reference. The details are as follows:
Although memcache is easy to use, it solves the IO problem when the database encounters high concurrency, but there are still many issues to be resolved:
One: The principle of Redis master-slave replication, steps. First step: Copy initialization---> after booting from Redis, the Sync command is sent to the primary redis based on configuration. After version 2.8, the Psync command is sent. After---> Master redis receives the Sync command, it begins to save the snapshot
databasesRandomKeyReturns a random key of the key space.$ Key = $ redis-> randomKey ();SelectSelect a databaseMoveTransfer a key to another database$ Redis-> select (0); // switch to DB 0$ Redis-> set ('X', '42'); // write 42 to x$ Redis-> move ('X', 1); // move to DB 1$ Redis
$ Redis-> auth ('foobared ');
BgrewriteaofUse aof for database persistence$ Redis-> bgrewriteaof ();
SlaveofSelect slave server$ Redis-> slaveof ('10. 0.1.7 ', 6379 );
SaveSave data to disk synchronously
BgsaveAsynchronously save data to a disk
LastsaveReturns the Unix timestamp when data is successfully saved to the d
free,auto-sharding and so on. For example, some common document databases are supported Schema-free, directly store JSON format data, and support auto-sharding functions such as MongoDB.
In the face of these different types of nosql products, we need to choose the most suitable products according to our business scenarios.
Redis is most suitable for all data in-momory scenarios, although Redis also provi
set the log to output to standard output in daemon case, the log will be written to/dev/null.LogFile ""If you want the log to print to the syslog, it is also easy to control by syslog-enabled. In addition, Syslog-ident allows you to specify log flags in the syslog, such as:Syslog-ident RedisIt also supports specifying a syslog device with a value of either user or LOCAL0-LOCAL7. Specifically, you can refer to the usage of the Syslog service itself.Syslog-facility local0For
$redis->set (' x ', ' 42 '); Write to X$redis->move (' x ', 1); Move to DB 1$redis->select (1); Switch to DB 1$redis->get (' x '); would return 42Rename, RenamekeyRename Key$redis->set (' x ', ' 42 ');$redis->rename (' x ', ' Y ')
$redis->get (' x '); would return 42
Rename, Renamekey
Rename Key
$redis->set (' x ', ' a '), $redis->rename (' x ', ' y '), $redis->get (' y '); →42$redis->get (' x '); → ' FALSE '
Renamenx
Similar to Remane, however, if the renamed name already exists, it will not replace
= "127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381,127.0.0.1:26382"/>#集群配置没验证 follow-up documentation will do this.[Note]: The session persistence setting is turned on by default from Tomcat6, the local session persistence can be turned off during the test, and in the Context.xml file under Tomcat's Conf directory, uncomment the following configuration:-Redis Exc
(1); Switch to DB 1$redis->get (' x '); would return 42Rename, RenamekeyRename Key$redis->set (' x ', ' 42 ');$redis->rename (' x ', ' Y ');$redis->get (' y '); →42$redis->get (' x '); → ' FALSE 'RenamenxSimilar to Remane, however, if the renamed name already exists, it wil
(1); Switch to DB 1$redis->get (' x '); would return 42Rename, RenamekeyRename Key$redis->set (' x ', ' 42 ');$redis->rename (' x ', ' Y ');$redis->get (' y '); →42$redis->get (' x '); → ' FALSE 'RenamenxSimilar to Remane, however, if the renamed name already exists, it wil
to DB 1$redis->select (1); Switch to DB 1$redis->get (' x '); would return 42Rename, RenamekeyRename Key$redis->set (' x ', ' 42 ');$redis->rename (' x ', ' Y ');$redis->get (' y '); →42$redis->get (' x '); → ' FALSE 'RenamenxSim
databasesRandomKeyReturns a random key of the key space.$ Key = $ redis-> randomKey ();SelectSelect a databaseMoveTransfer a key to another database$ Redis-> select (0); // switch to DB 0$ Redis-> set ('X', '42'); // write 42 to x$ Redis-> move ('X', 1); // move to DB 1$ Redis
Install redis and redis clusters in CentOSRedis Introduction
Redis is an open-source Log Type written in ANSIC language that supports Network, memory-based, and persistence,A high-performance Key-Value database that provides APIs in multiple languages.
Installation Steps1. Install gcc.yum install gcc-c++2. Download
′, ' field2′));Returns the value of the field1,field2 in a hash named HRedis Operations RelatedFlushdbEmpty the current databaseFlushallEmpty all databasesRandomkeyA key that returns the key space at random$key = $redis-gt;randomkey ();SelectSelect a databaseMoveTransfer a key to another database$redis-gt;select (0); Switch to DB 0$redis-gt;set (' x ', ' 42′ ');
(); SelectSelect a databaseMoveTransfer a key to another database$redis->select (0); Switch to DB 0$redis->set (' x ', ' 42 '); Write to X$redis->move (' x ', 1); Move to DB 1$redis->select (1); Switch to DB 1$redis->get (' x '); would return 42 Rename, RenamekeyRename Key$
$redis->set (' x ', ' 42 '); Write to X$redis->move (' x ', 1); Move to DB 1$redis->select (1); Switch to DB 1$redis->get (' x '); would return 42 Rename, RenamekeyRename Key$redis->set (' x ', ' 42 ');$redis->rename (' x ', ' Y '
another database$redis->select (0); Switch to DB 0$redis->set (' x ', ' 42 '); Write to X$redis->move (' x ', 1); Move to DB 1$redis->select (1); Switch to DB 1$redis->get (' x '); would return 42 Rename, RenamekeyRename Key$redis
); Switch to DB 0$redis->set (' x ', ' 42 '); Write to X$redis->move (' x ', 1); Move to DB 1$redis->select (1); Switch to DB 1$redis->get (' x '); would return 42Rename, RenamekeyRename Key$redis->set (' x ', ' 42 ');$redis->rena
snapshot.
2). Master AoF Persistence, if you do not rewrite the aof file, the performance impact of this persistence is minimal, but the aof file will continue to grow, aof file over the General Assembly to affect the recovery speed of master restart. Master should not do any persistent work, including memory snapshots and aof log files, especially do not enable memory snapshots for persistent
If the data
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.