(10-2)redis基本コマンド


(10-2)redis基本コマンド
  redis:
[root@baozi ~]# redis-server /etc/redis.conf
[root@baozi ~]# redis-cli
127.0.0.1:6379>


//     
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> select 2
OK
127.0.0.1:6379[2]> select 15
OK
127.0.0.1:6379[15]> select 16
(error) ERR invalid DB index
127.0.0.1:6379>

//      
127.0.0.1:6379> get info1
(nil)
127.0.0.1:6379> set info1 hehe
OK
127.0.0.1:6379> get info1
"hehe"
127.0.0.1:6379>

//      
127.0.0.1:6379> keys *
 1) "set2"
 2) "user:101"
 3) "sset1"
 4) "baozi1"
 5) "user:100"
 6) "name2"
 7) "info"
 8) "set0"
 9) "set1"
10) "name"
11) "info1"
12) "list2"
13) "baozi"
14) "name1"
15) "list1"
//       
127.0.0.1:6379> keys info*
1) "info"
2) "info1"
127.0.0.1:6379>
127.0.0.1:6379> keys info?
1) "info1"
127.0.0.1:6379> keys info[0-1]
1) "info1"
127.0.0.1:6379>

//    ,       
127.0.0.1:6379> del info1
(integer) 1
127.0.0.1:6379> del info1
(integer) 0
127.0.0.1:6379> set info1 hehe
OK
127.0.0.1:6379> set info2 haha
OK
127.0.0.1:6379> del info1 info2
(integer) 2
127.0.0.1:6379>

//      
127.0.0.1:6379> get info
"hello redishello world"
127.0.0.1:6379> type info
string
127.0.0.1:6379>


//  redis  
127.0.0.1:6379> shutdown
not connected> quit
[root@baozi ~]# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>

//        
not connected> quit
[root@baozi ~]# redis-server /etc/redis.conf
[root@baozi ~]# redis-cli keys "*"
 1) "name2"
 2) "list2"
 3) "user:101"
 4) "set0"
 5) "baozi"
 6) "name1"
 7) "set2"
 8) "baozi1"
 9) "sset1"
10) "set1"
11) "list1"
12) "info"
13) "user:100"
14) "name"
[root@baozi ~]#


//      
[root@baozi ~]#  redis-cli keys "*"
 1) "name2"
 2) "list2"
 3) "user:101"
 4) "set0"
 5) "baozi"
 6) "name1"
 7) "set2"
 8) "baozi1"
 9) "sset1"
10) "set1"
11) "list1"
12) "info"
13) "user:100"
14) "name"
[root@baozi ~]# redis-cli del `redis-cli keys "name*"`
(integer) 3
[root@baozi ~]#  redis-cli keys "*"
 1) "list2"
 2) "user:101"
 3) "set0"
 4) "baozi"
 5) "set2"
 6) "baozi1"
 7) "sset1"
 8) "set1"
 9) "list1"
10) "info"
11) "user:100"
[root@baozi ~]#


//    16      
[root@baozi ~]# redis-cli
127.0.0.1:6379> flushall