Redis cache server

Time:2021-7-15

website: http://www.redis.cn/
Advance preparation: virtual machine

Introduction to redis

Redis is an open source (BSD license), in memory data structure storage system, which can be used as database, cache, message middleware. It supports multiple types of data structures, such as strings, hashes, lists, sets, sorted sets and range queries, bitmaps, hyperlogs and geospatial index radius queries. Redis has built-in replication, Lua scripting, LRU driven events, transactions and different levels of disk persistence, and provides high availability through redis sentinel and cluster.

Nginx: 30000-50000 / S
Redis: read: 112000 / s write: 86000 / s average 100000 / s throughput: 500000 / S

Redis installation

1. Download redis-5.0.4.tar.gz and upload to
Redis cache server
Redis cache server

2. Unzip redis file
tar -xvf redis-5.0.4.tar.gz
Redis cache server
3. Move / modify files
Redis cache server

4. Install redis (this command takes a long time to execute)
Command 1:make
Command 2:make install
Redis cache server
Redis cache server
Redis cache server

Modify the redis.conf configuration file

1. Modify IP binding
Redis cache server

2. Turn off protection mode
Redis cache server

3. Start background startup
Redis cache server

Redis command

1. Start redis

redis-server redis.conf

Redis cache server

2. Check redis service items

ps -ef|grep redis

Redis cache server

3. Enter the redis client

redis-cli -p 6379
redis-cli

Redis cache server

4. Close redis

//Exit client
ctrl+c

Mode (1)

redis-cli -p 6379 shutdown
//When the default port is 6379, it can be omitted
redis-cli

Mode (2)

ps -ef|grep redis
kill -9 pid

Redis cache server

Common redis commands

String type

Set -- set username admin -- add key value

Get -- get username -- get data according to the key

Strlen -- stalen key -- get the length of the value according to the key

Exists -- exists name -- judge whether the key exists 

Del -- del key -- delete the key in redis

Keys -- keys * -- query all keys in redis
      --Keys n? Me -- use the placeholder to get the data
      --Keys Nam * -- get data beginning with Nam
      
Mset -- Mset key1 value1 key2 Value2 Key3 value3 -- assign multiple key values

Mget -- mget key1 key2 -- get values of multiple keys

Append -- append key value -- append the value of a key

Type -- type key -- check the type of a key

Select -- select 0-15 redis has 16 databases -- switch redis database

Flushdb -- flushdb -- empty single regular customer

Flush -- flush -- empty all databases

Incr -- incr key -- add 1 automatically

Decr -- decr key -- auto minus 1

Incrby -- incrby 10 -- specifies the value to add

Decrby -- decrby 10 -- decrease the specified value

Expire -- expire key 20 -- the key is invalid in 20 seconds

Pexpire -- pexpire key 2000 -- invalid in 2000 milliseconds

TTL -- TTL key - 2 data does not exist - 1 the data never times out -- check the remaining survival time of the key

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]