Differences between memcache and redis: No comment on mood in April 27, 2014
Official definition of memcache
Free & open source, high-performance, distributed memory Object Caching System, generic in nature, but intended for use in speeding up dynamic Web applications by alleviating database load.
Official definition of redis
Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
Same Copyright
Both use the BSD Protocol. Projects that use it can be used for commercial users. You do not need to publish the code that is modified twice, but you can modify the source code.
Data Type
Apsaradb for redis supports a wide range of data types, including set liset.
Memcache supports simple data types and requires the client to process complex objects by itself.
Durability
Redis supports persistent data storage
Memcache does not support persistent data storage.
Distributed Storage
Redis supports master-slave replication Mode
Memcache can be distributed using consistent hash
Different value sizes
Memcache is a memory cache with a key length less than 250 characters and a single item storage less than 1 MB. It is not suitable for virtual machines.
Different Data Consistency
Redis uses a single-threaded model to ensure that data is submitted in order.
Memcache uses CAs to ensure data consistency. CAS (check and set) is a mechanism to ensure concurrency consistency and belongs to the "optimistic lock" category. The principle is simple: Take the version number, operate, compare the version number, and operate if it is consistent, if they are inconsistent, discard any operation.
CPU utilization
The single-threaded redis model can only use one CPU, and multiple redis processes can be enabled
Reference
Http://www.cnblogs.com/qunshu/p/3196972.html
Http://www.blogjava.net/chhbjh/archive/2012/02/21/370472.html
Http://maoyidao.iteye.com/blog/1846089
Classification: redis tags: memcache, redisredis and redis PHP extensions post: May 29, 2013 mood1
Redis is a memory database that supports more value types than memcache. Sina Weibo uses redis for caching.
Install redis source code
wget http://download.redis.io/redis-stable.tar.gztar -zxvf redis-stable.tar.gzcd redis-stablemakemake testmake install
1. the following error may be reported during make:
zmalloc.o: In function `zmalloc_used_memory‘:/root/redis-stable/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4‘collect2: ld returned 1 exit statusmake[1]: *** [redis-server] Error 1make[1]: Leaving directory `/root/redis-stable/src‘make: *** [all] Error 2
Solution:
Edit the OPT in src/. Make-settings and change it to OPT =-O2-March = i686.
2. Make test:
You need tcl 8.5 or newer in order to run the Redis testmake: *** [test] Error 1
Solution: Install TCL
wget http://downloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gzcd tcl8.6.0/cd unix &&./configure --prefix=/usr --mandir=/usr/share/man --without-tzdata $([ $(uname -m) = x86_64 ] && echo --enable-64bit) &&make &&sed -e "[email protected]^\(TCL_SRC_DIR=‘\).*@\1/usr/include‘@" -e "/TCL_B/[email protected]=‘\(-L\)\?.*[email protected]=‘\1/usr/[email protected]" -i tclConfig.shmake install &&make install-private-headers &&ln -v -sf tclsh8.6 /usr/bin/tclsh &&chmod -v 755 /usr/lib/libtcl8.6.so
Redis command Introduction
Redis consists of four executable files: redis-benchmark, redis-CLI, redis-server, and redis-stat. conf constitutes the final available package of the entire redis. Their functions are as follows:
Redis-server: Daemon Startup Program of the redis Server
Redis-CLI: redis command line operation tool. Of course, you can also use Telnet to operate based on its plain text protocol.
Redis-benchmark: redis performance testing tool to test the read/write performance of redis in your system and your configuration
Redis-stat: redis status detection tool that can detect redis's current status parameters and latency
Now you can start redis. redis has only one startup parameter, that is, its configuration file path.
Start redis
Copy redis. conf in the source package to/etc.
# Cd redis-stable
# Cp redis. CONF/etc/redis. conf
Edit/etc/redis. conf and modify
Daemaon no is daemaon yes and starts the process as a daemon process.
# Redis-server/etc/redis. conf
Disable redis
# Redis-cli shutdown // close all
Disable redis on a port
# Redis-cli-P 6397 shutdown // shut down redis on port 6397
Note: cache data will be automatically dumped to the hard disk after it is disabled. For the hard disk address, see dbfilename dump. RDB in redis. conf.
Redis Configuration
Note: by default, the daemonize parameter of the previously copied redis. conf file is no, so redis will not run in the background. to test it, we need to re-open a terminal. If it is changed to yes, redis is run in the background. In addition, the PID file, log file, and data file address are specified in the configuration file. If you need to modify the address first, the default log information is directed to stdout.
The main configuration parameters of redis. conf are as follows:
Daemonize: whether to run in daemon mode
Pidfile: PID File Location
Port: the port number of the listener.
Timeout: Request timeout
Loglevel: log information level
Logfile: Location of the log file
Databases: number of databases Enabled
Save **: the frequency at which snapshots are saved. The first "*" indicates the duration and the third "indicates the number of write operations performed. Snapshots are automatically saved when a certain number of write operations are performed within a certain period of time. You can set multiple conditions.
Rdbcompression: whether to use Compression
Dbfilename: Data snapshot file name (only file name, excluding directory)
Dir: directory for storing data snapshots (this is the Directory)
Appendonly: whether to enable appendonlylog. If it is enabled, a log is recorded for each write operation, which improves data risk resistance but affects efficiency.
Appendfsync: How to synchronize appendonlylog to the disk (three options are force-call fsync for each write, enable fsync once per second, and do not call fsync to wait for the system to synchronize itself)
Now you can open a terminal for testing. The default listening port in the configuration file is 6379.
Automatic startup of redis upon startup
Before using this script for management, you must configure the following kernel parameters. Otherwise, an error will be reported when the redis script restarts or stops redis, data cannot be automatically synchronized to the disk before the service is stopped:
# Vi/etc/sysctl. conf
VM. overcommit_memory = 1
Then the application takes effect:
# Sysctl-P
Create a redis STARTUP script:
# Vim/etc/init. d/redis
#!/bin/bash # # Init file for redis # # chkconfig: - 80 12 # description: redis daemon # # processname: redis # config: /etc/redis.conf # pidfile: /var/run/redis.pid source /etc/init.d/functions #BIN="/usr/local/bin" BIN="/usr/local/bin" CONFIG="/etc/redis.conf" PIDFILE="/var/run/redis.pid" ### Read configuration [ -r "$SYSCONFIG" ] && 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 "$1" in start) start ;; stop) stop ;; restart) restart ;; condrestart) [ -e /var/lock/subsys/$prog ] && restart RETVAL=$? ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" RETVAL=1 esac exit $RETVAL
Then add the service and start it automatically:
# chmod 755 /etc/init.d/redis # chkconfig --add redis # chkconfig --level 345 redis on # chkconfig --list redis
Redis PHP extension Installation
Wget-O https://github.com/nicolasff/phpredis/zipball/master
Unzip php-redis.zip
CD nicolasff-phpredis-2d0f29b/
/Usr/local/PHP/bin/phpize
./Configure -- With-PHP-Config =/usr/local/PHP/bin/PHP-config
Make & make install
After the installation is complete, redis. So is installed
/Usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20100525/
VI/usr/local/PHP/lib/PHP. ini
Add
Extension = redis. So
Restart PHP-FPM.
You may encounter configure when adding the -- with-PHP-config parameter.
Configure: Error: cannot find PHP-config. Please use -- With-PHP-Config = path
./Configure -- With-PHP-Config =/usr/local/PHP/bin/PHP-config
Classification: redis tags: redis, startup, installation, and expansion