Test engineers must know and know-Redis

Hello everyone, I am Tester1991, an ordinary test engineer, love life and love to share!

Redis official website

https://redis.io/download

Install Redis on Alibaba Cloud Server

$ wget http://download.redis.io/releases/redis-6.0.8.tar.gz
$ tar xzf redis-6.0.8.tar.gz
$ cd redis-6.0.8
$ make

If the following errors occur during installation: 

             serverLog(LL_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket);
                                                                                              ^
server.c:5103:19: error: ‘struct redisServer’ has no member named ‘supervised_mode’
         if (server.supervised_mode == SUPERVISED_SYSTEMD) {
                   ^
server.c:5104:24: error: ‘struct redisServer’ has no member named ‘masterhost’
             if (!server.masterhost) {
                        ^
server.c:5117:15: error: ‘struct redisServer’ has no member named ‘maxmemory’
     if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
               ^
server.c:5117:39: error: ‘struct redisServer’ has no member named ‘maxmemory’
     if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
                                       ^
server.c:5118:176: error: ‘struct redisServer’ has no member named ‘maxmemory’
         serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);
                                                                                                                                                                                ^
server.c: In function ‘hasActiveChildProcess’:
server.c:1476:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘allPersistenceDisabled’:
server.c:1482:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘writeCommandsDeniedByDiskError’:
server.c:3747:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘iAmMaster’:
server.c:4914:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make[1]: *** [server.o] Error 1
make[1]: Leaving directory `/usr/src/redis-6.0.1/src'
make: *** [install] Error 2

The reason for the above error is that the installation of redis6.0+ and above requires gcc version 5.3 and above.

View the current gcc version

gcc -v

We found that on the Alibaba Cloud server, the gcc version of the centos7 system defaults to 4.8.5.

So we need to upgrade the gcc version.

//升级gcc到9以上
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

还需要执行下面命令,二者任选其一
//临时将此时的gcc版本改为9
scl enable devtoolset-9 bash
//或永久改变
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

After performing the above operations, execute the gcc -v command, we will find that the gcc version has been successfully upgraded to 9.1.1. Next, we continue to execute make to install redis6.0+, there should be no problems.

After redis6.0+ is successfully installed, how can we verify whether the redis service is normal?

启动服务端
src/redis-server

As shown above, we found that the redis service has been started normally.

The redis server has been started successfully, how do we connect the client?

Redis configuration file

Location: redis.conf file under the redis installation path

Modify the redis.conf configuration file

1.daemonize is set to yes

2. Comment out bind 127.0.0.1 and add bind 0.0.0.0

3. Change protected-mode yes to protected-mode no

 Configure Alibaba Cloud Security Group Rules

 

 After the above configuration, we can now use the redis client to connect to the redis service on our Alibaba Cloud.

Redis client

For the Redis client, I recommend that you use AnotherRedisDesktopManager, an open source tool.

AnotherRedisDesktopManager address

https://github.com/qishibo/AnotherRedisDesktopManager

 AnotherRedisDesktopManager supports directly opening the redis command client through the tool.

Python connects to Redis

import redis

pool = redis.ConnectionPool(host='xxx', port='6379', decode_responses=True)
r = redis.Redis(host='xxx', port='6379', decode_responses=True, password='xxx')
print(r.get('name'))

 Java connect to Redis

 

import redis.clients.jedis.Jedis;

public class RedisTest {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("xxx", 6379);
        jedis.auth("root");
        System.out.println("连接成功");
        //查看服务是否运行
        System.out.println("服务正在运行: " + jedis.ping());
        System.out.println("redis 存储的字符串为: " + jedis.get("name"));
    }
}

If you think my article has helped you, I will continue to share software testing related knowledge in the follow-up. I will record the actual video of this blog and upload it. Welcome everyone to learn testing knowledge and share!

 

 

 

Guess you like

Origin blog.csdn.net/qq_22693733/article/details/108781644