Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
sbbs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eric
sbbs
Commits
39e8ed20
Commit
39e8ed20
authored
13 years ago
by
mcmlxxix
Browse files
Options
Downloads
Patches
Plain Diff
new db query "KEYS" returns an array of object keys
parent
caae4a1f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
exec/load/json-client.js
+33
-25
33 additions, 25 deletions
exec/load/json-client.js
exec/load/json-db.js
+26
-1
26 additions, 1 deletion
exec/load/json-db.js
with
59 additions
and
26 deletions
exec/load/json-client.js
+
33
−
25
View file @
39e8ed20
...
...
@@ -14,20 +14,26 @@ load("json-sock.js");
- JSONClient.cycle();
- JSONClient.connect();
- JSONClient.disconnect();
- JSONClient.read();
- JSONClient.pop();
- JSONClient.shift();
- JSONClient.write();
- JSONClient.push();
- JSONClient.unshift();
- JSONClient.lock();
- JSONClient.unlock();
- JSONClient.subscribe();
- JSONClient.unsubscribe();
- JSONClient.status();
- JSONClient.who();
- JSONClient.ident();
- JSONClient.read(
scope,location,lock
);
- JSONClient.pop(
scope,location,lock
);
- JSONClient.shift(
scope,location,lock
);
- JSONClient.write(
scope,location,lock
);
- JSONClient.push(
scope,location,lock
);
- JSONClient.unshift(
scope,location,lock
);
- JSONClient.lock(
scope,location,lock
);
- JSONClient.unlock(
scope,location
);
- JSONClient.subscribe(
scope,location
);
- JSONClient.unsubscribe(
scope,location
);
- JSONClient.status(
scope,location
);
- JSONClient.who(
scope,location
);
- JSONClient.ident(
scope,username,password
);
NOTE: scope is the module or root service you wish to send the command to,
location is a dot-notated object property, and lock is one of the following:
LOCK_READ = 1
LOCK_WRITE = 2
LOCK_UNLOCK = -1
indirect methods: these will generally be called automatically by the other methods
and you will not typically need to use them
...
...
@@ -43,22 +49,14 @@ load("json-sock.js");
sample usage:
var LOCK_READ = 1;
var LOCK_WRITE = 2;
var UNLOCK = -1;
load("json-client.js");
var client=new JSONClient(myServer,myPort);
function callback(data) {
myData = data;
}
while(1) {
doSomething();
client.lock("mydatabase.dong",LOCK_READ);
var dong=client.read("mydatabase.dong");
client.unlock("mydatabase.dong");
client.lock("
myscript","
mydatabase.dong",LOCK_READ);
var dong=client.read("
myscript","
mydatabase.dong");
client.unlock("
myscript","
mydatabase.dong");
print("look at my " + dong);
client.cycle();
}
...
...
@@ -130,7 +128,7 @@ function JSONClient(serverAddr,serverPort) {
/* unlock an object */
this
.
unlock
=
function
(
scope
,
location
)
{
this
.
lock
(
scope
,
location
,
-
1
);
this
.
lock
(
scope
,
location
,
-
1
);
}
/* read object data (lock for reading or writing, blocking) */
...
...
@@ -143,6 +141,16 @@ function JSONClient(serverAddr,serverPort) {
return
this
.
wait
(
"
RESPONSE
"
);
}
/* read object keys (lock for reading or writing, blocking) */
this
.
keys
=
function
(
scope
,
location
,
lock
)
{
this
.
send
(
scope
,
"
QUERY
"
,{
oper
:
"
KEYS
"
,
location
:
location
,
lock
:
lock
});
return
this
.
wait
(
"
RESPONSE
"
);
}
/* shift object data (lock for reading or writing, blocking) */
this
.
shift
=
function
(
scope
,
location
,
lock
)
{
this
.
send
(
scope
,
"
QUERY
"
,{
...
...
This diff is collapsed.
Click to expand it.
exec/load/json-db.js
+
26
−
1
View file @
39e8ed20
...
...
@@ -87,7 +87,8 @@ function JSONdb (fileName) {
SUBSCRIBE
:
8
,
UNSUBSCRIBE
:
9
,
WHO
:
10
,
STATUS
:
11
STATUS
:
11
,
KEYS
:
12
}
/* error constants */
...
...
@@ -357,6 +358,27 @@ function JSONdb (fileName) {
return
false
;
}
};
/* retrieve a list of object keys */
this
.
keys
=
function
(
client
,
record
)
{
var
keys
=
[];
/* if the requested data does not exist, result is undefined */
if
(
record
.
data
===
undefined
)
{
send_packet
(
client
,
undefined
,
"
RESPONSE
"
);
return
true
;
}
/* if this client has this record locked, read */
if
(
record
.
info
.
lock
[
client
.
id
])
{
for
(
var
k
in
record
.
data
[
record
.
child_name
])
keys
.
push
(
k
);
send_packet
(
client
,
keys
,
"
RESPONSE
"
);
return
true
;
}
/* if there is no lock for this client, error */
else
{
return
false
;
}
}
/* remove a record from the database (requires WRITE_LOCK) */
this
.
remove
=
function
(
client
,
record
)
{
...
...
@@ -619,6 +641,9 @@ function JSONdb (fileName) {
case
"
WRITE
"
:
result
=
this
.
write
(
request
.
client
,
record
,
request
.
data
);
break
;
case
"
KEYS
"
:
result
=
this
.
keys
(
request
.
client
,
record
);
break
;
case
"
PUSH
"
:
result
=
this
.
push
(
request
.
client
,
record
,
request
.
data
);
break
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment