Redis (REmote DIctionary Server) 高性能數據庫

Redis {REmote DIctionary Server} 高性能數據庫

  • 1. What is Redis?
    • 1.1. 基于內存的數據存儲
  • 2. Install Redis on Linux
  • 3. Starting and stopping Redis in the background
    • 3.1. `systemctl`
    • 3.2. `service `
  • 4. Connect to Redis
  • 5. 退出 Redis 的命令行界面 (redis-cli)
  • 6. redis-server 統計信息
  • References

Redis (REmote DIctionary Server)
https://redis.io/

1. What is Redis?

Redis (REmote DIctionary Server) is an open source, in-memory, NoSQL key/value store that is used primarily as an application cache or quick-response database.
Redis (REmote DIctionary Server) 是一個開源的內存數據庫,遵守 BSD 協議,它提供了一個高性能的鍵值 (key-value) 存儲系統,常用于緩存、消息隊列、會話存儲等應用場景。Redis 是一個開源的使用 ANSI C 語言編寫、支持網絡、可基于內存亦可持久化的日志型、Key-Value 數據庫,并提供多種語言的 API。

Redis stores data in memory, rather than on a disk or solid-state drive (SSD), which helps deliver unparalleled speed, reliability, and performance.
Redis 將數據存儲在內存中,而不是磁盤或固態硬盤 (SSD) 上,這有助于提供無與倫比的速度、可靠性和性能。

Redis 將數據存儲在內存中,以提供快速的讀寫訪問速度,并且能夠通過異步的方式將數據持久化到磁盤上。

1.1. 基于內存的數據存儲

Redis 是一個內存中的數據結構存儲系統,意味著它使用計算機的主內存 (RAM) 來存儲所有的數據。這種內存優先的設計使得 Redis 能夠提供極高的性能,因為內存的數據訪問速度遠遠超過了傳統硬盤存儲。

由于存儲在內存中,Redis 能夠以微秒級別的延遲對數據進行讀寫操作,這對于需要快速響應的應用來說至關重要,如緩存系統、實時分析平臺和高頻交易系統等。然而,內存資源相對有限且價格較高,因此 Redis 也提供了數據驅動的逐出策略和精細的內存管理功能,確保有效利用可用內存。

2. Install Redis on Linux

https://redis.io/docs/latest/operate/oss_and_stack/install/archive/install-redis/

sudo apt update
sudo apt install redis-server

Note there are redis-server and redis packages in the Ubuntu repository. Both will install the same software, so you can use either and have the same outcome.

(base) yongqiang@yongqiang:~$ sudo apt update
(base) yongqiang@yongqiang:~$ sudo apt install redis-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:libfwupdplugin1 libxmlb1
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:libhiredis0.14 libjemalloc2 liblua5.1-0 lua-bitop lua-cjson redis-tools
Suggested packages:ruby-redis
The following NEW packages will be installed:libhiredis0.14 libjemalloc2 liblua5.1-0 lua-bitop lua-cjson redis-server redis-tools
0 upgraded, 7 newly installed, 0 to remove and 327 not upgraded.
Need to get 915 kB of archives.
After this operation, 4077 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...

3. Starting and stopping Redis in the background

3.1. systemctl

You can start the Redis server as a background process using the systemctl command. This only applies to Ubuntu/Debian when installed using apt, and Red Hat/Rocky when installed using yum.

sudo systemctl start <redis-service-name> # redis or redis-server depending on platform

To stop the server, use:

sudo systemctl stop <redis-service-name> # redis or redis-server depending on platform

適用于 Linux 的 Windows 子系統 (WSL) 默認不啟用 systemd,因此 sudo systemctl start redis-server 可能無效。

3.2. service

?通過服務命令啟動,并查看服務狀態。

(base) yongqiang@yongqiang:~$ sudo service redis-server start
Starting redis-server: redis-server.
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ sudo service redis-server status* redis-server is running
(base) yongqiang@yongqiang:~$

?通過服務命令關閉,并查看服務狀態。

