mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
redis: sismember
This commit is contained in:
@@ -131,14 +131,16 @@ function command:exists(key)
|
|||||||
local ok, exists = read_response(fd)
|
local ok, exists = read_response(fd)
|
||||||
socket.unlock(fd)
|
socket.unlock(fd)
|
||||||
assert(ok, exists)
|
assert(ok, exists)
|
||||||
exists = exists ~= 0
|
return exists ~= 0
|
||||||
return exists
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function command:sismember(key, value)
|
function command:sismember(key, value)
|
||||||
assert(not batch, "sismember can't used in batch mode")
|
assert(not batch, "sismember can't used in batch mode")
|
||||||
local result, ismember = skynet.call( self.__handle, "lua" , "SISMEMBER", key, value)
|
socket.lock(fd)
|
||||||
assert(result, ismember)
|
socket.write(fd, compose_message { "SISMEMBER", key, value })
|
||||||
|
local ok, ismember = read_response(fd)
|
||||||
|
socket.unlock(fd)
|
||||||
|
assert(ok, ismember)
|
||||||
return ismember ~= 0
|
return ismember ~= 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -159,17 +161,12 @@ function command:batch(mode)
|
|||||||
return allret
|
return allret
|
||||||
else
|
else
|
||||||
local allok = true
|
local allok = true
|
||||||
local allret = true
|
|
||||||
for i = 1, self.__batch do
|
for i = 1, self.__batch do
|
||||||
local ok, ret = read_response(fd)
|
local ok = read_response(fd)
|
||||||
allok = allok and ok
|
allok = allok and ok
|
||||||
if ret~="OK" then
|
|
||||||
allret = false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
socket.unlock(self.__handle)
|
socket.unlock(self.__handle)
|
||||||
self.__mode = false
|
self.__mode = false
|
||||||
assert(allret, "reading in batch write")
|
|
||||||
return allok
|
return allok
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ skynet.start(function()
|
|||||||
db:batch "write" -- ignore results
|
db:batch "write" -- ignore results
|
||||||
db:set("A", "hello")
|
db:set("A", "hello")
|
||||||
db:set("B", "world")
|
db:set("B", "world")
|
||||||
|
db:sadd("C", "one")
|
||||||
print(db:batch "end")
|
print(db:batch "end")
|
||||||
|
|
||||||
db:batch "read"
|
db:batch "read"
|
||||||
@@ -20,6 +21,8 @@ skynet.start(function()
|
|||||||
print(db:get "A")
|
print(db:get "A")
|
||||||
print(db:set("A","hello world"))
|
print(db:set("A","hello world"))
|
||||||
print(db:get("A"))
|
print(db:get("A"))
|
||||||
|
print(db:sismember("C","one"))
|
||||||
|
print(db:sismember("C","two"))
|
||||||
db:disconnect()
|
db:disconnect()
|
||||||
skynet.exit()
|
skynet.exit()
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user