Redis compared to Memcached and installed and configured under CentOS

高洛峰
Release: 2023-03-01 13:28:01
Original
893 people have browsed it

Learn about Redis

Redis is an open source, network-enabled, memory-based, key-value database. It is written in ANSI C and provides APIs in multiple languages. It is almost not difficult to get started, and it only takes a few minutes. You can complete the installation and let it start working smoothly with the application. In other words, with only a small investment of time and effort, you can get immediate and excellent performance improvements, which means it is a very simple caching solution. It supports stored Value types that are not limited to strings, but also supports master-slave synchronization, data persistence, etc. Everyone thinks that Redis is the most popular Key-Value storage database. Someone must ask about Memcached?

Redis VS Memcached

First of all, I just checked the database rankings of DB-Engines.com. Redis ranked ninth and Key-value store first; Memcached ranked 23rd and Key-value store second. . Of course this doesn't mean anything.

Redis supports more data types, including: String, Hash, List, Set; Memcached only supports one String data type.
Redis can support the concept of transactions through commands such as Multi/Watch/Exec and execute a batch of commands atomically; in the Memcached application mode, except for atomic operation commands such as increment/decrement, there is no support for transactions.
Redis can configure the server in the master-slave mode to achieve master-slave synchronous backup, and only supports two persistence solutions; Memcached does not guarantee the validity of the stored data, nor does it perform data persistence. Of course, none of this means anything.

Every thing in this world always has its meaning. Although Memcached's internal memory management mechanism is not as complex as Redis's, it is more practical and efficient because Memcached consumes relatively less memory resources when processing metadata; it also has advantages over Redis in terms of horizontal expansion because of its The design trend and relatively simple function settings. For example, when caching a string or Html page, it is relatively better to use Memcached.

Install Redis under CentOS

1. Download, unzip and install redis. Here is the latest 3.2.5 version downloaded from the official website. It is still downloaded through wget (I like this method).

wget http://download.redis.io/releases/redis-3.2.5.tar.gztar xzf redis-3.2.5.tar.gz
mv redis-3.2.5 /usr/local/redis
Copy after login

Redis compared to Memcached and installed and configured under CentOS

The above mv redis-3.2.5 /usr/local/redis command is to move the Redis installation file to the installation directory. Of course, you can customize this directory.

2. Enter the directory, compile and install

cd /usr/local/redis
make
make install
Copy after login

The installation is complete. At this time, you will see redis-server, redis-cli and other executable scripts in the /usr/local/bin/ directory. Enter and take a look. If not, Just go to the unzipped directory and copy it into it.

cd /usr/local/bin/

Redis compared to Memcached and installed and configured under CentOS

3. Configure redis.conf

Go back to the /usr/local/redis directory and configure:

cd ../redis
vim redis.conf
Copy after login

Redis compared to Memcached and installed and configured under CentOS

There are two places to modify here, Just a bind and daemonize will do.
Be careful when configuring bind here. By default, there is only one 127.0.0.1. At this time, you can only connect yourself, and you cannot connect to other LANs. Therefore, multiple IPs need to be configured so that connections can be made within the LAN.

Redis compared to Memcached and installed and configured under CentOS

daemonize is to set whether to start Redis in the background. The default is no. Normally, Redis needs to be started as a service, so it is set to yes here.

Redis compared to Memcached and installed and configured under CentOS

修改完后,保存退出。

4.启动

cd /usr/local/bin/
redis-server /usr/local/redis/redis.conf
netstat -anp | grep 6379
Copy after login

Redis compared to Memcached and installed and configured under CentOS

5.测试一下
这里用命令行模式连接上 Redis 进行一个简单的设置、获取缓存测试。

redis-cli    #连接 Redis ,默认是本机的。
keys *       #查看现在所有 
keyset name mafly    #设置一个key为`name`,value为`mafly`的缓存对象。
get name     #获取key为`name`的缓存
Copy after login

Redis compared to Memcached and installed and configured under CentOS

6.关闭 Redis

redis-cli shutdown

Redis compared to Memcached and installed and configured under CentOS

通过 netstat 可以看出来端口已经是TIME_WAIT状态了。

总结一下

经过这次安装配置 Redis 的过程,也让我更加了解了一下 Memcached ,也更明白了这两种最流行的 Key-Value 缓存服务的优劣势,当然大多数都是通过网络获取,在实际运用中怎样也在监测中。



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!