[Redis album] [1] methods and steps for installing php-redis under ubuntu12.04, redisphp-redis
First release path: Install phpredis
I haven't written a blog post for a long time, and I haven't completed many blog posts. Today I just took the time to finish this blog post. I hope it will be helpful to you.
First, let's give a brief introduction to redis:
Redis is completely open-source and free. It complies with the BSD Protocol and is an advanced key-value persistence product. It is usually called a Data Structure server, because values can be strings, maps, lists, sets) and sorted sets.
This is a Chinese translation of the official website. You do not need to write it in English. If you want to read English, you can go to redis. io to check it out. If you want to read Chinese, you can go to redis.cn to check it out.
Many people have written about the installation and use of php-redis. Here I just complete a verification process.
Install redis
Wget http://download.redis.io/redis-stable.tar.gz
Tar xvzf redis-stable.tar.gz
Cd redis-stable
Make
Sudo make install (if the root user does not need sudo)
After the installation is complete, copy the configuration file redis. conf to make it easier to use.
Sudo mkdir/etc/redis/
Sudo cp redis. conf/etc/redis/
Start redis and check the startup method:
Redis-server/etc/redis. conf
Interface effect after startup:
Geeknimo @ bogon :~ /Documents/phpredis $ redis-server/etc/redis. conf
[16859] 07 Aug 10:05:30. 292 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
[16859] 07 Aug 10:05:30. 293 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted.
[16859] 07 Aug 10:05:30. 293 # Current maximum open files is 1024. maxclients has been forced CED to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit-n '.
[16859] 07 Aug 10:05:30. 293 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction 'policy now.
_._
_.-"_"-. _
_.-"'.' _."-. _ Redis 2.8.13 (00000000/0) 32 bit
.-".-" '. "' \/_., _"-. _
(',.-' | ',) Running in stand alone mode
| '-._'-... -'__... -. "-. _ |'' _.-'| Port: 6379
| '-. _'. _/_.-'| PID: 16859
'-._'-._'-./_.-'_.-'
| '-. _.-' |
| '-. _'-. _.-'_.-' | Http://redis.io
'-._'-._'-.__.-'_.-'_.-'
| '-. _.-' |
| '-. _'-. _.-'_.-' |
'-._'-._'-.__.-'_.-'_.-'
'-._'-.__.-'_.-'
'-.__.-'
'-.__.-'
[16859] 07 Aug 10:05:30. 308 # Server started, Redis version 2.8.13
[16859] 07 Aug 10:05:30. 308 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. to fix this issue add'vm. overcommit_memory = 1' to/etc/sysctl. conf and then reboot or run the command 'sysctl vm. overcommit_memory = 1' for this to take effect.
[16859] 07 Aug 10:05:30. 308 * The server is now ready to accept connections on port 6379
To run the command in the background, run redis-server/etc/redis. conf &, or modify the daemonize in the configuration file/etc/redis. conf to yes.
After daemonize is set, start redis-server and use redis-cli to connect to redis-server.
Redis-cli
After successful connection:
Geeknimo @ bogon :~ /Documents/phpredis $ redis-cli
Wagner. 0.0.1: 6379>
Enter info to View Details:
127.0.0.1: 6379> info
# Server
Redis_version: 2.8.13
Redis_git_sha1: 00000000
Redis_git_dirty: 0
Redis_build_id: 7331093c2c819968
Redis_mode: standalone
OS: Linux 3.2.0-29-generic-pae i686
Arch_bits: 32
Multiplexing_api: epoll
Gcc_version: 4.6.3
Process_id: 16890
Run_id: 660fc790eb501ea29b01b8bb9551f4711ab5f151
Tcp_port: 6379
Uptime_in_seconds: 6
Uptime_in_days: 0
Hz: 10
Lru_clock: 14868319
Config_file:/etc/redis. conf
# Clients
Connected_clients: 1
Client_longest_output_list: 0
Client_biggest_input_buf: 0
Blocked_clients: 0
# Memory
Used_memory: 424880
Used_memory_human: 414.92 K
Used_memory_ RSS: 1609728
Used_memory_peak: 424880
Used_memory_peak_human: 414.92 K
Used_memory_lua: 22528
Mem_fragmentation_ratio: 3.79
Mem_allocator: jemalloc-3.6.0
# Persistence
Loading: 0
Rdb_changes_since_last_save: 0
Rdb_bgsave_in_progress: 0
Rdb_last_save_time: 1407377241
Rdb_last_bgsave_status: OK
Rdb_last_bgsave_time_sec:-1
Rdb_current_bgsave_time_sec:-1
Aof_enabled: 0
Aof_rewrite_in_progress: 0
Aof_rewrite_scheduled: 0
Aof_last_rewrite_time_sec:-1
Aof_current_rewrite_time_sec:-1
Aof_last_bgrewrite_status: OK
Aof_last_write_status: OK
# Stats
Total_connections_received: 1
Total_commands_processed: 0
Instantaneous_ops_per_sec: 0
Rejected_connections: 0
Sync_full: 0
Sync_partial_ OK: 0
Sync_partial_err: 0
Expired_keys: 0
Evicted_keys: 0
Keyspace_hits: 0
Keyspace_misses: 0
Pubsub_channels: 0
Pubsub_patterns: 0
Latest_fork_usec: 0
# Replication
Role: master
Connected_slaves: 0
Master_repl_offset: 0
Repl_backlog_active: 0
Repl_backlog_size: 1048576
Repl_backlog_first_byte_offset: 0
Repl_backlog_histlen: 0
# CPU
Used_cpu_sys: 0.00
Used_cpu_user: 0.00
Used_cpu_sys_children: 0.00
Used_cpu_user_children: 0.00
# Keyspace
This indicates that the redis service has been successfully started. As for optimization, we will talk about it later.
Next we will configure php-redis
First install git, php5, apache2, php5-dev
Sudo apt-get install php5 php5-dev apache2
Time required for Installation
In the php-redis source code directory, run
Git clone https://github.com/nicolasff/phpredis.git
Phpize
./Configure
Make & sudo make install
Prompt message:
Installing shared extensions:/usr/lib/php5/20121212 + lfs/
The shared library is in the above prompt path
Configure php-redis
Create index. php under/var/www/html and write the following content:
<? Php
Phpinfo ();
?>
And create a redis. ini under/etc/php5/mod-available. The content is as follows:
Extension = redis. so
And in/etc/php5/apache2/conf. d and/etc/php5/cli/conf. d. ini soft link. The cli part is critical. Otherwise, php-m cannot obtain any module information of redis, that is, it cannot load and use phpredis.
Ln-s/etc/php5/mod-available/redis. ini/etc/php5/cli/conf. d/10-redis.ini
Ln-s/etc/php5/mod-available/redis. ini/etc/php5/apache2/conf. d/10-redis.ini
Restart apache2
Sudo service apache2 restart
Open the ip address/index. php corresponding to ubuntu and you will be able to see the configuration of php-redis.
Additional. ini files parsed |
/Etc/php5/apache2/conf. d/05-opcache.ini,/etc/php5/apache2/conf. d/10-pdo.ini,/etc/php5/apache2/conf. d/10-redis.ini,/etc/php5/apache2/conf. d/20-json.ini,/etc/php5/apache2/conf. d/20-readline.ini |
Redis
Redis Support |
Enabled |
Redis Version |
2.2.5 |
Session
Session Support |
Enabled |
Registered save handlers |
Files user redis |
Registered serializer handlers |
Php_serialize php php_binary wddx |
With this information, start testing the code.
Create testredis. php with the following content:
<? Php
$ Redis = new Redis ();
$ Redis-> connect ('2017. 0.0.1 ', 127 );
Var_dump ($ redis-> info ());
?>
Execute php testredis. php
You can see the corresponding content on the terminal
You can also see the corresponding content on the web side.
In this case, php-redis is basically set up.
How can php redis respond?
Redis stores data in the memory and loses power. Pay attention to this. Make a persistence if necessary. The persistence method is hard to understand. For more information, see the article on the Internet.
Php's redis extension is called php-redis. The php-redis Chinese manual is available on the Internet. The following is an example:
<? Php $ redis = new redis (); $ result = $ redis-> connect ('2017. 0.0.1 ', 6379); // 6379 is the default port $ result = $ redis-> set ('123', "comment "); // set the key value echo $ result = $ redis-> get ('20140901'); // get the key value $ all = $ redis-> getMultiple (array ('20140901 ', '9639002718'); // obtain multiple key values at the same time // The method for obtaining all key values is not provided. I'm not sure whether it can be used. You can give it a try. $ All = $ redis-> getMultiple (array ('*'));
Thank you for your support!
What's the next project
Welcome! Welcome! Welcome! Welcome! Welcome! Welcome!