8-Quick Start Linux Playing Typical Applications-Cache Services: Redis&memcached

Keywords: Redis yum sudo Database

9-Cache Service

The amount of services hosted by database services is limited.

Add caching service layer between program and database.

Redis & memcached

memcached basic operations

explain command
install yum install memcached
start-up memcached -d -l -m -p
Stop it kill pid

The daemon runs after-d. How much memory is allocated?
- l listens for which server addresses. -p port number

11211 Service Port

Redis Basic Operations

explain command
install Source Code Compilation and Installation
start-up redis-server start/restart
Stop it redis-server stop
Client redis-client

yum install is recommended for online environments

Redis not only supports data of simple k/value type, but also provides storage of data structures such as list set hash.

Redis supports data backup, i.e. master-slave mode

Redis numbers support data persistence and can store data in memory on disk. When restarted, it can be loaded again for use.

sudo yum install memcached
ps -ef|grep memcache
man memcached
memcached
ps -ef|grep memcache
sudo netstat -anpl | grep memcache

The end of d generally refers to a service. Nginx Apache is designed to provide web service parsing. python java forwarded to us

mark

You can see that the listening port is 11211

Command-line interaction with mem

telnet
yum install telnet.*
mark

Telnet can judge whether our ip is smooth or not

telnet 127.0.0.1 80
telnet 127.0.0.1 3306
telnet 127.0.0.1 11211

Simple message data can be sent to our connection.

mark

Store data to MEM & get data & delete

mark

60 seconds automatically expire.

The console is occupied after the service is started. Unable to enter the following. So use the - d parameter at startup to make it a daemon.

set mtianyan 0 60 10
helloworld

key :mtianyan vlaue:helloworld

quit exits mem terminal

Both windows and xshell have local shells. It can be used to check whether the service port is open.

mark

Redis Basic Operations

Source code compilation.

mark

Right-click the copy link

http://download.redis.io/releases/redis-4.0.7.tar.gz

Enter the Virtual Machine

wget http://download.redis.io/releases/redis-4.0.7.tar.gz

Download the source package.

tar xzvf redis-4.0.7.tar.gz
cd redis-4.0.7

In general, there is an install file in the directory of source code compilation. Open readme for reading.

  • Step 1 make compiles
make[3]: gcc: Command not found
make[3]: *** [net.o] Error 127
make[3]: Leaving directory `/home/mtianyan/redis-4.0.7/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/home/mtianyan/redis-4.0.7/deps'
make[1]: [persist-settings] Error 2 (ignored)
    CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/home/mtianyan/redis-4.0.7/src'
make: *** [all] Error 2

Tell us which doesn't exist and we'll install which.

sudo yum install gcc

After installing gcc, we execute make command again

make

Continue to report errors:

make[1]: Entering directory `/home/mtianyan/redis-4.0.7/src'
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
 #include <jemalloc/jemalloc.h>
                               ^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/home/mtianyan/redis-4.0.7/src'
make: *** [all] Error 2

It's a reminder that we don't exist.

make MALLOC=libc

We attach the specified parameters.

Once the make compilation is complete, we can sudo make insatll, and then we have the installation completed.

command brief introduction
redis server redis server-side startup program
redis-cli redis client operating tools can also be operated using telnet based on its plain text protocol
redis-benchmark redis performance testing tool
redis-check-aof Data Repair Tool
redis-check-dump Check export tools

Start. / redis-server: Don't forget to enter the src directory first.

mark

Port 6379 PID 2221

ps -ef|grep redis
netstat -anpl |grep redis

cd src: Run redis-cli

mark
mark

set delete get

Use telnet to connect.

telnet 192.168.0.7 6379
mark

The error cannot be connected, and the command in the error message is run on the cli console.

mark

set get delete operation

Store a list in redis

LPUSH mtianyan redis
LPUSH mtianyan mysql
LPUSH mtianyan emmmm
LRANGE mtianyan 0 10
mark

There are two steps in source code compilation.

Posted by rage2021 on Mon, 17 Dec 2018 09:18:04 -0800