Centos7 安装redis及其入门使用
#!/bin/bash
wget -c http://download.redis.io/releases/redis-3.2.9.tar.gz #下载源码
tar -xvf redis-3.2..tar.gz #解压
cd redis-3.2./
make #编译,如果报zmalloc.h::: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录之类的错误,执行make MALLOC=libc
make install #安装
./utils/install_server.sh #安装并启动服务,直接回车默认即可
/etc/init.d/redis_6379 start #启动redis
进入redis,我们该如何使用呢
#字符串类型
[root@localhost src]# redis-cli -h 127.0.0.1
127.0.0.1:> set bp #设置字符串类型,变量bp的值为123
OK
127.0.0.1:> get bp #获取bp的值
""
127.0.0.1:> type bp #查看bp的类型
string
127.0.0.1:> append bp linux #在bp末尾添加linux
(integer)
127.0.0.1:> get bp #添加成功
"123linux"
127.0.0.1:> strlen bp #字符串长度
(integer)
127.0.0.1:> del bp #删除bp变量
(integer)
127.0.0.1:> get bp #删除成功
(nil)
127.0.0.1:> mset linux a kali b centos c #同时设置多个值,mset后面是两个两个一对
OK
127.0.0.1:> mget linux kali centos #同时获取多个值
) "a"
) "b"
) "c"
#散列类型
127.0.0.1:> hset id name passwd #散列名称为id,后面可以跟多对值
(integer)
127.0.0.1:> hset id sex color
(integer)
127.0.0.1:> hset id city good
(integer)
127.0.0.1:> hget id name #获取散列名称为id里的name对应的值
"passwd"
127.0.0.1:> hget id sex
"color"
127.0.0.1:> hgetall id #获取散列id的全部值
) "name"
) "passwd"
) "sex"
) "color"
) "city"
) "good"
127.0.0.1:> hmset ood name linux kali contos debian #一次性设置ood散列的值
OK
127.0.0.1:> hgetall ood
) "name"
) "linux"
) "kali"
) "contos"
) "debian"
) ""
127.0.0.1:> hget ood name
"linux"
127.0.0.1:> hmget ood name
) "linux"
127.0.0.1:> hdel ood name #删除ood里的name
(integer)
127.0.0.1:> hgetall ood
) "kali"
) "contos"
) "debian"
) ""
127.0.0.1:> hexists ood kali #散列ood是否存在kali,存在
(integer)
127.0.0.1:> hexists ood no #散列ood是否存在no,不存在
(integer)
#列表类型
127.0.0.1:> lpush test #列表名为test,从左边加入1
(integer)
127.0.0.1:> lpush test
(integer)
127.0.0.1:> rpush test - #列表名为test,从右边加入-
(integer)
127.0.0.1:> llen test #列表长度
(integer)
127.0.0.1:> lpop test #左边出去一个数
""
127.0.0.1:> llen test
(integer)
127.0.0.1:> rpop test #右边出去一个数
"-1"
127.0.0.1:> lpop test
""
127.0.0.1:> llen test
(integer)
127.0.0.1:> lpush test
(integer)
127.0.0.1:> lpush test
(integer)
127.0.0.1:> lpush test
(integer)
127.0.0.1:> rpush test
(integer)
127.0.0.1:> rpush test
(integer)
127.0.0.1:> lrange test #列表下标从0开始计算,显示第三个数和第四个数
) ""
) ""
127.0.0.1:> lrange test
) ""
) ""
) ""
) ""
127.0.0.1:> lrem test #左数删除1个3
(integer)
127.0.0.1:> llen test
(integer)
127.0.0.1:> lrange test
) ""
) ""
) ""
) ""
127.0.0.1:> lindex test #获取2的下标
""
127.0.0.1:> ltrim test #test取截取出来的下标0到2对应的值
OK
127.0.0.1:> llen test
(integer)
127.0.0.1:> lrange test
) ""
) ""
) ""
#集合类型
127.0.0.1:> sadd linux a b c d e a b #增加linux集合,集合内容为a b c d e a b
(integer)
127.0.0.1:> sadd kali A F I S
(integer)
127.0.0.1:> srem linux d e #删除linux集合中的d e元素
(integer)
127.0.0.1:> smembers linux #查看linux的元素
) "b"
) "c"
) "a"
127.0.0.1:> sismember linux d #查看d是否是集合linux的元素,否
(integer)
127.0.0.1:> sismember linux a #查看a是否是集合linux的元素,是
(integer)
127.0.0.1:> sadd centos a d e c b
(integer)
127.0.0.1:> smembers linux
) "b"
) "c"
) "a"
127.0.0.1:> smembers centos
) "e"
) "b"
) "c"
) "a"
) "d"
127.0.0.1:> sdiff linux centos #取差集,linux集合被包含在centos里面,所以没有(linux-centos)
(empty list or set)
127.0.0.1:> sinter linux centos #取交集
) "b"
) "c"
) "a"
127.0.0.1:> sdiff centos linux #centos-linux
) "e"
) "d"
127.0.0.1:> sunion linux centos #取并集
) "e"
) "b"
) "c"
) "d"
) "a"
#有序集合
127.0.0.1:> zadd test1 a #增加test1有序集合,分数为10 等级为a
(integer)
127.0.0.1:> zadd test2 b
(integer)
127.0.0.1:> zadd test1 c
(integer)
127.0.0.1:> zrem test1 b #移除test1的等级b的值
(integer)
127.0.0.1:> zscore test1 a #查看test1的等级a的值
""
127.0.0.1:> zrange test1 #查看test1第一个和第二个的值
) "c"
) "a"
127.0.0.1:> zrangebyscore test1 #根据分数查看对应的的等级
) "c"
) "a"
Centos7 安装redis及其入门使用的更多相关文章
- CentOS7 安装Redis Cluster集群
上一篇中已经讲到了如何安装单击版Redis,这一篇我们来说下如何安装Cluster,关于哨兵模式这里我就不写文章安装了,有兴趣的同学可以自己去研究,哨兵模式可以在主从模式下在创建三台机器的哨兵集群监控 ...
- CentOS7安装redis数据库及php-redis扩展
redis 首先把redis安装到服务器中 1.wget http://download.redis.io/redis-stable.tar.gz 下载redis源码 2. tar xvzf redi ...
- [ 搭建Redis本地服务器实践系列一 ] :图解CentOS7安装Redis
上一章 [ 搭建Redis本地服务器实践系列 ] :序言 作为开场白介绍了下为什么要写这个系列,从这个章节我们就开始真正的进入正题,开始搭建我们本地的Redis服务器.那么关于Redis的基本概念,什 ...
- centos7 安装redis服务及phpredis扩展
闲话少说 服务器版本:centos7.6 64位 软件包:https://pan.baidu.com/s/1Gb4iz5mqLqNVWvvZdBiOMQ 提取码: xrhx 一.安装redis 放在/ ...
- vmware安装centos7 安装redis windows7访问redis
1.在windows7中安装vmware 2.在vmware中安装centos7 3.禁用centos7自带的firewalld.service 4.安装iptables防火墙 5.安装Redis 3 ...
- CentOS7 安装Redis和PHP-redis扩展
aemonize yes Redis是一个key-value存储系统,属于我们常说的NoSQL.它遵守BSD协议.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的AP ...
- centos7安装redis
方法一:使用命令安装(前提是已经安装了EPEL). 安装redis: yum -y install redis 启动/停止/重启 Redis 启动服务: 1 systemctl start redis ...
- Centos7 安装redis
1.下载redis安装包 wget http://download.redis.io/releases/redis-4.0.9.tar.gz 2.检查及下载gcc gcc -v yum -y inst ...
- Centos7 安装 Redis
关闭防火墙:systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启 ...
随机推荐
- oracle查看编码以及修改编码
oracle的编码一直是个很重要的问题,以前也总结的写过,但都忘了,今天再在这写一下. 首先查看oracle数据库的编码 SQL>select * from nls_database_param ...
- vue-router-9-HTML5 History 模式
vue-router 默认 hash 模式,页面不会重新加载 用路由的 history 模式,利用 history.pushState API 来完成 URL 跳转而无须重新加载页面. const r ...
- Spring Data JPA中的动态查询 时间日期
功能:Spring Data JPA中的动态查询 实现日期查询 页面对应的dto类private String modifiedDate; //实体类 @LastModifiedDate protec ...
- DevExpress WinForms使用教程:新的CheckEdit样式
[DevExpress WinForms v18.2下载] 在最开始CheckEdit控件有16种样式, 使用CheckStyle属性,开发人员可以选择其中一种样式.随着时间推移,与其他Windows ...
- MyEclipse使用教程:在Web项目中使用Web片段
MyEclipse 在线订购年终抄底促销!火爆开抢>> MyEclipse最新版下载 本教程向用户展示了使用关联的Web项目创建Web片段项目的机制.用户还可以获得要检查的示例项目.在本教 ...
- 循环神经网络-Dropout
dropout 是 regularization 方法,在rnn中使用方法不同于cnn 对于rnn的部分不进行dropout,也就是说从t-1时候的状态传递到t时刻进行计算时,这个中间不进行memor ...
- 51nod1042
给出一段区间a-b,统计这个区间内0-9出现的次数. 比如 10-19,1出现11次(10,11,12,13,14,15,16,17,18,19,其中11包括2个1),其余数字各出现1次. Inp ...
- php优秀框架codeigniter学习系列——CodeIgniter.php概览
CodeIgniter.php是CI框架的核心文件.它在前端控制器index.php之后运行,加载各类基础组件,执行请求.文件执行完成后,这次请求也就结束了.所以,该文只能对CodeIgniter.p ...
- 2019-03-01-day002-基础编码
01 昨日内容回顾 编译型: 一次性编译成二进制. 优点:质型速度快. 确定:开发效率低,不能跨平台. 解释型: 逐行解释,逐行运行. 优点:开发效率高,可以跨平台. 缺点:回字形效率低. pytho ...
- 临时调用call()与apply()方法
当在某个局域范围内要调用构造函数中或者其他局域范围内的方法 此时可以用到临时调用方法call与apply 虽然这两个方法都是起临时调用的功能,但是用法不一样 call(obj,val) obj:对象名 ...