Redis is an open source, support network, based on memory, key-value pairs of the Key-value database, this article mainly introduced the Redis contrast Memcached and in the CentOS under the installation configuration detailed, interested can understand.
Find out about Redis.
Redis is an open source, support network, Key-value database based on memory, key-value pairs, with ANSI C, and provides a variety of language APIs, it is almost without difficulty, it takes only a few minutes to complete the installation work, and let it start with the application smooth collaboration. In other words, a small amount of time and effort is needed to get a quick and effective performance boost, which is a very simple caching solution. It supports storage of the Value type is not limited to strings, support master-slave synchronization, data persistence and so on, we all think Redis is the most popular key-value storage database, someone must ask Memcached?
Redis VS Memcached
First of all, I just went to Db-engines.com's database ranking, Redis ranked Nineth, Key-value store
first, Memcached ranked 23, Key-value store
second. This certainly doesn't explain anything.
Redis supports more data types, including: string, Hash, List, set;memcached support only one string data type.
Redis through Multi/Watch/Exec
Such commands can support the concept of a transaction, atomic execution of a batch of commands; In Memcached application mode, there is no support for the transaction except for atomic operations commands such as Increment/decrement.
Redis can master-slave
configure the server to implement a master-slave synchronous backup, while holding only two persistence schemes, Memcached does not guarantee the validity of the stored data, nor does the data persistence work. Of course, none of this means anything.
Every thing exists in this world there is always meaning in him. Memcached's internal memory management mechanism, while not as complex as Redis, is more practical, because Memcached consumes less memory resources while processing metadata, and has more advantages in scaling than Redis. Because of its design tendency and relatively simpler function settings. For example, when caching a string or HTML page, it is better to use Memcached.
Install Redis under CentOS
1. Download decompression installation Redis, here is the latest version of the website download 3.2.5
, still by wget
downloading (I like this way).
wget http://download.redis.io/releases/redis-3.2.5.tar.gz
tar xzf redis-3.2.5.tar.gz
mv redis-3.2.5/usr/ Local/redis
The above mv redis-3.2.5 /usr/local/redis
command is to move Redis installation files to the installation directory, of course this directory you can customize.
2. Enter directory, compile and install
Cd/usr/local/redis make make
install
Installation completed, this time will be in the /usr/local/bin/
directory to see redis-server、redis-cli
the executable script, into a look, if not, will be to extract the directory to copy in.
3. Configureredis.conf
Go back to /usr/local/redis
the directory and configure:
Cd.. /redis
Vim redis.conf
Here to modify two places, one bind
and daemonize
on the line.
bind
here Configure to note that the default is only one 127.0.0.1
, this time can only connect themselves, other LAN is not connected. So, you need to configure multiple IP, so you can connect within the LAN.
daemonize
is to set whether the background boot Redis, the default no
, the normal need to start the Redis service, so this is set to yes
.
After the modification, save the exit.
Here are the parameters of the configuration file I no longer one by one to repeat, there is a call Linli8 Bo Lord said to stay up late translation, haha, interested can see: https://github.com/linli8/cnblogs/blob/master/redis%E5% 89%af%e6%9c%ac.conf
4. Start
cd/usr/local/bin/
redis-server/usr/local/redis/redis.conf
netstat-anp | grep 6379
5. Test
Here, use the command-line mode to connect the Redis for a simple setup, get the cache test.
Redis-cli #连接 Redis, the default is native.
keys * #查看现在所有 key
set name Mafly #设置一个key为 ' name ', the value is ' mafly ' cache object. The cache of Get name #获取key为 ' name '
6. Close Redis
By netstat you can see that the port is already TIME_WAIT
state.
To sum up
After this installation configuration Redis process, also let me know more about the Memcached, but also more understand the two most popular key-value caching services, of course, most of them are obtained through the network, in the actual use of how also in the monitoring.
Every open source software is worthy of everyone to respect, every time using the open source software I have a moving heart, thank the author's selfless dedication, of course, commercial software in the domestic situation is still worth pondering, a company with the ability to buy genuine software why is still using pirated software?
I hope this article is of little use to you. We also hope that we can support the cloud-dwelling community.