1. redis-cli -h 127.0.0.1 -p 6379
2. redis-cli SHUTDOWN
3. incr foo; get foo;
4. keys ×;
5. config set loglevel warning;
6.包括incr在内的所有Redis命令都是原子操作
7. incrby, decrby, incrbyfloat
8.exists;
9. append key " world!"
10. mset, mget
11.setbit, getbit, bitcount
12. bitop or res op1 op2
13. 每个键都属于一个明确的数据类型,如通过HSET命令建立的键是散列类型,通过set命令建立的键是字符串类型等。
13. hmset car name value1 price value2
14. hgetall car;
15. hexists key field
16. hsetnx key field value, 是原子条件,不用担心竞态条件;
17.hincrby person score 60,散列类型没有hincr命令;
18.hdel key field可以删除一个或多个字段,返回值是被删除的字段个数
19. hkeys, hvals, hlen;
20. 散列类型;列表类型;
21. 列表类型,使用散列;
22. lpush 1, 2, 3; rpush;lpop; rpop; llen; lrange list 0 2;lrange number 0 -1; lrem number -1 2
23. lindex number 0; ltrim number 0 2; linsert number before 3 1
24. rpoplpush source destination;
25. 集合类型
26. sadd letters a;srem letters c d;smembers letters;sismember letters a
127.0.0.1:6379> sadd setA 1 2 3
(integer) 3
127.0.0.1:6379> sadd setB 2 3 4
(integer) 3
127.0.0.1:6379> sdiff setA setB
1) "1"
127.0.0.1:6379> sadd setC 2 3
(integer) 2
127.0.0.1:6379> sdiff setA setB setC
1) "1"
127.0.0.1:6379> sinter setA setB
1) "2"
2) "3"
127.0.0.1:6379> sunion setA setB
127.0.0.1:6379> scard setA [1/305]
(integer) 3
127.0.0.1:6379> smembers letters
1) "b"
2) "a"
127.0.0.1:6379> scard letters
(integer) 2
127.0.0.1:6379> sdiffstore setAB setA setB
(integer) 1
127.0.0.1:6379> scard setAB
(integer) 1
127.0.0.1:6379> smembers setAB
1) "1"
127.0.0.1:6379> srandmember letters
"a"
127.0.0.1:6379> srandmember letters
"b"
127.0.0.1:6379> srandmember letters
"a"
127.0.0.1:6379> srandmember letters
"a"
127.0.0.1:6379> sadd letters c d
(integer) 2
127.0.0.1:6379> sadd letters e f
(integer) 2
127.0.0.1:6379> srandmember letter 2
(empty list or set)
127.0.0.1:6379> srandmember letters 2
1) "c"
2) "a"
127.0.0.1:6379> srandmember letters 2
1) "d"
2) "f"
127.0.0.1:6379> srandmember letters -4
1) "b"
2) "c"
3) "d"
4) "b"
127.0.0.1:6379> spop letters
127.0.0.1:6379> zadd scoreboard 89 Tom 67 Peter 100 David [2/30]
(integer) 3
127.0.0.1:6379> zadd scoreboard 76 Peter
(integer) 0
127.0.0.1:6379> zadd testboard 17e+307 a
(integer) 1
127.0.0.1:6379> zadd testboard 1.5 b
(integer) 1
127.0.0.1:6379> zadd testboard +inf c
(integer) 1
127.0.0.1:6379> zadd testboard -inf d
(integer) 1
127.0.0.1:6379> zscore scoreboard Tom
"89"
127.0.0.1:6379> zrange scoreboard 0 2
1) "Peter"
2) "Tom"
3) "David"
127.0.0.1:6379> zrange scoreboard 1 -1
1) "Tom"
2) "David"
127.0.0.1:6379> zrange scoreboard 1 -1 withscores
1) "Tom"
2) "89"
3) "David"
4) "100"
127.0.0.1:6379> zadd chineseName 0 麻花 0 刘用 0 是吗光 0 照着
(integer) 4
127.0.0.1:6379> zrange chineseName 0 -1
1) "\xe5\x88\x98\xe7\x94\xa8"
2) "\xe6\x98\xaf\xe5\x90\x97\xe5\x85\x89"
3) "\xe7\x85\xa7\xe7\x9d\x80"
4) "\xe9\xba\xbb\xe8\x8a\xb1"
127.0.0.1:6379> zrangebyscore scoreboard 80 100
1) "Tom"
2) "David"
127.0.0.1:6379> zrangebyscore scoreboard 80 (100
1) "Tom"
127.0.0.1:6379> zrangebyscore scoreboard (80 +inf
127.0.0.1:6379> zadd scoreboard 56 Jerry 92 Wendy 67 Yvonne
(integer) 3
127.0.0.1:6379> zrange scoreboard 0 -1 withscores
1) "Jerry"
2) "56"
3) "Yvonne"
4) "67"
5) "Peter"
6) "76"
7) "Tom"
8) "89"
9) "Wendy"
10) "92"
11) "David"
12) "100"
127.0.0.1:6379> zrangebyscore scoreboard 60 +inf limit 1 3
1) "Peter"
2) "Tom"
3) "Wendy"
127.0.0.1:6379> zrevrangebyscore scoreboard 100 0 limit 0 3
1) "David"
2) "Wendy"
3) "Tom"
127.0.0.1:6379> zincrby scoreboard 4 Jerry
"60"
127.0.0.1:6379> zincrby scoreboard -4 Jerry
"56"
127.0.0.1:6379> zrangebyscore scoreboard 60 +inf limit 1 3 [14/99]
1) "Peter"
2) "Tom"
3) "Wendy"
127.0.0.1:6379> zrevrangebyscore scoreboard 100 0 limit 0 3
1) "David"
2) "Wendy"
3) "Tom"
127.0.0.1:6379> zincrby scoreboard 4 Jerry
"60"
127.0.0.1:6379> zincrby scoreboard -4 Jerry
"56"
127.0.0.1:6379> clear
127.0.0.1:6379> zcard scoreboard
(integer) 6
127.0.0.1:6379> zcount scoreboard 90 100
(integer) 2
127.0.0.1:6379> zcount scoreboard (89 +inf
(integer) 2
127.0.0.1:6379> zcount scoreboard (89 -inf
(integer) 0
127.0.0.1:6379> zrem scoreboard Wendy
(integer) 1
127.0.0.1:6379> zcard scoreboard
(integer) 5
127.0.0.1:6379> zadd testRem 1 a 2 b 3 c 4 d 5 e 6 f
(integer) 6
127.0.0.1:6379> zremrangebyrank 0 2
(error) ERR wrong number of arguments for 'zremrangebyrank' command
127.0.0.1:6379> ZREMRANGEBYRANK 0 2
(error) ERR wrong number of arguments for 'zremrangebyrank' command
127.0.0.1:6379> zremrangebyrank scoreboard 0 2
(integer) 3
127.0.0.1:6379> zremrangebyrank testrem 0 2
(integer) 0
127.0.0.1:6379> zremrangebyrank testRem 0 2
(integer) 3
127.0.0.1:6379> zcard testRem
(integer) 3
127.0.0.1:6379> zrange testRem 0 -1
27. 建立实例或从数据库
a. redis-server --port 6380 --slaveof 127.0.0.1 6379;
b. redis-cli; redis-cli -p 6380