ubuntuにredisをインストールする

18578 ワード

1.apt-get install redis-server
2. Redis ~ ps -aux|grep redis redis 4162 0.1 0.0 10676 1420 ? Ss 23:24 0:00 /usr/bin/redis-server /etc/redis/redis.conf conan 4172 0.0 0.0 11064 924 pts/0 S+ 23:26 0:00 grep --color=auto redis 3. Redis ~ netstat -nlt|grep 6379 tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 4. Redis ~ sudo /etc/init.d/redis-server status redis-server is running
Redis-serverのインストール時にクライアントコマンドも一緒にインストールされているので、redis-cliでクライアントにアクセスできます
~ redis-cli
redis 127.0.0.1:6379>

#       
redis 127.0.0.1:6379> help
redis-cli 2.2.12
Type: "help @" to get a list of commands in 
      "help " for help on 
      "help " to get a list of possible help topics
      "quit" to exit


#      key  
redis 127.0.0.1:6379> keys *
(empty list or set)

テスト:
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set key "my name is  yuwensong";
Invalid argument(s)
127.0.0.1:6379> set key "my name is  yuwensong"
OK
127.0.0.1:6379> key *
(error) ERR unknown command 'key'
127.0.0.1:6379> keys *
1) "key"
127.0.0.1:6379> get key
"my name is  yuwensong"
127.0.0.1:6379> 
#         key2
set key2 1
OK

#      
redis 127.0.0.1:6379> INCR key2
(integer) 2
redis 127.0.0.1:6379> INCR key2
(integer) 3

#     
redis 127.0.0.1:6379> get key2
"3"
#         key3
redis 127.0.0.1:6379> LPUSH key3 a
(integer) 1

#        
redis 127.0.0.1:6379> LPUSH key3 b
(integer) 2

#        
redis 127.0.0.1:6379> RPUSH key3 c
(integer) 3

#       ,        
redis 127.0.0.1:6379> LRANGE key3 0 3
1) "b"
2) "a"
3) "c"
#          key4
redis 127.0.0.1:6379> HSET key4 name "John Smith"
(integer) 1

#        ,email Key Value  
redis 127.0.0.1:6379> HSET key4 email "[email protected]"
(integer) 1

#       ,name key  
redis 127.0.0.1:6379> HGET key4 name
"John Smith"

#        
redis 127.0.0.1:6379> HGETALL key4
1) "name"
2) "John Smith"
3) "email"
4) "[email protected]"
         key5


#          key5,      Key value  
redis 127.0.0.1:6379> HMSET key5 username antirez password P1pp0 age 3
OK

#       ,username age key  
redis 127.0.0.1:6379> HMGET key5 username age
1) "antirez"
2) "3"

#           
redis 127.0.0.1:6379> HGETALL key5
1) "username"
2) "antirez"
3) "password"
4) "P1pp0"
5) "age"
6) "3"

 
    


#      key  
redis 127.0.0.1:6379> keys *
1) "key2"
2) "key3"
3) "key4"
4) "key5"
5) "key1"

#   key1,key5
redis 127.0.0.1:6379> del key1
(integer) 1
redis 127.0.0.1:6379> del key5
(integer) 1

#      key  
redis 127.0.0.1:6379> keys *
1) "key2"
2) "key3"
3) "key4"
4.   Redis   

4.1   Redis     

     ,  Redis          ,             Redis        。       redisredis。

 vi  Redis        redis.conf


~ sudo vi /etc/redis/redis.conf

#    requirepass
requirepass redisredis

4.2  Redis        

     ,Redis          ,       ,                 。

 vi  Redis        redis.conf


~ sudo vi /etc/redis/redis.conf

#  bind
#bind 127.0.0.1

   ,  Redis   。


~ sudo /etc/init.d/redis-server restart
Stopping redis-server: redis-server.
Starting redis-server: redis-server.

       Redis   


~ redis-cli

redis 127.0.0.1:6379> keys *
(error) ERR operation not permitted

      ,        。

  Redis   ,    


~  redis-cli -a redisredis

redis 127.0.0.1:6379> keys *
1) "key2"
2) "key3"
3) "key4"

   ,    。
    Redis       


  Redis       
~ netstat -nlt|grep 6379
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN

              127.0.0.1:3306    0 0.0.0.0:3306,  Redis          。

         Linux  Redis   


~ redis-cli -a redisredis -h 192.168.1.199

redis 192.168.1.199:6379> keys *
1) "key2"
2) "key3"
3) "key4"

      。       ,    Redis      , Linux Ubuntu