Redis Installation
1, Download:
TCL 8.5:
http://www.tcl.tk/
Redis:
Http://redis.io
2, installation
First install tcl8.5:
TAR-ZXVF tcl8.6.1-src.tar.gz
cd Tcl8.6.1/unix
./configure make
&& make install
Re-install Redis:
TAR-ZXVF redis-2.6.16.tar.gz
cd redis-2.6.16 make to
test make
Install
3, simple configuration:
Before running Redis, we need to configure it. The Redis configuration file is in your installation directory. The name is: redis.conf.
Simple to say a few redis.conf:
Redis default is not a daemon, if you need to change, daemonize No to daemonize yes. (The test can not change, look at printing information.)
If you are not comfortable with the default 6379 port for Redis, you can change port 6379
If you want the data file to be placed in a specified folder, change the dir/opt/data/
Default is dir./It is by default placed in the installation directory.
Dir is the data file path. The default is under the installation directory.
* Select one of the following configuration two, as detailed in the comments section of this article, 2.
###### snapshotting ##### #内存快照方式:
The default memory snapshot policy is
900 seconds (15 minutes), at least 1 changes in data,
or 300 seconds, with at least 10 data changes;
or 60 seconds , there are at least 1000 data changes, time + data change times, together affecting the emergence of memory snapshots.
###### APPEND only mode ###### aof
Appendfsync everysec sync per second. This can be commented out, open the following options Appendfsync no
The rest of the configuration, the comments in the Conf write quite clear, I will not much nonsense. Everyone look at their own match on the line.
The following are the meaning of the main configuration parameters of redis.conf:
Daemonize: Whether to run after the daemon mode
Pidfile:pid File Location
Port: The port number listening
Timeout: Request Timeout time
Loglevel:log Information level
Logfile:log File Location
Databases: number of databases Open
Save * *: How often the snapshot is saved, how long the first * represents, and the third * indicates how many writes have been performed. Automatically saves snapshots when a certain number of writes are performed within a certain amount of time. Multiple conditions can be set.
Rdbcompression: Whether to use compression
Dbfilename: Data Snapshot file name (just filename, excluding directory)
Dir: Save directory for Data snapshots (this is a directory)
AppendOnly: Whether to turn on the Appendonlylog, open the word every write will remember a log, which will improve the risk-resistant ability of data, but affect efficiency.
Appendfsync:appendonlylog How to sync to disk (three options, each write is forced to call Fsync, enable once per second Fsync, do not call Fsync wait for the system to sync itself)
At this point you can open a terminal for testing, the default listening port in the configuration file is 6379 configuration details Chinese reference: Https://github.com/silenceper/my/blob/master/config/redis2.4.chinese
4, start Redis
In the installation directory # CD SRC
#./redis-server./... /redis.conf
Note:
2.0.4 Previous version, running very simple, under the installation directory:
#./redis-server
You can also copy the relevant commands to/usr/bin and run them.
# CD redis-stable
# cp redis.conf/etc/redis.conf
# redis-server/etc/redis.conf
5, close Redis.
# REDIS-CLI Shutdown//Close all
To close a redis on a port
# redis-cli-p 6397 shutdown//Close 6397-Port Redis
Note: After the shutdown, the cached data will automatically dump to the hard disk, the hard disk address see redis.conf in the Dbfilename Dump.rdb
6. Test
# redis-cli
redis> set name Songbin
OK
redis> get name
"Songbin"
7, Redis boot automatically
Before you can use this script to manage, you need to configure the following kernel parameters, otherwise the Redis script will error when you restart or stop Redis, and you cannot automatically synchronize data to disk before stopping the service:
# vi/etc/sysctl.conf
Vm.overcommit_memory = 1
Then the application takes effect:
# sysctl–p
To create a Redis startup script:
# Vim/etc/init.d/redis
# Vim/etc/init.d/redis #!/bin/bash # init file for Redis # chkconfig:-# Description:redis Daemon # Processname:redis # Config:/etc/redis.conf # pidfile:/var/run/redis.pid source/etc/init.d/functions #BIN = "/usr/lo Cal/bin "bin="/usr/local/bin "config="/etc/redis.conf "pidfile="/var/run/redis.pid "### Read configuration [-R" $SYS CONFIG "] && source" $SYSCONFIG "retval=0 prog=" Redis-server "desc=" Redis Server "start () {if [E $ Pidfile];then echo "$desc already running ..." Exit 1 fi echo-n $ "starting
$desc: "Daemon $BIN/$prog $CONFIG retval=$? echo [$RETVAL-eq 0] && touch/var/lock/subsys/$prog return $RETVAL} stop () {echo
-N $ "Stop $desc:" Killproc $prog retval=$?
echo [$RETVAL-eq 0] && rm-f/var/lock/subsys/$prog $PIDFILE return $RETVAL} restart () { Stop start} case "in Start" start;;
stop) stop;;
restart) restart;;
Condrestart) [-e/var/lock/subsys/$prog] && restart retval=$?
;;
Status $prog retval=$?
;; * echo $ "Usage: $ {start|stop|restart|condrestart|status}" retval=1 Esac exit $RETVAL
Then add the service and boot from:
# chmod 755/etc/init.d/redis
# chkconfig--add redis
# chkconfig--level 345 redis in
# chkconfig--list Redi S
Comments:
The default port number for ▲redis is 6379, according to Redis's author Antirez, 6379 is the number of Merz on the keypad, and Merz is the name of the Italian diva Alessia Merz. And Merz has long been antirez and his friends as a byword for stupidity. )
▲redis There are two ways to store, the default is the snapshot way, the implementation method is timed to the memory of the snapshot (snapshot) persisted to the hard disk, the disadvantage is that after the persistence of the crash will lose a piece of data. As a result of the perfectionist, the author adds a aof approach. AOF, append only mode, saves the operation commands to the log file while writing the memory data.
Php-redis Extended Installation
1, Download:
Http://pecl.php.net
2, installation
TAR-ZXVF redis-2.2.4.tgz
cd redis-2.2.4
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/ local/php/bin/
/php-config make
&& make install
3, modify PHP.ini
Extension=redis.so
4. Restart PHP
Kill ' Cat/var/run/php-fpm.pid ' &&/usr/local/php/sbin/php-fpm
Using Phpredisadmin to manage Redis
git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
cd phpredisadmin
git clone https://github.com /nrk/predis.git Vendor
You can manage it by moving to a directory that you can access. (If an error is made to see if SELinux is closed)
Common Commands
Redis commonly used commands are divided into two aspects, one is the key-value related commands, one is the server-related commands
1, key value related commands
Keys * Remove all current key
exists name to see if n has name this key
Del name Delete key name
Expire Confirm 100 Set confirm this key100 second expires
TTL confirm gets the effective length of this key confirm
Select 0 Choose to 0 database Redis The default database is 0~15 altogether 16 databases
Move confirm 1 moves the key in the current database to another database, where you move the Confire key from the current database to 1
Persist confirm removes the expiration time for this key confirm
Randomkey randomly returns a key inside the database
Rename Key2 key3 rename Key2 to Key3
Type Key2 returns the data type of the key
2, server-related commands
Ping pong Returns whether the response is connected successfully
Echo Prints some content at the command line
Select 0~15 Numbered Database
Quit/exit Exit Client
Dbsize returns the number of key keys in the current database
Info returns information on Redis
Config get dir/* live transmit requests received
FLUSHDB Delete all keys in the currently selected database
Flushall Delete databases in all databases