1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
--[[[
-- Just a test for Redis API
--]]
local logger = require "rspamd_logger"
local redis_lua = require "lua_redis"
local lua_util = require "lua_util"
local redis_params
local N = 'redis_test'
local lua_script = [[
local f = function() end
return "hello from lua on redis"
]]
local function redis_simple_async_symbol(task)
local function redis_cb(err, data)
if err then
task:insert_result('REDIS_ASYNC_ERROR', 1.0, err)
else
task:insert_result('REDIS_ASYNC', 1.0, data)
end
end
redis_lua.rspamd_redis_make_request(
task,
redis_params,
"test_key",
false,
redis_cb,
'GET',
{'test_key'}
)
end
local function redis_symbol(task)
local params = lua_util.deepcopy(redis_params)
params.task = task
local is_ok, connection = redis_lua.redis_connect_sync(params)
logger.infox(task, "connect: %1, %2", is_ok, connection)
if not is_ok then
task:insert_result('REDIS_ERROR', 1.0, connection)
return
end
local err, data
is_ok, err = connection:add_cmd('EVAL', {lua_script, 0})
logger.infox(task, "add_cmd: %1, %2", is_ok, err)
if not is_ok then
task:insert_result('REDIS_ERROR_2', 1.0, err)
return
end
is_ok,data = connection:exec()
logger.infox(task, "exec: %1, %2", is_ok, data)
if not is_ok then
task:insert_result('REDIS_ERROR_3', 1.0, data)
return
end
task:insert_result('REDIS', 1.0, data)
end
redis_params = rspamd_parse_redis_server(N)
rspamd_config:register_symbol({
name = 'SIMPLE_REDIS_ASYNC_TEST',
score = 1.0,
callback = redis_simple_async_symbol,
no_squeeze = true
})
rspamd_config:register_symbol({
name = 'REDIS_TEST',
score = 1.0,
callback = redis_symbol,
no_squeeze = true
})
-- ]]
|