First release path: Phpredis installation
A long time did not write blog, a lot of posts are not finished, today just take time to finish this blog post, I hope to have a certain help to everyone
Let's start with a brief introduction to Redis:
Redis is fully open source free, complies with BSD protocol, advanced Key–value persistent products. It is commonly referred to as a data structure server, because the value can be a string (string), a hash (MAP), a list, a collection (sets), and an ordered collection (sorted sets).
This is the official website of the Chinese translation, the English is not necessary to write up, if you want to see English, you can go to redis.io up to see, Chinese can go to redis.cn to see
About the installation and use of Php-redis has been written by a lot of people, I am here just to complete a verification process
Installing 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 can not use sudo)
After the installation is complete, copy the following configuration file redis.conf, here for more convenient use
sudo mkdir/etc/redis/
sudo cp redis.conf/etc/redis/
At this point start the next redis look at the boot method:
Redis-server/etc/redis/redis.conf
The interface effect after startup:
[Email protected]:~/documents/phpredis$ redis-server/etc/redis/redis.conf
[16859] 10:05:30.292 # requested maxclients of 10000 requiring at least 10032 max file descriptors.
[16859] 10:05:30.293 # Redis can ' t set maximum open files to 10032 because of OS error:operation not permitted.
[16859] 10:05:30.293 # Current maximum open files are 1024. MaxClients have been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase ' ulimit-n '.
[16859] 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)
.-".-" '. "' \ \ _.,_"-._
(',.-' | ',) Running in Stand alone mode
| '-._ '-...-' __...-. ' -._| ' ' _.-' | port:6379
| '-._ '. _/_.-' | pid:16859
'-._ '-._ '-./_.-' _.-'
| '-._ '-._ '-.__.-' _.-' _.-' |
| '-._ '-._ _.-' _.-' | Http://redis.io
'-._ '-._ '-.__.-' _.-' _.-'
| '-._ '-._ '-.__.-' _.-' _.-' |
| '-._ '-._ _.-' _.-' |
'-._ '-._ '-.__.-' _.-' _.-'
'-._ '-.__.-' _.-'
'-._ _.-'
'-.__.-'
[16859] 10:05:30.308 # Server started, Redis version 2.8.13
[16859] 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.overcom Mit_memory=1′for this to take effect.
[16859] 10:05:30.308 * The server is now-accept connections on port 6379
If you want to run in the background, you can perform redis-server/etc/redis/redis.conf &, or modify the Daemonize settings in the configuration file/etc/redis/redis.conf to Yes.
When set to Daemonize, start redis-server and connect to Redis-server using REDIS-CLI
Redis-cli
After the connection is successful:
[Email protected]:~/documents/phpredis$ redis-cli
127.0.0.1:6379>
Enter info to view:
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/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.92k
used_memory_rss:1609728
used_memory_peak:424880
used_memory_peak_human:414.92k
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 started successfully, as for the optimization, the following article
Next we go to configure Php-redis
The first thing to install is Git,php5,apache2,php5-dev
sudo apt-get install php5 php5-dev apache2
Installation takes some time
Under the Php-redis source code directory, execute the
git clone Https://github.com/nicolasff/phpredis.git
Phpize
./configure
Make && sudo make install
Tip Information:
Installing Shared extensions:/usr/lib/php5/20121212+lfs/
Shared library under the path indicated above
Configure Php-redis
Create index.php under/var/www/html and write the following:
<?php
Phpinfo ();
?>
And under the/etc/php5/mods-available set up a Redis.ini, the contents are as follows:
Extension=redis.so
And in/ETC/PHP5/APACHE2/CONF.D and/ETC/PHP5/CLI/CONF.D to establish a soft link with redis.ini, where the CLI this part is critical, otherwise php-m can not get any of the Redis module information, That cannot be loaded successfully using Phpredis
Ln-s/etc/php5/mods-available/redis.ini/etc/php5/cli/conf.d/10-redis.ini
Ln-s/etc/php5/mods-available/redis.ini/etc/php5/apache2/conf.d/10-redis.ini
Restart Apache2 Service
sudo service apache2 restart
Here you can see the configuration of the Php-redis by opening Ubuntu corresponding ip/index.php
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, you start to test the code
Set up the testredis.php, which reads as follows:
<?php
$redis = new Redis ();
$redis->connect (' 127.0.0.1′,6379);
Var_dump ($redis->info ());
?>
Then execute PHP testredis.php
can see the corresponding content at the terminal
You can also see the corresponding content on the Web side.