当前位置:网站首页>Redis:Redis的简单使用
Redis:Redis的简单使用
2022-07-03 01:25:00 【dengfengling999】
目录:
(1)Redis的细节使用
启动、关闭、启动客户端
(2)Redis的基本知识1
测试性能、查看转态、服务器的统计信息
(3)Redis基本知识2
数据库实例
(4)Redis基本知识3
查看key、清空库
(1)Redis的细节使用

启动方式:
(1)前台启动:redis-server:启动完之后,会占整个控制台会占命令行终端,不能做别的事情,命令行一旦关了,它的服务也就关了,实际开发过程中很少使用这种方式
(2)后台启动:redis-server & 控制台不会占整个命令行终端,即是命令行关掉了,后台服务该怎么启动就怎么启动
(3)启动服务时,指定配置文件:redis-server redis-conf & 如果修改了配置文件,需要在启动时,指定配置文件
关闭方式:
- 通过kill命令,不建议这种方式,容易数据丢失
ps -ef | grep redis查看pid
kill -9 pid
2. 通过redis-cli 命令关闭
redis-cli shutdown
启动:redis-server &

进行查看:ps -ef|grep redis:发现有6379这个redis

关闭Redis:redis-cli shutdown

进行查看:ps -ef|grep redis:没有了端口号6379的redis

Redis服务端装好之后,不能直接使用,你要想使用,必须通过客户端去连他,通过客户端输入一些命令通过网络传给他,服务端来执行这些命令,来对这些数据进行完成增删改查,并把增删改查的结果返回给客户端
例如:MySql:
1、mysql命令连接数据库格式:
mysql -h 主机地址 -P 端口号 -u用户名 -p用户密码2、MySQL连接本地数据库,用户名为“root”,密码“123”
mysql -h localhost -u root -p123mysql基于命令行的比较麻烦,我们嫌不方便,于是出现了可视化工具Navica客户端第三方开发的客户端,这种客户端也可以连接Mysql服务端,向后台Mysql发送一些命令,服务端可以把结果返回给客户端,这种可视化界面给我们带来极大方便。
Redis客户端
Redis客户端是一个程序,通过网络连接到Redis服务器,从而实现跟 Redis服务器的交互。
Redis客户端发送命令,同时显示Redis服务器的处理结果。
redis-cli(Redis Command Line Interface)是Redis自带的基于命令行的Redis客户端,用于与服务端交互,我们可以使用该客户端来执行redis的各种命令。
启动Redis客户端:
1)直接连接redis (默认ip127.0.0.1,端口6379):redis-cli
在任意目录执行 redis-cli
此命令是连接本机127.0.0.1 ,端口6379的redis

可以指定端口号:
2)指定IP和端口连接redis:redis-cli –h 127.0.0.1 -p 6379
-h redis主机IP(可以指定任意的redis服务器)
-p端口号(不同的端口表示不同的redis应用)
在任意目录下执行 redis-cli -h 127.0.0.1 -p 6379

- 退出Redis客户端:exit或者quit指令。

(2)Redis的基本知识1

- 测试Redis性能


2.Redis沟通命令,查看状态
redis >ping 返回PONG
解释:输入ping,redis给我们返回PONG,表示redis服务运行正常

3.查看redis服务器的统计信息:info
语法:info [section]
作用:以一种易于解释且易于阅读的格式,返回关于 Redis 服务器的各种信息和统计数值。section 用来返回指定部分的统计信息。 section的值:server , clients ,memory等等。不加section 返回全部统计信息
返回值:指定section的统计信息或全部信息
例1:统计server的信息

例2:统计全部信息

(3)Redis基本知识2

MySQL中的数据库实例,可以根据开发人员自己创建,自己可以创建,自己可以命名,自己可以维护
Redis的数据库实例,只能由Redis自己创建去维护,程序员想用的话,不能自己创建只用用创建号好的
- redis默认使用16个库
Redis默认使用16个库,从0到15。 对数据库个数的修改,在redis.conf文件中databases 16,理论上可以配置无限多个。

Redis的库和关系型数据库中的数据库实例类似,但又有一些不同,比如redis中各个库不能自定义命名,只能用序号表示,redis中各个库不是完全独立的,使用时最好一个应用使用一个redis实例,不建议一个redis实例中保存多个应用的数据。Redis实例本身所占存储空间其实是非常小的,因此不会造成存储空间的浪费。
例如:用set 命令存一个数据,默认情况下客户端连的是0号实例

2.切换库命令:select db
默认使用第0个,如果要使用其他数据库,命令是 select index

(4)Redis的基本知识3
1.查看当前数据库中key的数目:dbsize
语法:dbsize
作用:返回当前数据库的 key 的数量。
返回值:数字,key的数量

刚才存放一条数据,为什么是2呢?
:0号比较特殊,里面默认放了几条数据了

2.查看当前数据库中有哪些key:keys *


3.清空当前库:flushdb

4.清空所有数据库:flushall 清空所有的数据库实例

这也体现出redis中的库并不是完全无关的。

4.config get * 获得redis的所有配置值
语法:config get parameter
作用:获取运行中Redis服务器的配置参数, 获取全部配置可以使用*。参数信息来自redis.conf 文件的内容。
例1:获取数据库个数 config get databases

例2:获取端口号config get port

边栏推荐
- Openresty cache
- Learn BeanShell before you dare to say you know JMeter
- 函数的定义和调用、this、严格模式、高阶函数、闭包、递归
- 网络安全-钓鱼
- PS去除水印详解
- ByteDance data Lake integration practice based on Hudi
- Why is it not recommended to use BeanUtils in production?
- Huakaiyun (Zhiyin) | virtual host: what is a virtual host
- Analysis, use and extension of open source API gateway apisex
- [error record] an error is reported in the fluent interface (no mediaquery widget ancestor found. | scaffold widgets require a mediaquery)
猜你喜欢
![[data mining] task 3: decision tree classification](/img/9a/1cb2a8a90f16e7bfa9b48e516a966c.png)
[data mining] task 3: decision tree classification

Processing of tree structure data

Query product cases - page rendering data

Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day

【Camera专题】OTP数据如何保存在自定义节点中

【数据挖掘】任务1:距离计算

Main features of transport layer TCP and TCP connection

Why is it not recommended to use BeanUtils in production?

In the face of difficult SQL requirements, HQL is not afraid

Smart management of Green Cities: Digital twin underground integrated pipe gallery platform
随机推荐
Steps to obtain SSL certificate private key private key file
Reprint some Qt development experience written by great Xia 6.5
[fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)
[untitled]
转载收录6.5大侠写的部分Qt开发经验
openresty 缓存
串口抓包/截断工具的安装及使用详解
网络安全-浅谈安全威胁
Common English Vocabulary
【Camera专题】手把手撸一份驱动 到 点亮Camera
Smart management of Green Cities: Digital twin underground integrated pipe gallery platform
并发编程的三大核心问题 -《深入理解高并发编程》
网络安全-ACL访问控制列表
Vant 实现简单的登录注册模块以及个人用户中心
Everything file search tool
When the epidemic comes, how to manage the team as a leader| Community essay solicitation
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance o
SSL flood attack of DDoS attack
Network security - dynamic routing protocol rip
STM32 - introduction of external interrupts exti and NVIC