支持 js websocket
This commit is contained in:
10
examples/js_kv/.pages.yaml
Normal file
10
examples/js_kv/.pages.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
routes:
|
||||
- path: "get"
|
||||
js:
|
||||
exec: "index.js"
|
||||
debug: true
|
||||
|
||||
- path: "put"
|
||||
js:
|
||||
exec: "index.js"
|
||||
debug: true
|
||||
14
examples/js_kv/index.html
Normal file
14
examples/js_kv/index.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>JS 概念验证</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="/get">查询数据</a>
|
||||
<a href="/put">更新数据</a>
|
||||
</body>
|
||||
</html>
|
||||
19
examples/js_kv/index.js
Normal file
19
examples/js_kv/index.js
Normal file
@@ -0,0 +1,19 @@
|
||||
var db = kv.repo("self");
|
||||
if(request.path == "put"){
|
||||
data = db.get('key')
|
||||
if(data == undefined){
|
||||
db.set('key','0')
|
||||
}else {
|
||||
db.set('key',(parseInt(data)+1).toString())
|
||||
}
|
||||
}
|
||||
response.write("当前存储的数值为 " + db.get('key'))
|
||||
|
||||
var test = kv.repo("test");
|
||||
for (let i = 0; i < 500; i++) {
|
||||
test.set("key" + i,"value" + i);
|
||||
}
|
||||
var list = test.list()
|
||||
console.log(list.keys.length)
|
||||
console.log(list.cursor)
|
||||
console.log(list.hasNext)
|
||||
Reference in New Issue
Block a user