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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c214ad328e8c64a680d183de71a3d70ecfc4033e
4
- data.tar.gz: 8f94f9e93cceb204226fdfbe975d2d12473d5814
3
+ metadata.gz: 487fa212d82812cc8a4857fa40ac9c187f24655f
4
+ data.tar.gz: adcd2bfd44090494e15c4c5e1244136cfe1597a4
5
5
  SHA512:
6
- metadata.gz: 58c666e386a44a976090f939b9c88006909f3ab3cb2fb6f31a47294bf4193298b2e5af67195fbe2cc83f9cb4bad98c8b30f8f8627fcec05d2bb9bbfd196efdec
7
- data.tar.gz: 36eb952a2a3ad64a5481895a715cecad71d10a1c0a9f534008bd1b5640ff6ce434334a29d1f0658464adbbdb2649ab3ace0b3c863e8858037c81dc56b46be992
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 gem is
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 angry bees.
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hsss`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
19
+ ## Example
6
20
 
7
- ## Installation
21
+ Let's say you have two scripts in directory `example/`:
8
22
 
9
- Add this line to your application's Gemfile:
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
- And then execute:
16
-
17
- $ bundle
30
+ `delete.lua`
31
+ ```lua
32
+ --deletes first key
33
+ redis.call('del', KEYS[1])
18
34
 
19
- Or install it yourself as:
35
+ ```
20
36
 
21
- $ gem install hsss
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
- ## Usage
42
+ typedef struct {
43
+ //deletes first key
44
+ char *delete;
24
45
 
25
- TODO: Write usage instructions here
46
+ //echoes the first argument
47
+ char *echo;
26
48
 
27
- ## Development
49
+ } redis_lua_script_t;
28
50
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+ static redis_lua_script_t redis_lua_hashes = {
52
+ "c6929c34f10b0fe8eaba42cde275652f32904e03",
53
+ "8f8f934c6049ab4d6337cfa53976893417b268bc"
54
+ };
30
55
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+ static redis_lua_script_t redis_lua_script_names = {
57
+ "delete",
58
+ "echo",
59
+ };
32
60
 
33
- ## Contributing
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
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hsss.
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
@@ -1,3 +1,3 @@
1
1
  module Hsss
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/hsss.rb CHANGED
@@ -46,7 +46,8 @@ module Hsss
46
46
  end
47
47
 
48
48
  @cout= <<-EOS.gsub(/^ {8}/, '')
49
- //don't edit this please, it was auto-generated
49
+ // don't edit this please, it was auto-generated by hsss
50
+ // https://github.com/slact/hsss
50
51
 
51
52
  typedef struct {
52
53
  %s
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
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-16 00:00:00.000000000 Z
11
+ date: 2016-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler