首页 > 代码库 > redis 的图标挺有意思的

redis 的图标挺有意思的


redis 的使用


1.安装redis官网的步骤安装redis (http://redis.io/download)


$ wget http://download.redis.io/releases/redis-2.8.15.tar.gz
$ tar xzf redis-2.8.15.tar.gz
$ cd redis-2.8.15
$ make


2.启动redis 


$ src/redis-server

or


后台启动


nohup src/redis-server &

进程 

[1] 16461


有意思的提示

root@5254004e45d0:/srv/rorapps/redis/redis-2.8.15# src/redis-server 
[16445] 16 Sep 09:54:32.684 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
[16445] 16 Sep 09:54:32.686 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 2.8.15 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 16445
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

[16445] 16 Sep 09:54:32.688 # Server started, Redis version 2.8.15
[16445] 16 Sep 09:54:32.688 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[16445] 16 Sep 09:54:32.688 * The server is now ready to accept connections on port 6379



Ok, 以上redis的服务端完成了



3.客户端使用

这里介绍Rails的使用

Gem

redis-rb (https://github.com/redis/redis-rb)


require "redis"

redis = Redis.new

redis.set("mykey", "hello world")
# => "OK"

redis.get("mykey")
# => "hello world"



Ok,客户端简单版


4.错误解决

提示

Redis::ProtocolError ( Got 'H' as initial reply byte. If you're in a forking environment, such as Unicorn, you need to connect to Redis after forking. ):

是指你的Redis 服务没有启动







redis 的图标挺有意思的