New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support nonblocking behavior. #31
Comments
Hi @littleboss, This is a blocking client implementation and currently there are no plans to add a non-blocking interface to it (to be honest I've never experimented with cosocket) as it's not a priority. Things may change in this respect with help coming from other developers though. |
You can make a non-blocking (asynchronous) implementation using copas. It will look like this ( example with benchmark): local redis = require("redis")
local copas = require("copas")
local socket = require("socket")
local get_connection = function(host, port, pass)
local sock = socket.tcp()
sock = copas.wrap(sock)
sock:connect(host, port or 6379)
local client = redis.connect({
socket = sock,
})
client:auth(pass)
return client
end
local now = socket.gettime
local start = now()
local reps = 1000
for i = 1, reps do
copas.addthread(function()
local host, port, pass = "redis", 6379, "redis-pass"
local client = get_connection(host, port, pass)
print(i, client:incr("bench") )
reps = reps - 1
if reps == 0 then
print("finished in " .. (now() - start) .. " seconds") -- 0.18 seconds for 1000 requests
end
end)
end
copas.loop()
Here is the benchmark for the default implementation: local redis = require("redis")
local host, port, pass = "redis", 6379, "redis_pass"
local client = redis.connect(host, port or 6379)
client:auth(pass)
local now = require("socket").gettime
local start = now()
for _ = 1, 1000 do
print( client:incr("bench1") )
end
print("finished in " .. (now() - start) .. " seconds") -- 11.95 seconds As you can see, 1000 queries in the synchronous implementation are executed in 11 seconds, while "async" queries are executed in 0.18 seconds |
i check the lua redis client in https://github.com/agentzh/lua-resty-redis, it support 100% nonblocking behavior. because it uses cosocket api,
dose this client api support non blocking
thanks
The text was updated successfully, but these errors were encountered: