我是靠谱客的博主 飞快衬衫,最近开发中收集的这篇文章主要介绍redisredis安装密码设置redis基础命令,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

redis安装

//安装依赖包
[root@localhost ~]# yum -y install gcc gcc-c++ centos-release-scl 

//升级gcc版本
[root@localhost ~]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils && scl enable devtoolset-9 bash

//安装redis
[root@localhost redis-6.0.6]# make

//把这个移到/usr/bin下就可以直接使用
[root@localhost src]# cp redis-server redis-cli /usr/bin/
[root@localhost src]# redis-server 
24093:C 13 Aug 2020 05:00:31.734 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
24093:C 13 Aug 2020 05:00:31.734 # Redis version=6.0.6, bits=64, commit=00000000, modified=0, pid=24093, just started
24093:C 13 Aug 2020 05:00:31.734 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
24093:M 13 Aug 2020 05:00:31.735 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 24093
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

24093:M 13 Aug 2020 05:00:31.735 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
24093:M 13 Aug 2020 05:00:31.735 # Server initialized
24093:M 13 Aug 2020 05:00:31.735 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
24093:M 13 Aug 2020 05:00:31.735 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
24093:M 13 Aug 2020 05:00:31.735 * Ready to accept connections

//因为这个是服务在前端,使用开启是这样的,也可以放在后台启动


[root@localhost src]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:6379                *:*                  
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128    :::6379               :::*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  


[root@localhost ~]# redis-cli 
127.0.0.1:6379> set a 10
OK
127.0.0.1:6379> quit
[root@localhost ~]# redis-cli get a
"10"


密码设置

//复制配置文件到/etc/
[root@localhost redis-6.0.6]# cp redis.conf /etc/


//编辑配置文件
[root@localhost redis-6.0.6]# vim /etc/redis.conf 

786    requirepass 123   //在786行,密码可以自行输入


//放在后台运行并指定配置文件
[root@localhost ~]# nohup redis-server /etc/redis.conf &
[1] 93816
[root@localhost ~]# nohup: 忽略输入并把输出追加到"nohup.out"


[root@localhost ~]# redis-cli
127.0.0.1:6379> set f 60
(error) NOAUTH Authentication required.   
127.0.0.1:6379> auth 123
OK
127.0.0.1:6379[1]> config set requirepass 123456     //设置密码为123456
OK
127.0.0.1:6379[1]> config get requirepass            //查看密码
1) "requirepass"
2) "123456"
127.0.0.1:6379[1]> quit
[root@localhost ~]# redis-cli 
127.0.0.1:6379> auth 123
(error) WRONGPASS invalid username-password pair
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> 


redis基础命令

命令作用
keys *查看当前数据库中所有key
info查看当前redis状态
monitor监控redis正在执行的命令
select n切换到 n 号数据库 (编号 0 -15)
del删除key
flushdb清空当前数据库
flushall清空所有库中的数据
get取出
set设置
incr自增1
incrby自增自定义
decr自减1
decrby自减自定义
[root@localhost ~]# redis-cli
127.0.0.1:6379> auth 123
OK
127.0.0.1:6379> set a 10       //设置
OK
127.0.0.1:6379> set b 20
OK
127.0.0.1:6379> keys *         //查看当前数据库中所有key
1) "b"
2) "a"
127.0.0.1:6379> del a          //删除
(integer) 1
127.0.0.1:6379> keys *
1) "b"
127.0.0.1:6379> incr a          //自增1
(integer) 1
127.0.0.1:6379> keys *
1) "a"
2) "b"
127.0.0.1:6379> get a
"1"
127.0.0.1:6379> incr b
(integer) 21
127.0.0.1:6379> get b
"21"
127.0.0.1:6379> incrby a 5        //自定义自增
(integer) 6
127.0.0.1:6379> decr b            // 自减1
(integer) 20
127.0.0.1:6379> decrby b 5        //decrby	自减自定义
(integer) 15
127.0.0.1:6379> get b
"15"
127.0.0.1:6379> select 5         //切换到5号数据库
OK
127.0.0.1:6379[5]> select 1
OK
127.0.0.1:6379[1]> set a 2
OK
127.0.0.1:6379[1]> set b 3
OK
127.0.0.1:6379[1]> flushdb       //清空当前库所有数据
OK
127.0.0.1:6379[1]> keys *
(empty array)
127.0.0.1:6379[1]> set b 3
OK
127.0.0.1:6379[1]> select 2
OK
127.0.0.1:6379[2]> set a 2
OK
127.0.0.1:6379[2]> keys *
1) "a"
127.0.0.1:6379[2]> flushall    //清空所有库数据
OK
127.0.0.1:6379[2]> keys *
(empty array)
127.0.0.1:6379[2]> select 1
OK
127.0.0.1:6379[1]> keys *
(empty array)
127.0.0.1:6379[1]> quit        //退出

最后

以上就是飞快衬衫为你收集整理的redisredis安装密码设置redis基础命令的全部内容,希望文章能够帮你解决redisredis安装密码设置redis基础命令所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部