1. redis-cli的登录与常用数据类型
- 登录redis-cli
./redis-cli -h 127.0.0.1 -p 6379 -a root
ping
select 1
- 常用数据类型
String(字符串) Hashe(散列) List(列表) Set(集合) Sorted Set(有序集合) bitmaps、hyperloglogs等
2. 各种数据类型的操作
2.1 String(数值在这里也被视为字符串)
name : zhangsan
sex : '1'
age : '20'
address : Beijing
tel : 189*******4
set name zhangsan
mset sex 1 age 20 address BeiJing
get name
mget name sex age address
del name
del sex age address
2.3 Hash(可以将一个Hash元素看成是一个对象)
user : {
name : zhangsan,
sex : '1',
age : '20',
address : BeiJing
}
hset user name zhangsan
hmset user sex 1 age 20 address BeiJing
hget user name
hmget user name sex age address
hgetall user
hdel user sex age address
2.4 List(按照入栈规则自动排序,并且可存在相同数据)
students : [lisi, zhangsan, wangwu, lisi, houliu, lisi]
lpush students zhangsan lisi
rpush students wangwu houliu
lrange students 0 2
lrem students 2 lisi
2.5 Set(无序且不存在重复数据)
letters : {aaa, bbb, ccc, ddd, eee, fff}
sadd letters aaa bbb ccc ddd
sadd letters eee fff
sadd letters aaa bbb
smembers letters
srem letters aaa ddd
scard letters
2.6 Sorted Set(按照一定规则排序的集合)
score: {lvbu, zhaoyun, dianwei, guanyu, maochao, zhangfei}
zadd score 2 zhaoyun 4 guanyu 5 machao 6 zhangfei
zadd score 3 dianwei 1 lvbu
zrange score 0 5
zrem score guanyu zhangfei
zcard score
|