hsss 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CODE_OF_CONDUCT.md +4 -3
- data/README.md +101 -18
- data/lib/hsss/version.rb +1 -1
- data/lib/hsss.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 487fa212d82812cc8a4857fa40ac9c187f24655f
|
4
|
+
data.tar.gz: adcd2bfd44090494e15c4c5e1244136cfe1597a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05afc51d04680fbfe69190cde89918e5838156858c25ce88c6a9001d4eab710808ae623d8d9535283a5c148f446e33ba117a7ea131bd3cfbfebf1a62d3ebfa6b
|
7
|
+
data.tar.gz: 0d1d0db05ab197ab623540b023ed7a5777886a4bb04c6c55b8c411d6fd930a56c0ce5e6cefed2c6a5de470d182354764e80bee64c7f6107c92970a4d33729c7d
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
In the spirit of inclusiveness, cooperation and community, this
|
1
|
+
In the spirit of inclusiveness, cooperation and community, this software is
|
2
2
|
distributed with the strictly enforced CYHTFYW Code of Conduct. Failure to
|
3
|
-
comply with this code may result in punitive action and
|
3
|
+
comply with this code may result in punitive action and loss of privilege.
|
4
|
+
|
5
|
+
## CYHTFYW Code of Conduct:
|
4
6
|
|
5
|
-
CYHTFYW Code of Conduct:
|
6
7
|
1. Conduct yourself however the fuck you want.
|
data/README.md
CHANGED
@@ -1,40 +1,123 @@
|
|
1
1
|
# Hsss
|
2
2
|
|
3
|
-
|
3
|
+
Hash-Safe Script Splinterer, a Lua Script and hash embedder into C source.
|
4
|
+
Good for putting Redis Lua scripts in your C headers.
|
5
|
+
```
|
6
|
+
Usage: hsss [options] files
|
7
|
+
--struct [redis_lua_script_t] C struct name
|
8
|
+
--scripts [redis_lua_scripts] Scripts variable
|
9
|
+
--hashes [redis_lua_hashes] Hashes variable
|
10
|
+
--names [redis_lua_script_names] Script names variable
|
11
|
+
--count [redis_lua_scripts_count] integer script count variable
|
12
|
+
--no-count Omit script count variable
|
13
|
+
--each-macro [REDIS_LUA_SCRIPTS_EACH] Iterator macro
|
14
|
+
--no-each Omit the iterator macro
|
15
|
+
--no-parse Skip using luac to check script syntax
|
16
|
+
--prefix PREFIX Prefix default names with this
|
17
|
+
```
|
4
18
|
|
5
|
-
|
19
|
+
## Example
|
6
20
|
|
7
|
-
|
21
|
+
Let's say you have two scripts in directory `example/`:
|
8
22
|
|
9
|
-
|
23
|
+
`echo.lua`:
|
24
|
+
```lua
|
25
|
+
--echoes the first argument
|
26
|
+
redis.call('echo', ARGS[1])
|
10
27
|
|
11
|
-
```ruby
|
12
|
-
gem 'hsss'
|
13
28
|
```
|
14
29
|
|
15
|
-
|
16
|
-
|
17
|
-
|
30
|
+
`delete.lua`
|
31
|
+
```lua
|
32
|
+
--deletes first key
|
33
|
+
redis.call('del', KEYS[1])
|
18
34
|
|
19
|
-
|
35
|
+
```
|
20
36
|
|
21
|
-
|
37
|
+
running `hsss example/*.lua` outputs
|
38
|
+
```c
|
39
|
+
// don't edit this please, it was auto-generated by hsss
|
40
|
+
// https://github.com/slact/hsss
|
22
41
|
|
23
|
-
|
42
|
+
typedef struct {
|
43
|
+
//deletes first key
|
44
|
+
char *delete;
|
24
45
|
|
25
|
-
|
46
|
+
//echoes the first argument
|
47
|
+
char *echo;
|
26
48
|
|
27
|
-
|
49
|
+
} redis_lua_script_t;
|
28
50
|
|
29
|
-
|
51
|
+
static redis_lua_script_t redis_lua_hashes = {
|
52
|
+
"c6929c34f10b0fe8eaba42cde275652f32904e03",
|
53
|
+
"8f8f934c6049ab4d6337cfa53976893417b268bc"
|
54
|
+
};
|
30
55
|
|
31
|
-
|
56
|
+
static redis_lua_script_t redis_lua_script_names = {
|
57
|
+
"delete",
|
58
|
+
"echo",
|
59
|
+
};
|
32
60
|
|
33
|
-
|
61
|
+
static redis_lua_script_t redis_lua_scripts = {
|
62
|
+
//delete
|
63
|
+
"--deletes first key\n"
|
64
|
+
"redis.call('del', KEYS[1])\n",
|
34
65
|
|
35
|
-
|
66
|
+
//echo
|
67
|
+
"--echoes the first argument\n"
|
68
|
+
"redis.call('echo', ARGS[1])\n"
|
69
|
+
};
|
36
70
|
|
71
|
+
const int redis_lua_scripts_count=2;
|
72
|
+
#define REDIS_LUA_SCRIPTS_EACH(script_src, script_name, script_hash) \
|
73
|
+
for((script_src)=(char **)&redis_lua_scripts, (script_hash)=(char **)&redis_lua_hashes, (script_name)=(char **)&redis_lua_script_names; (script_src) < (char **)(&redis_lua_scripts + 1); (script_src)++, (script_hash)++, (script_name)++)
|
74
|
+
```
|
37
75
|
|
76
|
+
## Using in your C code
|
77
|
+
|
78
|
+
- `EVALSHA`:
|
79
|
+
```c
|
80
|
+
redisAsyncCommand(asyncContext, callback, data, "EVALSHA %s 0", redis_lua_hashes.script_name);
|
81
|
+
```
|
82
|
+
|
83
|
+
- iterator macro, loading scripts
|
84
|
+
```c
|
85
|
+
|
86
|
+
//privdata for error checking callback
|
87
|
+
typedef struct {
|
88
|
+
char *name;
|
89
|
+
char *hash;
|
90
|
+
} script_hash_and_name_t;
|
91
|
+
|
92
|
+
//error checking callback
|
93
|
+
static void redisLoadScriptCallback(redisAsyncContext *c, void *r, void *privdata) {
|
94
|
+
script_hash_and_name_t *hn = privdata;
|
95
|
+
redisReply *reply = r;
|
96
|
+
switch(reply->type) {
|
97
|
+
case REDIS_REPLY_ERROR:
|
98
|
+
printf("nchan: Failed loading redis lua script %s :%s", hn->name, reply->str);
|
99
|
+
break;
|
100
|
+
case REDIS_REPLY_STRING:
|
101
|
+
if(strcmp(reply->str, hn->hash)!=0) { //sha1 hash length is 40 chars
|
102
|
+
printf("nchan Redis lua script %s has unexpected hash %s (expected %s)", hn->name, reply->str, hn->hash);
|
103
|
+
}
|
104
|
+
break;
|
105
|
+
}
|
106
|
+
free(hn);
|
107
|
+
}
|
108
|
+
|
109
|
+
static void redisInitScripts(redisAsyncContext *c){
|
110
|
+
char **script, **script_name, **script_hash;
|
111
|
+
|
112
|
+
REDIS_LUA_SCRIPTS_EACH(script, script_name, script_hash) {
|
113
|
+
script_hash_and_name_t *hn = alloc(sizeof(*hn));
|
114
|
+
hn->name=*script_name;
|
115
|
+
hn->hash=*script_hash;
|
116
|
+
redisAsyncCommand(c, redisLoadScriptCallback, hn, "SCRIPT LOAD %s", *script);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
```
|
120
|
+
|
38
121
|
## License
|
39
122
|
|
40
123
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/hsss/version.rb
CHANGED
data/lib/hsss.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hsss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leo P.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|