lib/async/redis/client.rb in async-redis-0.3.4 vs lib/async/redis/client.rb in async-redis-0.4.0

- old
+ new

@@ -16,35 +16,35 @@ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -require_relative 'protocol/resp' require_relative 'pool' -require_relative 'context/multi' +require_relative 'context/pipeline' +require_relative 'context/transaction' require_relative 'context/subscribe' -require_relative 'methods/strings' -require_relative 'methods/keys' -require_relative 'methods/lists' -require_relative 'methods/server' +require_relative 'protocol/resp2' require 'async/io' +require 'async/io/stream' +require 'protocol/redis/methods' + module Async module Redis + # Legacy. + ServerError = ::Protocol::Redis::ServerError + def self.local_endpoint Async::IO::Endpoint.tcp('localhost', 6379) end class Client - include Methods::Strings - include Methods::Keys - include Methods::Lists - include Methods::Server + include ::Protocol::Redis::Methods - def initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP, **options) + def initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP2, **options) @endpoint = endpoint @protocol = protocol @pool = connect(**options) end @@ -98,24 +98,41 @@ ensure context.close end end - def nested(&block) - context = Context::Nested.new(@pool) + def transaction(&block) + context = Context::Transaction.new(@pool) return context unless block_given? begin yield context ensure context.close end end + + def pipeline(&block) + context = Context::Pipeline.new(@pool) + + return context unless block_given? + + begin + yield context + ensure + context.close + end + end + # Deprecated. + alias nested pipeline + def call(*arguments) @pool.acquire do |connection| connection.write_request(arguments) + + connection.flush return connection.read_response end end