require"redis"worker_processes3# If you set the connection to Redis *before* forking,# you will cause forks to share a file descriptor.## This causes a concurrency problem by which one fork# can read or write to the socket while others are# performing other operations.## Most likely you'll be getting ProtocolError exceptions# mentioning a wrong initial byte in the reply.## Thus we need to connect to Redis after forking the# worker processes.after_forkdo|server,worker|Redis.current.quitend
然后我试着找资料写了一个 PhusionPassenger 的解决方案
1234567891011121314151617181920212223242526272829
# config/initializers/redis_search.rbrequire"redis"require"redis-namespace"require"redis-search"# don't forget change namespaceifdefined?(PhusionPassenger)PhusionPassenger.on_event(:starting_worker_process)do|forked|ifforkedRedis.current.client.reconnectelseRedis.current=Redis.new(:host=>"127.0.0.1",:port=>"6379")endendendredis=Redis.currentredis.select(3)# We suggest you use a special db in Redis, when you need to clear all data, you can use flushdb command to clear them.# # Give a special namespace as prefix for Redis key, when your have more than one project used redis-search, this config will make them work fine.redis=Redis::Namespace.new("wakmj:redis_search",:redis=>redis)Redis::Search.configuredo|config|config.redis=redisconfig.complete_max_length=100config.pinyin_match=true# use rmmseg, true to disable it, it can save memroyconfig.disable_rmmseg=falseend