Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic knowledge points of Redis database?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the basic knowledge points of Redis database?" interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the basic knowledge points of Redis database?"

1. What is Redis?

Non-relational database: NoMsql

The mainstream NoSQL databases are Redis, MongBD, Hbase, Memcached and so on.

Redis, translated as "remote Dictionary Service", is a key-based NoSQL database based on memory implementation, often referred to as a data structure server, because it can store a variety of data types, such as string (string), hash (hash), list (list), set (collection) and sorted set (ordered collection).

Redis complies with the BSD protocol and is free and open source. The latest version is 6.20, and the commonly used versions include 3.0,4.0,5.0.

Since the birth of Redis, it has been widely praised for its ultra-high performance, perfect documentation and concise and easy-to-understand source code. Many large Internet companies at home and abroad have used Redis, such as Tencent, Ali, Twitter, Github and so on.

2. Characteristics of Redis:

Redis can not only save data completely in memory, but also achieve persistent storage of data through disk; Redis supports a variety of data types, including string, list, set, zset, hash and other data types, so it is also known as "data structure server"; Redis supports master-slave synchronization, that is, master-slave master-slave replication mode. Data can be synchronized from master server to any number of slave servers, which effectively ensures the security of data; Redis supports a variety of programming languages, including C, C++, Python, Java, PHP, Ruby, Lua and so on.

Until Redis version 6. 0, users' requests were handled in a single-thread manner.

Why is single thread so fast?

Pure memory

Non-blocking

Avoid thread switching and race consumption

Redis does not provide the operation to create a new database because it comes with 16 (0-15) databases (0 libraries are used by default). In the same library, key is the only one that exists and cannot be duplicated. It is like a "key" that can only open a "lock". The essence of key-value storage is to use key to identify value. When you want to retrieve value, you must use the key corresponding to value to find it.

3. Redis vs. memcached

Memcachedredis type key-valuekey-value expiration policy supports data type single data type five big data type persistence does not support master-slave replication does not support virtual memory does not support 4. Redis typical application scenarios:

Session sharing: commonly seen in Tomcat in web clusters or session sharing of multiple web servers in PHP

Cache: data query, e-commerce website commodity information, news content

Counter: visit ranking, merchandise views and other numerical statistics related to the number of times

Weibo / Wechat social occasions: common friends, number of fans, followers, likes, comments, etc.

Message queue: ELK's log cache, subscription and publishing system for some businesses.

Geographical location: based on GEO (Geographic Information Positioning), to achieve shake, nearby people, takeout and other functions

5. Download and install Redis:

Note: unofficial Redis versions can be downloaded and installed on Windows systems, but their performance is much lower than that of Linux systems.

Here we deploy and install Redis version 5.0.7 on centos7:

Download address of rpm source package: wget https://download.redis.io/releases/redis-5.0.7.tar.gz

# disable firewall and SELinuxsystemctl stop firewalldsetenforce installation dependency package yum install-y gcc gcc-c++ make# download package cd / optwget https://download.redis.io/releases/redis-5.0.7.tar.gztar zxf redis-5.0.7.tar.gz cd redis-5.0.7/makemake PREFIX=/usr/local/redis install

# since the Makefile file is provided directly in the Redis source code package, after decompressing the package, you do not need to execute the. / configure configuration first, you can directly execute the make and make install commands to install.

Cd / opt/redis-5.0.7/utils./install_server.sh# . Enter until this step # need to manually modify to the executable file path, note that you need to enter Please select the redis executable path [] / usr/local/redis/bin/redis-server correctly at one time

Putting the executable program file of redis into the directory of path environment variable is easy for the system to identify.

Ln-s / usr/local/redis/bin/* / usr/local/bin/# when the install_server.sh script is finished, the Redis service is started. The default listening port is 6379ss-natp | grep 6379

Redis service control: / etc/init.d/redis_6379 stop # stop / etc/init.d/redis_6379 start # start / etc/init.d/redis_6379 restart # restart / etc/init.d/redis_6379 status # View status # modify configuration / etc/redis/6379.conf parameter # 70 line, add The listening host address vim / etc/redis/6379.confbind 127.0.0.1 192.168.111.10 needs to restart Redis/etc/init.d/redis_6379 restart after modifying the configuration

Redis command tool: redis-server tool for starting Redis redis-benchmark is used to test the running efficiency of Redis on this machine redis-check-aof repair AoF persistence file redis-check-rdb repair RDB persistence file redis-cliRedis command line tool redis-benchmark test tool

Syntax: redis-benchmark [option] [option value]

-h: specify the server hostname.

-P: specify the server port.

-s: specify server socket

-c: specify the number of concurrent connections.

-n: specify the number of requests.

-d: specifies the data size of the SET/ get value in bytes.

-k: 1=keep alive 0=reconnect.

-r: SET/GET/INCR uses random key and SADD uses random values.

-P: transmit the request through the pipeline.

-Q: forcibly exits redis. Only the query/ secvalue is displayed.

-csv: output in CSV format.

-l: generate a loop to permanently execute the test.

-t: only run a comma-separated list of test commands.

-I: Idle mode. Open only N idle connections and wait.

# send 100 concurrent connections and 100000 requests to a Redis server with an IP address of 192.168.111.100 and port 6379 to test performance redis-benchmark-h 192.168.111.100-P 6379-c 100-n 10000bytes test the performance of packets with an access size of 100byte redis-benchmark-h 192.168.111.100-P 6379-Q-d 10bytes test the performance of the Redis service on this machine when performing set and lpush operations redis-benchmark-t set Lpush-n 100000-qredis-cli command line tool:-redis-cli command line tool-redis-cli-h 192.168.111.100-p 6379-a 123123-n database serial number (0-15)-h: specify remote host address-p: specify redis service port-a: specify password, database password can be omitted-an option-n: specify database serial number, default is serial number 0 Redis has 16 libraries (0-15). If you do not add any selection representation, use 127.0.1 6379 to connect to the local redis database.

At this point, I believe that you have a deeper understanding of the "Redis database entry knowledge points", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report