Php and redis application experience

Source: Internet
Author: User
Tags redis download
Php and redis user experience sharing 1. Installation 1. redis download and installation: reference mkdir/usr/local/rediscd/usr/local/rediswgethttp: // redis.googlecode.com/files/redis-2.4.2.tar.gztarxzfredis-2.4 sharing of php and redis experiences
I. Installation
1. download and install redis:
Reference
Mkdir/usr/local/redis
Cd/usr/local/redis
Wget http://redis.googlecode.com/files/redis-2.4.2.tar.gz
Tar xzf redis-2.4.2.tar.gz
Cd redis-2.4.2
Make
./Src/redis-server

2. redis test command:
src/redis-cliredis> set foo barOKredis> get foo“bar”;

3. configure redis as follows:
Reference
Daemonize yes
Pidfile/usr/local/redis/var/redis. pid
Port 6379
Timeout 300
Loglevel verbose
Logfile/usr/local/redis/var/redis. log
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression yes
Dbfilename dump. rdb
Dir/usr/local/redis/var
Slave-serve-stale-data yes
Appendonly no
Appendfsync everysec
No-appendfsync-on-rewrite no
Vm-enabled no
Vm-swap-file/tmp/redis. swap
Vm-max-memory 0
Vm-page-size 32
Vm-pages 134217728
Vm-max-threads 4
Hhash-max-zipmap-entries 512
Hash-max-zipmap-value 64
List-max-ziplist-entries 512
List-max-ziplist-value 64
Set-max-intset-entries 512
Activerehashing yes

4. Redis Chinese configuration document:
Reference
1. whether to run the subsequent processes. the default value is no. set it to yes in the production environment and set it to auto start.
Daemonize no
2. if a later process runs, you must specify a pid. the default value is/var/run/redis. pid.
Pidfile/var/run/redis. pid
3. listening port. the default value is 6379.
Port 6379
4. bind the host IP address. the default value is 127.0.0.1 (note). in the production environment, it is generally an intranet/Internet IP address.
Bind 127.0.0.1
5. timeout. the default value is 300 seconds)
Timeout 300
6. log record level, with four optional values: debug, verbose (default), notice, and warning
Loglevel verbose
7. log recording method. the default value is stdout.
Logfile stdout
8. number of available databases. the default value is 16. the default value is 0.
Databases 16
9. indicates the time in which the data is synchronized to the data file after the number of update operations. This can be used with multiple conditions. for example, three conditions are set in the default configuration file.
At least one key is changed within 900 seconds (15 minutes ).
Save 900 1
At least 10 keys are changed in 300 seconds (5 minutes ).
Save 300 10
10. Whether to compress the data stored in the local database. the default value is yes.
Rdbcompression yes
11. name of the local database file. the default value is dump. rdb.
Dbfilename/root/redis_db/dump. rdb
12. local database storage path. the default value is ./
Dir/root/redis_db/
13. when the local machine is a slave service, set the IP address and port of the master service (note)
Slaveof
14. when the local machine is a slave service, set the connection password of the master service (Comment)
Masterauth
15. connection password (note)
Requirepass foobared
16. maximum number of client connections. no limit by default (note)
Maxclients 128
17. after setting the maximum memory to reach the maximum memory setting, Redis will first try to clear expired or expiring keys. after this method is processed, any of them will reach the maximum memory setting, no more write operations can be performed. (Note)
Maxmemory
18. whether to record the log after each update operation. if it is not enabled, data may be lost for a period of time during power failure. Because redis synchronizes data files according to the save conditions above, some data will only exist in the memory for a period of time. The default value is no.
Appendonly yes
19. update the log file name. The default value is appendonly. aof (comment)
Appendfilename/root/redis_db/appendonly. aof
20. Update Log conditions. There are three optional values. "No" indicates that data is cached and synchronized to the disk by the operating system. "always" indicates that data is manually written to the disk by calling fsync () after each update operation. "everysec" indicates that data is synchronized once per second (default ).
Appendfsync everysec
21. whether to use virtual memory. the default value is no.
Vm-enabled yes
22. Virtual memory file path. the default value is/tmp/redis. swap. it cannot be shared by multiple Redis instances.
Vm-swap-file/tmp/redis. swap
23. store all data greater than vm-max-memory to the virtual memory, no matter how small the vm-max-memory settings are, all Index data is stored in memory (Redis index data is keys). That is to say, when vm-max-memory is set to 0, all values are actually stored on the disk. The default value is 0.
Vm-max-memory 0
24. Virtual memory files are stored in blocks, each with 32 bytes
Vm-page-size 32
25. maximum number of virtual internal files
Vm-pages 134217728
26. you can set the number of threads used to access the swap file. it is recommended that the number of server cores not exceed the value. if it is set to 0, all operations on the swap file are serial. it may cause a long delay, but it guarantees data integrity.
Vm-max-threads 4
27. put the small output cache together so that multiple responses can be sent to the client in a TCP packet. I am not very clear about the specific principle and actual effect. So according to the annotations, you can set it to yes if you are not sure.
Glueoutputbuf yes
28. hash data structure is introduced in redis 2.0. When the hash contains more than the specified number of elements and the maximum number of elements does not exceed the critical value, hash will be stored in a special encoding method (greatly reducing memory usage, the two thresholds can be set here.
Hash-max-zipmap-entries 64
29. maximum value of an element in hash
Hash-max-zipmap-value 512
30. after it is enabled, redis will use a CPU time of 1 ms every 100 ms to re-hash the redis hash table, which can reduce the memory usage. When your application scenario requires strict real-time performance and you cannot accept Redis's 2 ms latency for requests from time to time, set this parameter to no. If you do not have such strict real-time requirements, you can set it to yes to release the memory as quickly as possible.
Activerehashing yes

5. install the php-Redis module:
If your machine does not have phpize, install the php-devel package first.
sudo apt-get install php-devel

Reference
Cd/usr/local/src
Wget -- no-check-certificate http://github.com/owlient/phpredis/tarball/master-O phpredis.tar.gz
Tar zxvf phpredis.tar.gz
Cd phpredis *
Phpize
./Configure -- with-php-config =/usr/local/php/bin/php-config
Make
Sudo make install

Restart the web service after installation.
6. Redis interface management tools
A php version of Redis WEB visual management software
Download https://github.com/ErikDubbelboer/phpRedisAdmin/downloads here
In the web directory, you can access
7. Use of php code
$redis = new Redis();$redis->connect('127.0.0.1', 6379);$redis->set('key', 'val');echo $redis->get('key');

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.