- 数据类型
1) 字符串类型 string 2) 哈希类型 hash: map 3) 列表类型 list:
linkedlist格式。支持重复元素
4) 集合类型 set:
不允许重复元素
5) 有序集合类型 sortedset:
不允许重复元素,且元素有顺序
1)string
127.0.0.1:6379> set uname fff OK 127.0.0.1:6379> get uname "fff" 127.0.0.1:6379> del uname (integer) 1 127.0.0.1:6379> keys * (empty list or set)
2)hash
127.0.0.1:6379> hset mhash username zhangsan (integer) 1 127.0.0.1:6379> hset mhash password 123 (integer) 1 127.0.0.1:6379> hget mhash username "zhangsan" 127.0.0.1:6379> hgetall mhash 1) "username" 2) "zhangsan" 3) "password" 4) "123" 127.0.0.1:6379> hdel mhash password (integer) 1 127.0.0.1:6379> hgetall mhash 1) "username" 2) "zhangsan"
3)list
127.0.0.1:6379> lpush room a (integer) 1 127.0.0.1:6379> lpush room b (integer) 2 127.0.0.1:6379> rpush room c (integer) 3 127.0.0.1:6379> lrange room 0 -1 0 -1可以显示所有,若是 1 3 则显示从左往右第二个至第四个 1) "b" 2) "a" 3) "c" 127.0.0.1:6379> lpush room d (integer) 4 127.0.0.1:6379> lrange room 0 -1 1) "d" 2) "b" 3) "a" 4) "c" 127.0.0.1:6379> rpop room "c" 127.0.0.1:6379> lrange room 0 -1 1) "d" 2) "b" 3) "a"
4)set
127.0.0.1:6379> sadd fruits apple (integer) 1 127.0.0.1:6379> sadd fruits apple (integer) 0 127.0.0.1:6379> sadd fruits pear (integer) 1 127.0.0.1:6379> smembers fruits 1) "pear" 2) "apple" 127.0.0.1:6379> srem fruits pear (integer) 1 127.0.0.1:6379> smembers fruits 1) "apple"
5)sortedset
127.0.0.1:6379> zadd test 46 hong (integer) 1 127.0.0.1:6379> zadd test 44 li (integer) 1 127.0.0.1:6379> zadd test 60 zhang (integer) 1 127.0.0.1:6379> zrange test 0 -1 1) "li" 2) "hong" 3) "zhang" 127.0.0.1:6379> zrem test hong (integer) 1 127.0.0.1:6379> zrange test 0 -1 1) "li" 2) "zhang"
通用命令
127.0.0.1:6379> keys * 1) "test" 2) "fruits" 3) "room" 4) "mhash" 127.0.0.1:6379> type fruits 获取类型 set 127.0.0.1:6379> type test zset 127.0.0.1:6379> del mhash (integer) 1 127.0.0.1:6379> keys * 1) "test" 2) "fruits" 3) "room"