(base) yongqiang@yongqiang:~$ sudo service redis-server stop
Stopping redis-server: redis-server.
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ sudo service redis-server status* redis-server is not running
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ sudo service redis-server status* redis-server is running
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ ps aux | grep redis
redis      882  0.1  0.1  60924  6272 ?        Ssl  21:58   0:01 /usr/bin/redis-server 127.0.0.1:6379
yongqia+   897  0.0  0.0   8172  2304 pts/0    S+   22:08   0:00 grep --color=auto redis
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ redis-cli --version
redis-cli 5.0.7
(base) yongqiang@yongqiang:~$ sudo service redis-server stop
Stopping redis-server: redis-server.
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ ps aux | grep redis
yongqia+   910  0.0  0.0   8172  2432 pts/0    S+   22:11   0:00 grep --color=auto redis
(base) yongqiang@yongqiang:~$

4. Connect to Redis

Check the Redis command-line client version by entering the following to ensure it is configured properly:

redis-cli --version
(base) yongqiang@yongqiang:~$ redis-cli --version
redis-cli 5.0.7
(base) yongqiang@yongqiang:~$

Once Redis is running, you can test it by running redis-cli:

redis-cli

Test the connection with the ping command:

127.0.0.1:6379> ping
PONG
(base) yongqiang@yongqiang:~$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>

5. 退出 Redis 的命令行界面 (redis-cli)

使用 exit 命令:

(base) yongqiang@yongqiang:~$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit
(base) yongqiang@yongqiang:~$

使用 quit 命令:

(base) yongqiang@yongqiang:~$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> quit
(base) yongqiang@yongqiang:~$

6. redis-server 統計信息

(base) yongqiang@yongqiang:~$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> INFO
# Server
redis_version:5.0.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:66bd629f924ac924
redis_mode:standalone
os:Linux 6.6.87.2-microsoft-standard-WSL2 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:9.3.0
process_id:939
run_id:036b682fce7ef9126ec09d7b6210f7df004ff9f0
tcp_port:6379
uptime_in_seconds:57
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:10352588
executable:/usr/bin/redis-server
config_file:/etc/redis/redis.conf# Clients
connected_clients:1
client_recent_max_input_buffer:2
client_recent_max_output_buffer:0
blocked_clients:0# Memory
used_memory:859360
used_memory_human:839.22K
used_memory_rss:5902336
used_memory_rss_human:5.63M
used_memory_peak:859360
used_memory_peak_human:839.22K
used_memory_peak_perc:100.12%
used_memory_overhead:845926
used_memory_startup:796232
used_memory_dataset:13434
used_memory_dataset_perc:21.28%
allocator_allocated:1575864
allocator_active:1880064
allocator_resident:10461184
total_system_memory:4029890560
total_system_memory_human:3.75G
used_memory_lua:41984
used_memory_lua_human:41.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.19
allocator_frag_bytes:304200
allocator_rss_ratio:5.56
allocator_rss_bytes:8581120
rss_overhead_ratio:0.56
rss_overhead_bytes:-4558848
mem_fragmentation_ratio:7.22
mem_fragmentation_bytes:5084984
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:49694
mem_aof_buffer:0
mem_allocator:jemalloc-5.2.1
active_defrag_running:0
lazyfree_pending_objects:0# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1755182995
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0# Stats
total_connections_received:1
total_commands_processed:2
instantaneous_ops_per_sec:0
total_net_input_bytes:45
total_net_output_bytes:11475
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
expired_stale_perc:0.00
expired_time_cap_reached_count:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0# Replication
role:master
connected_slaves:0
master_replid:23df661e5962e2a8c907cb36e19637d3d74662a2
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0# CPU
used_cpu_sys:0.073876
used_cpu_user:0.052958
used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000# Cluster
cluster_enabled:0# Keyspace
127.0.0.1:6379> exit
(base) yongqiang@yongqiang:~$

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/
[2] What is Redis? https://www.ibm.com/think/topics/redis

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/918780.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/918780.shtml
英文地址,請注明出處:http://en.pswp.cn/news/918780.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

MySQL中的DML(二)

DML(Data Manipulation Language) : 數據庫操作語言&#xff0c;對數據庫中表的數據進行增刪改操作。 創建student表&#xff1a; CREATE DATABASE test; use test; CREATE TABLE student (id int,name varchar(255),address varchar(255),city varchar(255) );INSERT INTO stu…

