设为首页 收藏本站
查看: 722|回复: 0

[经验分享] 配置Redis主从服务器(有图)

[复制链接]
YunVN网友  发表于 2018-11-2 10:36:16 |阅读模式
[root@srv5 ~]# redis-cli  127.0.0.1:6379> ping
  PONG
  127.0.0.1:6379> set string1 "hello the word"    //设置字符串变量
  OK
  127.0.0.1:6379> get string1                    //查看字符串变量
  "hello the word"
  127.0.0.1:6379> set string2 "hello" ex 5    //设置字符串变量,并设置过期时间为5秒
  OK
  127.0.0.1:6379> get string2                //查看字符串变量
  "hello"
  127.0.0.1:6379> get string2                //字符串过期后,查看该值为空
  (nil)
  127.0.0.1:6379> get string1
  "hello the word"
  127.0.0.1:6379> set string1 hello nx        //仅当string1不存在时,才执行set指令
  (nil)
  127.0.0.1:6379> set string1 hello xx        //仅当string1存在时,才执行set指令
  OK
  127.0.0.1:6379> get string1                     //查看修改后string1的值
  "hello"
  127.0.0.1:6379> set string1 "hello the world"    //修改string1的值
  OK
  127.0.0.1:6379> get string1
  "hello the world"
  127.0.0.1:6379> setrange string1 6 "Redis"        //从第6个字符开始替换string1的值
  (integer) 15
  127.0.0.1:6379> get string1
  "hello Redisorld"
  127.0.0.1:6379> strlen string1                    //计算string1的长度
  (integer) 15
  127.0.0.1:6379> append string1 xxx                //对string1进行追加操作
  (integer) 18
  127.0.0.1:6379> get string1
  "hello Redisorldxxx"
  127.0.0.1:6379> append string1 " xxx"
  (integer) 22
  127.0.0.1:6379> get string1
  "hello Redisorldxxx xxx"
  127.0.0.1:6379> setbit string2 0 1                //按位设置string2的值,0位为1
  (integer) 0
  127.0.0.1:6379> setbit string2 1 1                //按位设置string2的值,1位为1
  (integer) 0
  127.0.0.1:6379> setbit string2 2 1
  (integer) 0
  127.0.0.1:6379> setbit string2 3 0
  (integer) 0
  127.0.0.1:6379> get string2                    //不可以查看所有的值
  "\xe0"
  127.0.0.1:6379> bitcount string2                 //统计string2中1的个数
  (integer) 3
  127.0.0.1:6379> getbit string2 0                //查看string2第0位的值
  (integer) 1
  127.0.0.1:6379> getbit string2 1                //查看string2第1位的值
  (integer) 1
  127.0.0.1:6379> decr string3                    //递减运算,初始值为0
  (integer) -1
  127.0.0.1:6379> decr string3
  (integer) -2
  127.0.0.1:6379> decr string3
  (integer) -3
  127.0.0.1:6379> decr string3
  (integer) -4
  127.0.0.1:6379> decr string3
  (integer) -5
  127.0.0.1:6379> set string4 10                    //自定义变量初始值为10
  OK
  127.0.0.1:6379> decr string4                    //对自定义变量进行递减运算
  (integer) 9
  127.0.0.1:6379> decr string4
  (integer) 8
  127.0.0.1:6379> decr string4
  (integer) 7
  127.0.0.1:6379> decrby string4 2                //对变量进行递减2运算
  (integer) 5
  127.0.0.1:6379> decrby string4 2
  (integer) 3
  127.0.0.1:6379> get string4
  "3"
  127.0.0.1:6379> set string5 "hello the world"        //设置字符串变量
  OK
  127.0.0.1:6379> getrange string5 0 4            //查看字串的第0至第4位
  "hello"
  127.0.0.1:6379> getrange string5 -3 -1            //查看字串的倒数第3位至倒数第1位
  "rld"
  127.0.0.1:6379> incr page                        //对变量进行递增运算,初始值为0
  (integer) 1
  127.0.0.1:6379> incr page
  (integer) 2
  127.0.0.1:6379> incr page
  (integer) 3
  127.0.0.1:6379> incr page
  (integer) 4
  127.0.0.1:6379> set string6 10                    //设置字符串变量为10
  OK
  127.0.0.1:6379> incr string6                    //对变量进行递增运算
  (integer) 11
  127.0.0.1:6379> incr string6
  (integer) 12
  127.0.0.1:6379> incrby string6 2                //对变量进行递增2运算
  (integer) 14
  127.0.0.1:6379> incrby string6 2
  (integer) 16
  127.0.0.1:6379> incrby string6 2
  (integer) 18
  127.0.0.1:6379> incrby string6 2
  (integer) 20
  127.0.0.1:6379> set num 16.1                //设置浮点数变量
  OK
  127.0.0.1:6379> incrbyfloat num 1.1        //对浮点数进行递增1.1运算
  "17.2"
  127.0.0.1:6379> incrbyfloat num 1.1
  "18.3"
  127.0.0.1:6379> incrbyfloat num 1.1
  "19.4"
  127.0.0.1:6379> incrbyfloat num 1.1
  "20.5"


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-629723-1-1.html 上篇帖子: 搭建Redis 集群 下篇帖子: Redis主从复制(读写分离)、哨兵(主从切换)配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表