Skip to content

Instantly share code, notes, and snippets.

@kmansoft
Created July 19, 2016 12:12
Show Gist options
  • Save kmansoft/48bbb1fd933f5779b1e51052d145ad4e to your computer and use it in GitHub Desktop.
Save kmansoft/48bbb1fd933f5779b1e51052d145ad4e to your computer and use it in GitHub Desktop.
Tarantool side of things
#!/usr/bin/env tarantool
require("os")
clock = require("clock")
fiber = require('fiber')
local ADDR="127.0.0.1"
local PORT_CONN=3401
box.cfg{
logger = 'tarantool.log',
log_level = 4,
snapshot_period = 3600,
snapshot_count = 3,
listen = ADDR..':'..PORT_CONN
}
print ("Lua version: ", _VERSION)
space = box.space.data
if not space then
space = box.schema.create_space('data')
space:create_index('primary', { parts = {1, 'STR'}, type = 'HASH' })
space:create_index('value', { parts = {2, 'STR'}, type = 'TREE', unique = false})
space:create_index('ts_ping', { parts = {3, 'NUM'}, type = 'TREE', unique = false })
end
print ("existing object count: ", space:len())
local user = box.session.user()
print('user', user)
local clock_time1 = clock.time64()
print ("clock time1 = ", clock_time1)
local clock_time2 = clock.time64()
print ("clock_time2 = ", clock_time2)
local fiber_time1 = fiber.time64()
print ("fiber time1 = ", fiber_time1)
local fiber_time2 = fiber.time64()
print ("fiber_time2 = ", fiber_time2)
box.schema.user.grant('guest', 'read,write,execute', 'universe', nil, { if_not_exists=true })
box.schema.user.create('push', {password='push_pass', if_not_exists=true})
box.schema.user.grant('push', 'read,write', 'space', 'data', { if_not_exists=true })
box.schema.user.grant('push', 'execute', 'universe', nil, { if_not_exists=true })
function GoHandler_GetInsert(key, setval, ts_ping)
local val = space:get(key)
if val == nil then
val = {key, setval, ts_ping}
space:insert(val)
end
return val
end
function GoHandler_Put(key, setval, ts_ping)
local val = space:put({key, setval, ts_ping})
return val
end
function GoHandler_GetList(ts_ping)
local val = space.index.ts_ping:select({ts_ping}, {iterator='GE', limit=10})
return val
end
function GoHandler_GetVal(ts_ping)
local val = true
return {{true}}
end
local FUNC_LIST = {'GoHandler_GetInsert', 'GoHandler_Put', 'GoHandler_GetList', 'GoHandler_GetVal'}
for k, func in ipairs(FUNC_LIST)
do
print(k, func)
box.schema.func.create(func, { if_not_exists=true })
box.schema.user.grant('push', 'execute', 'function', func, { if_not_exists=true })
end
print ("connect to "..ADDR..":"..PORT_CONN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment