Ubuntu 18.04 Redis database installation

What is a redis database?

Redis is a nosql database. Its data is stored in memory. At the same time, redis can synchronize the memory data to disk regularly, that is, it can persist the data, and it supports more data structures (string, list list [ Queue and stack], set[set], sorted set[ordered set], hash(hash table)).
Applicable scene:

  • Login session storage: stored in redis, compared with memcached, data will not be lost.
  • Ranking version/counter: For example, some show-type projects often have some top anchor rankings. There are also some techniques for article reading, or the number of likes on Sina Weibo.
  • As a message queue: For example, celery uses redis as a middleman.
  • Current number of online people: It is still the previous example of the show, it will show the current number of online people in the system.
  • Some commonly used data caches: For example, in our BBS forum, the section does not change frequently, but every time you visit the home page, you have to get it from mysql, which can be cached in redis instead of requesting the database every time.
  • Friendship: Weibo's friend relationship is implemented using redis.
  • Publish and subscribe functions: can be used as chat software.

Install command

sudo apt install redis-server

View redis server system process

ps -agx|grep redis

View redis service status

sudo systemctl status redis

Access redis through the command line client

redis-cli

Start, stop and restart redis service commands

sudo systemctl start redis-server
sudo systemctl stop redis-server
sudo systemctl restart redis-server

The default configuration file of redis is located in /etc/redis/redis.conf. By default, the server listens for connections from all available interfaces on the server.

Redis commonly used commands

Redis-server /path/redis.conf Start Redis with a specific configuration file
Redis-cli Open the Redis prompt
APPEND key value Append a value to the key
BITCOUNT key [start end] Set the bit in the string
SET key value in the key Set a value in
EXPIRE key 120 to make the key expire within 120 seconds.
INCR key Increase the value in the key
KEYS pattern Find all keys that match a specific pattern

Guess you like

Origin blog.csdn.net/qq_43314560/article/details/114283406