redis五大基本类型---String
String(字符串)
指定配置文件启动redis,并连接,默认6379端口,看如何连接
[root@5444 src]# ./redis-server redis2.conf
[root@5444 src]# redis-cli -p 6380
127.0.0.1:6380> ping
PONG
记录命令,先看
set
get
mset
mget
incr
decr
incrby
decrby
setex
setnx
msetnx
keys *
append
strlen
ttl
getrange
使用:
127.0.0.1:6379> keys * //获取所有键值对
1) "name"
2) "k3"
3) "k2"
4) "views"
5) "k1"
127.0.0.1:6380> FLUSHALL
OK
127.0.0.1:6380> keys *
127.0.0.1:6380> set k1 v1 //设置键值对
OK
127.0.0.1:6380> get k1 //获取键值对
"v1"
127.0.0.1:6380> mset k2 v2 k3 v3 //批量设置键值对
OK
127.0.0.1:6380> mget k1 k2 //批量获取键值对
1) "v1"
2) "v2"
127.0.0.1:6380> set views 0
OK
127.0.0.1:6380> incr views //使views自增 +1
(integer) 1
127.0.0.1:6380> incr views
(integer) 2
127.0.0.1:6380> incrby views 1000 //使views自增 +1000
(integer) 1002
127.0.0.1:6380> decrby views 999 //使views自增 -999
(integer) 3
127.0.0.1:6380> exists k1 //判断键是否存在
(integer) 1
127.0.0.1:6380> append key1 "hello redis" //追加字符串,如果当前key不存在,就相当于setkey
(integer) 11
127.0.0.1:6380> get key1
"hello redis"
127.0.0.1:6380> strlen key1 //计算值的长度
(integer) 11
127.0.0.1:6380> getrange key1 0 3 //循环输出
"hell"
127.0.0.1:6380> get key2
"\x00MM"