From c45f02a6d766858a340bdec1330a487159349359 Mon Sep 17 00:00:00 2001 From: Vladimir Kochnev Date: Fri, 21 Aug 2015 16:29:42 +0300 Subject: [PATCH] Synchronize redis operations with task-aware latch. --- lib/celluloid/redis.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/celluloid/redis.rb b/lib/celluloid/redis.rb index 4648b0e..9742289 100644 --- a/lib/celluloid/redis.rb +++ b/lib/celluloid/redis.rb @@ -1,3 +1,25 @@ require "redis" require "celluloid/redis/version" +require "celluloid/io" + +module Celluloid + class Redis < ::Redis + VERSION = CelluloidRedis::VERSION + + def initialize(*args) + super + if @options[:driver] == :celluloid + @latch = Celluloid::IO::Stream::Latch.new + end + end + + def synchronize + if @latch + @latch.synchronize { yield @client } + else + super(&proc) + end + end + end +end