当前位置: 首页 > news >正文

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.dtcms.com/a/330705.html

相关文章:

  • 【cmake】编译cpp文件,安装MinGW
  • 《Leetcode》-面试题-hot100-动态规划
  • 《嵌入式 C 语言编码规范个人笔记》参考华为C语言规范标准
  • 标贝科技「十万音色·自然语音数据集」 重构AI语音训练基础设施
  • 机器视觉之图像处理篇
  • OpenCV Python——报错AttributeError: module ‘cv2‘ has no attribute ‘bgsegm‘,解决办法
  • 63w+有小程序注册的企业汇总数据(2024.2)
  • 阿里云TranslateGeneral - 机器翻译SDK-自己封账单文件版本—仙盟创梦IDE
  • CSS中实现一个三角形
  • 哪些对会交由SpringBoot容器管理?
  • Unity中的神经网络遗传算法实战
  • 【数据可视化-89】基孔肯雅热病例数据分析与可视化:Python + pyecharts洞察疫情动态
  • UE小:编辑器模式下「窗口/鼠标不在焦点」时仍保持高帧率
  • Flask中ORM的使用
  • 论郑和下西洋元素融入课件编辑器的意义与影响​
  • docker使用指定的MAC地址启动podman使用指定的MAC地址启动
  • 同创永益 IStorM CNBR云原生业务韧性管理平台 v3.3.0重磅发布:告别备份烦恼,云原生数据保护再升级!
  • 深度学习——03 神经网络(4)-正则化方法价格分类案例
  • MacOS 系统计算机专业好用工具安装
  • Nginx学习笔记(九)—— Nginx Rewrite深度解析
  • C++ STL学习 之 泛型编程
  • Unity Shader unity文档学习笔记(十九):粘土效果,任意网格转化成一个球(顶点动画,曲面着色器)
  • 算法提升之树上问题-(LCA)
  • vue3使用leaflet地图
  • **超融合架构中的发散创新:探索现代编程语言的挑战与机遇**一、引言随着数字化时代的快速发展,超融合架构已成为IT领域的一种重要趋势
  • 【入门级-算法-2、入门算法:枚举法】
  • 代码随想录Day50:图论(图论理论、深度搜索理论、所有可达路径、广度搜索理论)
  • 表单输入绑定详解
  • 给电脑升级内存,自检太慢,以为出错
  • FPS游戏时,你的电脑都在干什么(CS2)