linux 主機驅動(SPI)與外設驅動分離的設計思想

一、 主機驅動與外設驅動分離Linux中的SPI、I2c、USB等子系統都利用了典型的把主機驅動和外設驅動分離的想法&#xff0c;讓主機端負責產生總線上的傳輸波形&#xff0c;而外設端只是通過標準的API來讓主機端以適當的波形訪問自身。因此這里涉及了4個軟件模塊&#xff1…

如何生成.patch?

文章目錄 ??方法 1:使用 `git format-patch`(推薦)? ??步驟?? ?方法 2:使用 `diff`命令(適用于非 Git 項目)? ??方法 3:使用 `git diff`(生成未提交的變更)? ?方法 4:使用 `quilt`(適用于大量補丁管理) ?如何提交補丁給上游項目?? ?總結?? 在 L…

【計算機網絡 | 第6篇】計算機體系結構與參考模型

文章目錄計算機體系結構與參考模型分層思想&#x1f342;常見的3種模型&#xff08;網絡體系結構&#xff09;&#x1f426;?&#x1f525;TCP/IP體系結構各層包含的主要協議&#x1f95d;每層所解決的主要問題&#x1f914;層次間的交互規則&#x1f95d;實體與對等實體協議服…

Autoware Universe 感知模塊詳解 | 第一節 感性認識多源傳感器標定

傳感器與感知模塊 在基于規則的自動駕駛系統中&#xff0c;感知模塊&#xff0c;承擔著理解車體周圍環境信息的重要職責。它通過融合多種傳感器數據&#xff0c;與定位模塊共同為規劃與控制模塊提供準確、系統化的輸入信息。正如人可以通過眼睛觀察周圍的環境&#xff08;盲人也…

docker搭建java運行環境(java或者springboot)

目錄1. 創建測試代碼2. 編譯打包3. 代碼環境運行使用普通運行方式使用docker掛載項目&#xff08;長期運行&#xff09;1. 創建 Dockerfile2. 構建并后臺運行使用docker swram實現零停機更新&#xff08;推薦&#xff09;1. 初始化swarm2. 創建 Dockerfile3. 使用Dockerfile 構…

哈希表特性與unordered_map/unordered_set實現分析

目錄 一、哈希表核心特性總結 1.開放地址法 2.鏈地址法 二、unordered_map/unordered_set實現要點分析 1. 哈希表核心實現(HashTable2.h) (1) 哈希函數處理 (2) 鏈地址法實現 (3) 迭代器設計 (4) hashtable設計 2. unordered_map實現要點 3. unordered_map實現要點 一…

生產環境sudo配置詳細指南

目錄 1. 語法格式 2. 配置示例 3. 使用 /etc/sudoers.d/ 目錄管理&#xff08;推薦&#xff09; 4. 基礎配置&#xff1a;用戶權限管理 4.1 ??添加用戶到sudo組 ??4.2 驗證用戶組信息 5. sudo日志配置 5.1 修改sudoers配置文件 5.2 創建日志目錄與權限設置 6. Su…

CSS動態視口單位:徹底解決移動端適配頑疾,告別布局跳動

你是否曾被這些問題困擾&#xff1a; 移動端頁面滾動時&#xff0c;地址欄收縮導致頁面高度突變&#xff0c;元素錯位&#xff1f;100vh在移動設備上實際高度超出可視區域&#xff1f;全屏彈窗底部總被瀏覽器UI遮擋&#xff1f; 這些痛點背后都是傳統視口單位的局限——無法響應…

【P27 4-8】OpenCV Python——Mat類、深拷貝(clone、copyTo、copy)、淺拷貝,原理講解與示例代碼

P27 4-8 1 Mat結構體2 深拷貝VS淺拷貝3 代碼示例1 Mat結構體 2 深拷貝VS淺拷貝 只拷貝了頭部&#xff0c;header&#xff0c;&#xff0c;但是data部分是共用的&#xff0c;速度非常快&#xff1b; 缺點&#xff0c;任意一個修改&#xff0c;另一個data跟著變&#xff0c;這就是…

容器運行時支持GPU,并使用1panel安裝ollama

