You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
216 lines
3.7 KiB
216 lines
3.7 KiB
|
|
本文标题: Django中redis的使用方法(包括安装、配置、启动)
|
|
本文地址: http://www.cppcns.com/shujuku/redis/220910.html
|
|
|
|
|
|
./redis-4.0.8/src/redis-cli [-h] [-p]
|
|
127.0.0.1:6379> ping
|
|
PONG
|
|
127.0.0.1:6379> select 5
|
|
OK
|
|
127.0.0.1:6379[5]> keys *
|
|
(empty list or set)
|
|
127.0.0.1:6379[5]> set name itchat
|
|
OK
|
|
127.0.0.1:6379[5]> get name
|
|
"itchat"
|
|
127.0.0.1:6379[5]> set name itchat2
|
|
OK
|
|
127.0.0.1:6379[5]> get name
|
|
"itchat2"
|
|
127.0.0.1:6379[5]> keys *
|
|
1) "name"
|
|
127.0.0.1:6379[5]> setex aa 3 ii
|
|
OK
|
|
127.0.0.1:6379[5]> keys *
|
|
1) "name"
|
|
127.0.0.1:6379[5]> setex aa 3 ii
|
|
OK
|
|
127.0.0.1:6379[5]> get aa
|
|
"ii"
|
|
127.0.0.1:6379[5]> get aa
|
|
(nil)
|
|
127.0.0.1:6379[5]> mset a1 java a2 python a3 c
|
|
OK
|
|
127.0.0.1:6379[5]> get a1
|
|
"java"
|
|
127.0.0.1:6379[5]> get a2
|
|
"python"
|
|
127.0.0.1:6379[5]> get a3
|
|
"c"
|
|
127.0.0.1:6379[5]> append a1 haha
|
|
(integer) 8
|
|
127.0.0.1:6379[5]> get a1
|
|
"javahaha"
|
|
127.0.0.1:6379[5]> exists a
|
|
(integer) 0
|
|
127.0.0.1:6379[5]> exists a2
|
|
(integer) 1
|
|
127.0.0.1:6379[5]> type name
|
|
string
|
|
127.0.0.1:6379[5]> mget a1 a2 a3
|
|
1) "javahaha"
|
|
2) "python"
|
|
3) "c"
|
|
127.0.0.1:6379[5]> del a1 a2 a3
|
|
(integer) 3
|
|
127.0.0.1:6379[5]> keys *
|
|
1) "name"
|
|
127.0.0.1:6379[5]> set a1 python
|
|
OK
|
|
127.0.0.1:6379[5]> expire a1 3
|
|
(integer) 1
|
|
127.0.0.1:6379[5]> get a1
|
|
(nil)
|
|
127.0.0.1:6379[5]> get a1
|
|
(nil)
|
|
127.0.0.1:6379[5]> expire a1 3
|
|
(integer) 0
|
|
127.0.0.1:6379[5]> get a1
|
|
(nil)
|
|
127.0.0.1:6379[5]> hset user name itthema
|
|
(integer) 1
|
|
127.0.0.1:6379[5]> keys *
|
|
1) "name"
|
|
2) "user"
|
|
127.0.0.1:6379[5]> hmset u2 name itcast age 12
|
|
OK
|
|
127.0.0.1:6379[5]> type u2
|
|
hash
|
|
127.0.0.1:6379[5]> hkeys user
|
|
1) "name"
|
|
127.0.0.1:6379[5]> hkeys u2
|
|
1) "name"
|
|
2) "age"
|
|
127.0.0.1:6379[5]> keys name
|
|
1) "name"
|
|
127.0.0.1:6379[5]> keys *
|
|
1) "name"
|
|
2) "user"
|
|
3) "u2"
|
|
127.0.0.1:6379[5]> hget u2 name
|
|
"itcast"
|
|
127.0.0.1:6379[5]> hget u2 age
|
|
"12"
|
|
127.0.0.1:6379[5]> hvals u2
|
|
1) "itcast"
|
|
2) "12"
|
|
127.0.0.1:6379[5]> hdel u2 name
|
|
(integer) 1
|
|
127.0.0.1:6379[5]> hkeys u2
|
|
1) "age"
|
|
127.0.0.1:6379[5]> set a1
|
|
(error) ERR wrong number of arguments for 'set' command
|
|
127.0.0.1:6379[5]> lpush a1 a b c
|
|
(integer) 3
|
|
127.0.0.1:6379[5]> type a1
|
|
list
|
|
127.0.0.1:6379[5]> lrange a1
|
|
(error) ERR wrong number of arguments for 'lrange' command
|
|
127.0.0.1:6379[5]> lrange a1 0 3
|
|
1) "c"
|
|
2) "b"
|
|
3) "a"
|
|
127.0.0.1:6379[5]> rpush a1 0 1
|
|
(integer) 5
|
|
127.0.0.1:6379[5]> lrange a1 0 5
|
|
1) "c"
|
|
2) "b"
|
|
3) "a"
|
|
4) "0"
|
|
5) "1"
|
|
127.0.0.1:6379[5]> lrange a1 0 4
|
|
1) "c"
|
|
2) "b"
|
|
3) "a"
|
|
4) "0"
|
|
5) "1"
|
|
127.0.0.1:6379[5]> lrange a1 0 3
|
|
1) "c"
|
|
2) "b"
|
|
3) "a"
|
|
4) "0"
|
|
127.0.0.1:6379[5]> linsert a1 before b 3
|
|
(integer) 6
|
|
127.0.0.1:6379[5]> lrange a1 0 5
|
|
1) "c"
|
|
2) "3"
|
|
3) "b"
|
|
4) "a"
|
|
5) "0"
|
|
6) "1"
|
|
127.0.0.1:6379[5]> lrange a1 0 -1
|
|
1) "c"
|
|
2) "3"
|
|
3) "b"
|
|
4) "a"
|
|
5) "0"
|
|
6) "1"
|
|
127.0.0.1:6379[5]> lset a1 1 z
|
|
OK
|
|
127.0.0.1:6379[5]> lrange a1 0 -1
|
|
1) "c"
|
|
2) "z"
|
|
3) "b"
|
|
4) "a"
|
|
5) "0"
|
|
6) "1"
|
|
127.0.0.1:6379[5]> sadd a3 1 2 3 4
|
|
(integer) 4
|
|
127.0.0.1:6379[5]> smembers a2
|
|
(empty list or set)
|
|
127.0.0.1:6379[5]> smembers a3
|
|
1) "1"
|
|
2) "2"
|
|
3) "3"
|
|
4) "4"
|
|
127.0.0.1:6379[5]> sadd a2 zhangsan wanger lisi
|
|
(integer) 3
|
|
127.0.0.1:6379[5]> smembers a2
|
|
1) "wanger"
|
|
2) "zhangsan"
|
|
3) "lisi"
|
|
127.0.0.1:6379[5]> smembers a3
|
|
1) "1"
|
|
2) "2"
|
|
3) "3"
|
|
4) "4"
|
|
127.0.0.1:6379[5]> srem a3 3
|
|
(integer) 1
|
|
127.0.0.1:6379[5]> smembers a3
|
|
1) "1"
|
|
2) "2"
|
|
3) "4"
|
|
127.0.0.1:6379[5]> zadd a4 4 lisi 5 wangwu 6 zhaoliu 3 zhangsan
|
|
(integer) 4
|
|
127.0.0.1:6379[5]> keys *
|
|
1) "name"
|
|
2) "a2"
|
|
3) "a1"
|
|
4) "user"
|
|
5) "a4"
|
|
6) "a3"
|
|
7) "u2"
|
|
127.0.0.1:6379[5]> type a4
|
|
zset
|
|
127.0.0.1:6379[5]> zrange a4 0 -1
|
|
1) "zhangsan"
|
|
2) "lisi"
|
|
3) "wangwu"
|
|
4) "zhaoliu"
|
|
127.0.0.1:6379[5]> zscore a4 zhangsan
|
|
"3"
|
|
127.0.0.1:6379[5]> zrem z4 zhangsan
|
|
(integer) 0
|
|
127.0.0.1:6379[5]> zrem a4 zhangsan
|
|
(integer) 1
|
|
127.0.0.1:6379[5]> zrange a4 0 -1
|
|
1) "lisi"
|
|
2) "wangwu"
|
|
3) "zhaoliu"
|
|
127.0.0.1:6379[5]> zremrangebyscore a4 5 6
|
|
(integer) 2
|
|
127.0.0.1:6379[5]> zrange a4 0 -1
|
|
1) "lisi"
|
|
|