配置Redis主从服务器(有图)
# redis-cli 127.0.0.1:6379> pingPONG
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]