redis 的图标挺有意思的

来源:互联网 发布:真人变卡通人物软件 编辑:程序博客网 时间:2024/06/06 02:47


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.newredis.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 服务没有启动




5. 做ActiveRecord对象缓存

http://robbinfan.com/blog/33/activerecord-object-cache


6.  dalli/redis

  require 'active_support'  require 'dalli'  require 'active_support/cache/dalli_store'  Dalli.logger = $common_logger  dalli_opts = {    :namespace => "namespace_name",    :compress => true,    :expires_in => 60.minute  }  CACHE = ActiveSupport::Cache::DalliStore.new(APP_CONFIG['redis_url'], dalli_opts)  DALLI = Dalli::Client.new(APP_CONFIG['redis_url'], dalli_opts)  RedisCache = Redis.new(url: APP_CONFIG['redis_url'], :driver => :hiredis)  CACHE = ActiveSupport::Cache::RedisStore.new([{:host => APP_CONFIG['redis_url'], :port => 6379, :driver => :hiredis}])







0 0
原创粉丝点击