viernes, 1 de julio de 2011

数据库操作 (数据库已自动连接平台分配的服务器)

CODES:
local rows = get_results("SELECT * FROM table LIMIT 100;") --get_row、query、found_rows、insert_id
for l,row in pairs(rows) do
print(row.title)
end

缓存操作 (已自动连接平台的memcached集群)

CODES:
local datas = {}
datas.title = 'Title1'
datas.content = 'Content1'
cache_set('key_name',datas) --cache_delete
local d = cache_get('key_name')
print(d.title)

文件操作 (已自动连接平台的存储集群)

CODES:
file_put_content('/path/filename',datas)
--对应访问URL: http://app.com/upload/path/filename
local file_contents = file_get_content('/path/filename')
file_delete('/path/filename')

网页模板输出

CODES(/htdocs/index.lua):
title = '标题'
rows = get_results('SELECT * FROM table LIMIT 100')

HTML模板(/template/index.html):
$ [title]无标题
  • $ [sub_title]

敏捷的API开发模式

CODES(/api/demo.lua):
function rpc_hello(word)
return 'hello '..word
end

LUA程序里调用API接口:
local r = R('http://yo2lua.com/api/demo/', 'rpc_hello')('oneoo') --返回字符串 'hello oneoo'

同时我们也提供PHP、JavaScript和Flash AS的API操作库,其他语言都可以很简单直接的调用这些函数。我们给该API模式命名为:rFuntion。一处代码随处可用!



数据库操作 (数据库已自动连接平台分配的服务器)
CODES:
local rows = get_results("SELECT * FROM table LIMIT 100;") --get_row、query、found_rows、insert_id
for l,row in pairs(rows) do
    print(row.title)
end
缓存操作 (已自动连接平台的memcached集群)
CODES:
local datas = {}
datas.title = 'Title1'
datas.content = 'Content1'
cache_set('key_name',datas) --cache_delete
local d = cache_get('key_name')
print(d.title)
文件操作 (已自动连接平台的存储集群)
CODES:
file_put_content('/path/filename',datas)
--对应访问URL: http://app.com/upload/path/filename 
local
 file_contents = file_get_content('/path/filename')
file_delete('/path/filename')
网页模板输出
CODES(/htdocs/index.lua):
title = '标题'
rows = get_results('SELECT * FROM table LIMIT 100')
HTML模板(/template/index.html):
<span class="orange2" style="color: rgb(247, 94, 36); ">$ [title]</span>无标题
         
  • $ [sub_title]

敏捷的API开发模式
CODES(/api/demo.lua):
function rpc_hello(word)
    return 'hello '..word
end
LUA程序里调用API接口:
local r = R('http://yo2lua.com/api/demo/''rpc_hello')('oneoo'--返回字符串 'hello oneoo'
同时我们也提供PHP、JavaScript和Flash AS的API操作库,其他语言都可以很简单直接的调用这些函数。我们给该API模式命名为:rFuntion。一处代码随处可用!



Follow kmigomo on Twitter

No hay comentarios: