Linux Installation Redis Tutorial detailed

Source: Internet
Author: User
Tags hash php redis php script redis redis download install redis redis tutorial


Install Reids

Redis Download Address: http://www.redis.io/download # wget http://download.redis.io/releases/redis-2.8.13.tar.gz #  cd redis-2.8.13/# make zmalloc.o: in function  ' zmalloc_used_memory ':/usr/local/
webserver/redis-2.8.13/src/zmalloc.c:226: undefined reference to  ' __sync_add_and_fetch_4 ' Collect2: ld returned 1 exit status Make[1]: *** [redis-server] error  1 make[1]: leaving directory  '/usr/local/webserver/redis-2.8.13/src ' make: *** [ All] error 2   # make cflags= "-march=i686"   Mkdir /usr/redis # cp  Redis.conf  /usr/redis # cd ./src # cp redis-server  /usr/redis # cp  redis-benchmark /usr/redis # cp redis-cli  /usr/redis   Cd /usr/redis #  redis-server redis.conf php install redis extension php redis extended download Address: Http://pecl.php.net/package/redis # wget http://pecl.php.net/get/redis-2.2.5.tgz # tar zxvf redis-2.2.5.tgz # cd  redis-2.2.5 # /usr/local/webserver/php/bin/phpize # ./configure --with-php-config=/usr/local/ Webserver/php/bin/php-config # make && make install # cp ./modules/ redis.so /usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20121212/


Modify php.ini and restart PHP-FPM

PHP script test

<?php

$redis = new Redis ();

$redis->connect (' 127.0.0.1 ', 6379);

$redis->set (' Time ', Time ());

echo $redis->get (' time ');

Description of configuration file parameters

1. Redis is not run as a daemon by default, and can be modified using Yes to enable the daemon process

Daemonize No

2. When Redis is running as a daemon, Redis writes the PID to the/var/run/redis.pid file by default, which can be specified by pidfile

Pidfile/var/run/redis.pid

3. Specify the Redis listening port, the default port is 6379, the author in his own posting explained why 6379 as the default port, because 6379 on the phone button on the number of Merz, and Merz from the Italian singer Alessia Merz name

Port 6379

4. The host address of the binding

Bind 127.0.0.1

5. Close the connection when the client is idle for a long time, or 0 if specified, to turn off the feature

Timeout 300

6. Specify logging level, Redis supports four levels in total: Debug, verbose, notice, warning, default to verbose

LogLevel verbose

7. Logging mode, default to standard output, if the configuration redis for the daemon mode, and this is configured as logging mode for standard output, the log will be sent to/dev/null

LogFile stdout

8. Set the number of databases, the default database is 0, you can use the Select command to specify the database ID on the connection

Databases 16

9. Specify how long, how many times the update operation, the data synchronized to the data file, can be multiple conditions with


Save <seconds> <changes>
There are three conditions available in the Redis default configuration file:
Save 900 1
Save 300 10
Save 60 10000
Each represents 1 changes in 900 seconds (15 minutes), 5 changes in 300 seconds (10 minutes), and 60 changes in 10,000 seconds.
10. Specifies whether to compress the data when stored to the local database, the default is Yes,redis with LZF compression, if you want to save CPU time, you can turn off this option, but it will cause the database file to become huge

Rdbcompression Yes

11. Specify the local database filename, the default value is Dump.rdb

Dbfilename Dump.rdb

12. Specify local Database storage directory

Dir./

13. Set the IP address and port of master service when this machine is Slav service, it automatically synchronizes data from master when Redis is started

Slaveof <masterip> <masterport>

14. When the master service is password protected, the Slav service connects Master's password

Masterauth <master-password>

15. Set the Redis connection password, if the connection password is configured, the client will need to provide the password through auth command when connecting Redis, the default shutdown

Requirepass foobared

16. Set the maximum number of client connections at the same time, the default unrestricted, Redis can open the number of client connections Redis process can open the maximum number of file descriptors, if set maxclients 0, which means no restrictions. When the number of client connections reaches a limit, Redis closes the new connection and returns the max number of clients reached error message to the client

MaxClients 128

17. Specify Redis maximum memory limit, Redis will load the data into memory at startup, and after reaching maximum memory, Redis will attempt to clear a key that has expired or is about to expire, and when this method is processed, it still reaches the maximum memory setting, no more writes will be made, but the read operation is still available. Redis the new VM mechanism, the key is stored in memory, and value is stored in the swap area

MaxMemory <bytes>

18. Specifies whether to log records after each update operation, redis the data to disk by default and, if not, may result in loss of data for a period of time if the power is not turned on. Because the Redis itself synchronizes data files according to the above save condition, some data will only exist in memory for a period of time. Default is No

AppendOnly No

19. Specify update log file name, default to Appendonly.aof

Appendfilename appendonly.aof

20. Specify an update log condition with 3 optional values:
No: Indicates that the operating system synchronizes data cache to disk (fast)
Always: Indicates that Fsync () is manually invoked after each update operation () to write data to disk (slow, secure)
Everysec: Indicates sync per second (compromise, default)

Appendfsync everysec

21. Specifies whether the virtual memory mechanism is enabled, the default is no, a simple introduction, the VM mechanism to store data paging, by Redis will be less visited the page that cold data swap to disk, Access to many pages from the disk automatically swapped out into memory (in the following article I will carefully analyze the VM mechanism of Redis)

Vm-enabled No

22. Virtual memory file path, default value is/tmp/redis.swap, not multiple Redis instance sharing

Vm-swap-file/tmp/redis.swap

23. Save all data larger than vm-max-memory into virtual memory, no matter how small the Vm-max-memory settings, all index data is memory storage (Redis index data is the keys), that is to say, when the vm-max-memory is set to 0, In fact, all of the value exists on the disk. The default value is
Vm-max-memory 0

Redis swap file is divided into a lot of page, an object can be saved on multiple page, but a page can not be shared by multiple objects, Vm-page-size is based on the size of the stored data set, the authors suggest that if you store a lot of small objects, The page size is best set to 32 or 64bytes; If you store a large object, you can use a larger page and, if unsure, use the default value


Vm-page-size 32

25. Set the number of pages in the swap file, because the page table (a bitmap that indicates that the page is idle or used) is in memory, which consumes 1byte of memory per 8 pages on disk.


Vm-pages 134217728

26. Set the number of threads to access the swap file, preferably do not exceed the machine's core, if set to 0, then all operation of the swap file is serial, may cause a relatively long delay. The default value is 4

Vm-max-threads 4

27. Set when replying to the client, whether to merge the smaller packages into one package send, default to open


Glueoutputbuf Yes

28. Specifies that a special hashing algorithm is used when more than a certain number or maximum element exceeds a critical value


Hash-max-zipmap-entries 64
Hash-max-zipmap-value 512

29. Specifies whether to activate the reset hash, which is turned on by default (described later when introducing the hash algorithm for Redis)

activerehashing Yes

30. Specifies that there are other configuration files that can use the same configuration file between multiple Redis instances on the same host, while each instance has its own specific configuration file


Include/path/to/local.conf

Related Article

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.