Redis 简明教程(五) 基本操作命令
程序员文章站
2024-01-05 09:26:10
...
redis 命令在线文档
http://redisdoc.com/#
String
基本操作实例
127.0.0.1:6379> set cat chouchou
OK
127.0.0.1:6379> get cat
"chouchou"
Hash
127.0.0.1:6379> hmset cat name "chouchou" age 1 weight 1 sex "female"
OK
127.0.0.1:6379> hgetall cat
1) "name"
2) "chouchou"
3) "age"
4) "1"
5) "weight"
6) "1"
7) "sex"
8) "female"
List
127.0.0.1:6379> lpush dog dahuang
(integer) 1
127.0.0.1:6379> lpush dog datao
(integer) 2
127.0.0.1:6379> lpush dog datao
(integer) 3
127.0.0.1:6379> lpush dog ahhah
(integer) 4
127.0.0.1:6379> lpush dog mm
(integer) 5
127.0.0.1:6379> lrange dog 0 10
1) "mm"
2) "ahhah"
3) "datao"
4) "datao"
5) "dahuang"
SET
127.0.0.1:6379> aadd university qinghua
(error) ERR unknown command 'aadd'
127.0.0.1:6379> sadd university qinghua
(integer) 1
127.0.0.1:6379> sadd university peking
(integer) 1
127.0.0.1:6379> sadd university huake
(integer) 1
127.0.0.1:6379> sadd university wuhan
(integer) 1
127.0.0.1:6379> sadd university wuhan
(integer) 0
127.0.0.1:6379> sadd university scuec
(integer) 1
127.0.0.1:6379> smembers university
1) "peking"
2) "huake"
3) "wuhan"
4) "scuec"
5) "qinghua"
ZSET
127.0.0.1:6379> zadd school 1 wuhan
(integer) 1
127.0.0.1:6379> zadd school 2 chengdu
(integer) 1
127.0.0.1:6379> zadd school 3 chongqing
(integer) 1
127.0.0.1:6379> zadd school 3 xiangyang
(integer) 1
127.0.0.1:6379> zadd school 4 xiaogan
(integer) 1
127.0.0.1:6379> zadd school 5 yichang
(integer) 1
127.0.0.1:6379> zrange school 0 10 withscores
1) "wuhan"
2) "1"
3) "chengdu"
4) "2"
5) "chongqing"
6) "3"
7) "xiangyang"
8) "3"
9) "xiaogan"
10) "4"
11) "yichang"
12) "5"
127.0.0.1:6379> zrange school 0 10
1) "wuhan"
2) "chengdu"
3) "chongqing"
4) "xiangyang"
5) "xiaogan"
6) "yichang"