linux缓存工具之redis

1. Redis 简介

Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库。

Redis 与其他 key - value 缓存产品有以下三个特点:

  • Redis支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用。
  • Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
  • Redis支持数据的备份,即master-slave模式的数据备份。

2. Redis 优势

  • 性能极高 – Redis能读的速度是110000次/s,写的速度是81000次/s 。
  • 丰富的数据类型 – Redis支持二进制案例的 Strings, Lists, Hashes, Sets 及 Ordered Sets 数据类型操作。
  • 原子 – Redis的所有操作都是原子性的,意思就是要么成功执行要么失败完全不执行。单个操作是原子性的。多个操作也支持事务,即原子性,通过MULTI和EXEC指令包起来。
  • 丰富的特性 – Redis还支持 publish/subscribe, 通知, key 过期等等特性。

官网文档

3. Redis安装及配置

//下载并解压redis安装包
[root@localhost ~]# wget http://download.redis.io/releases/redis-6.0.6.tar.gz?_ga=2.201306478.1396430506.1597239708-1651673018.1597239708
[root@localhost ~]# tar xf redis-6.0.6.tar.gz 
[root@localhost ~]# ls
anaconda-ks.cfg  redis-6.0.6  redis-6.0.6.tar.gz

//在编译之前请安装好gcc、gcc-c++,然后查看gcc的版本是否过低,我这里的版本就过低了
//这时编译的话,会直接报错的!!如果你的gcc版本也和我这一样,或者更低,就需要升级了!
[root@localhost ~]# yum -y install gcc gcc-c++ tcl
[root@localhost ~]# gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)

//升级gcc
[root@localhost redis-6.0.6]# yum -y install centos-release-scl
............
[root@localhost redis-6.0.6]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
............
[root@localhost redis-6.0.6]# scl enable devtoolset-9 bash
............
//再次查看gcc版本,此时为9.3了,现在就可以编译了!
[root@localhost redis-6.0.6]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-20200408/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)

//编译redis
[root@localhost redis-6.0.6]# make MALLOC=libc
............
Hint: It's a good idea to run 'make test' ;)

make[1]: 离开目录“/root/redis-6.0.6/src”

[root@localhost src]# cp redis-cli redis-server /usr/bin/
[root@localhost ~]# which redis-cli
/usr/bin/redis-cli

[root@localhost ~]# redis-server
............
[root@localhost ~]# ss -anlt
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            :::80                         :::*                  
LISTEN     0      128            :::22                         :::*                  
LISTEN     0      100           ::1:25                         :::*

//进入redis
[root@localhost ~]# redis-cli
127.0.0.1:6379> set a 10    //定义a的值为10
OK
127.0.0.1:6379> get a   //查看a
"10"

//也可以在外面设置
[root@localhost ~]# redis-cli set b 20
OK
[root@localhost ~]# redis-cli get b
"20"

//设置登录密码
[root@localhost redis-6.0.6]# cp redis.conf /etc/
[root@localhost redis-6.0.6]# vim /etc/redis.conf
............
requirepass 123456@abc    //修改密码

//重启服务
[root@localhost ~]# nohup redis-server /etc/redis.conf &
[1] 30509
[root@localhost ~]# nohup: 忽略输入并把输出追加到"nohup.out"
[root@localhost ~]# redis-cli
127.0.0.1:6379> set a 10
(error) NOAUTH Authentication required.  
127.0.0.1:6379> auth 123456@abc
OK
127.0.0.1:6379> get a
"10"

命令大全
在这里插入图片描述

//添加多个元素到集合里
127.0.0.1:6379> SADD ab 10 20 30 40
(integer) 4
//获取集合中元素的数量
127.0.0.1:6379> SCARD ab
(integer) 4
//获取集合中所有的元素
127.0.0.1:6379> SMEMBERS ab
1) "10"
2) "20"
3) "30"
4) "40"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值