前言 安裝Docker請看之前博文&#xff1a;Docker實戰中1panel方式安裝Docker。 安裝 NVIDIA 容器工具包 https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html 安裝 先決條件 閱讀有關平臺支持的部分。為您的 Linux 發行版安裝…

高并發內存池 性能瓶頸分析與基數樹優化(9)

文章目錄前言一、性能瓶頸分析操作步驟及其環境配置分析性能瓶頸二、基數樹優化單層基數樹二層基數樹三層基數樹三、使用基數樹來優化代碼總結前言 到了最后一篇嘍&#xff0c;嘻嘻&#xff01; ??終于是要告一段落了&#xff0c;接下來我們將學什么呢&#xff0c;再說吧&…

C#面試題及詳細答案120道(01-10)-- 基礎語法與數據類型

《前后端面試題》專欄集合了前后端各個知識模塊的面試題&#xff0c;包括html&#xff0c;javascript&#xff0c;css&#xff0c;vue&#xff0c;react&#xff0c;java&#xff0c;Openlayers&#xff0c;leaflet&#xff0c;cesium&#xff0c;mapboxGL&#xff0c;threejs&…

機器翻譯:回譯與低資源優化詳解

文章目錄一、機器翻譯的瓶頸二、回譯&#xff08;Back-Translation&#xff09;2.1 什么是回譯&#xff1f;2.2 為什么回譯有效&#xff1f;2.3 回譯的缺點與挑戰三、低資源優化詳解3.1 數據層面策略3.2 模型層面策略3.3 架構層面策略四、回譯與低資源優化對比4.1 回譯與低資源…

leetcode-python-344反轉字符串

題目&#xff1a; 編寫一個函數&#xff0c;其作用是將輸入的字符串反轉過來。輸入字符串以字符數組 s 的形式給出。 不要給另外的數組分配額外的空間&#xff0c;你必須原地修改輸入數組、使用 O(1) 的額外空間解決這一問題。 示例 1&#xff1a; 輸入&#xff1a;s [“h”,“…

【Python】新手入門:什么是python字符編碼?python標識符?什么是pyhon保留字?

?? 個人主頁:(時光煮雨) ?? 高質量專欄:vulnhub靶機滲透測試 ?? 希望得到您的訂閱和支持~ ?? 創作高質量博文(平均質量分95+),分享更多關于網絡安全、Python領域的優質內容!(希望得到您的關注~) ??文章目錄?? 前言 ??一、編碼 ??二、標識符 ??三、Py…

為什么要使用消息隊列呢?

消息隊列&#xff08;Message Queue&#xff0c;MQ&#xff09;在分布式系統中扮演著 ?異步通信樞紐? 的角色&#xff0c;其核心價值在于解決系統間的解耦、流量削峰、異步處理等關鍵問題。以下是它的核心價值及典型應用場景&#xff1a;?? 一、核心價值&#xff1a;解決什…

ROS機器人云實踐案例博客建議和范文-AI版本

海報圖AI圖1AI圖2zhangrelay的博客以技術深度、跨界思考和社會洞察為特色&#xff0c;內容兼具實用性與前瞻性&#xff0c;但部分觀點存在爭議&#xff0c;需結合具體主題辯證看待。以下從內容特色、技術深度、社會洞察、爭議點四個維度展開分析&#xff1a;一、內容特色&#…

UE小:編輯器模式下「窗口/鼠標不在焦點」時仍保持高幀率

要在UE編輯器模式下「窗口/鼠標不在焦點」時仍保持高幀率&#xff0c;可按下面做法&#xff1a; 關閉編輯器的后臺降頻選項&#xff1a;在 Edit -> Editor Preferences -> General -> Performance 中取消勾選 “Use Less CPU when in Background”。

VS2022 + Qt 5.15.2+Occ開發環境搭建流程

Visual Studio 2022 Qt 5.15.2 圖形處理開發環境搭建流程 1. 安裝 Visual Studio 2022 下載安裝程序&#xff1a;Visual Studio 官網選擇工作負載&#xff1a; ?? “使用C的桌面開發”?? “通用Windows平臺開發”&#xff08;可選&#xff09; 安裝組件&#xff1a; ??…