From 407263fcd013a9fda078b5864b86ecf755eeb25b Mon Sep 17 00:00:00 2001 From: theory Date: Mon, 17 Mar 2014 05:01:21 -0600 Subject: [PATCH] redis? --- init.js | 2 +- package.json | 3 ++- redis.sh | 14 ++++++++++++++ shots.js | 32 +++++++++++++++++++++++--------- test/blah.js | 26 ++++++++++++++++++++++++++ test/server.js | 3 ++- 6 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 redis.sh create mode 100644 test/blah.js diff --git a/init.js b/init.js index 6f433b7c..058428d2 100644 --- a/init.js +++ b/init.js @@ -13,7 +13,7 @@ opt.hook = { }) }; -opt.run = []; +opt.run = ['./test/server']; web(opt); console.log("Gun @ "+ opt.port); \ No newline at end of file diff --git a/package.json b/package.json index b338e7e3..9f8af195 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,9 @@ "theory": "~>0.2.5", "coalesce": "~>0.1.9b", "aws-sdk": "~>2.0.0", + "hiredis": "", "redis": "~>0.10.1", "mime": "~>1.2.11" } -, "main": "gun" +, "main": "shots" } \ No newline at end of file diff --git a/redis.sh b/redis.sh new file mode 100644 index 00000000..f5d86113 --- /dev/null +++ b/redis.sh @@ -0,0 +1,14 @@ +if [ -e redis-stable ]; +then + echo "redis already installed." +else + echo "installing redis" + curl -O http://download.redis.io/redis-stable.tar.gz + tar xvzf redis-stable.tar.gz + cd redis-stable + make + echo "redis installed" + cd .. +fi +cd redis-stable +src/redis-server \ No newline at end of file diff --git a/shots.js b/shots.js index 0e6bde52..7e1266ff 100644 --- a/shots.js +++ b/shots.js @@ -1,7 +1,29 @@ module.exports = require('theory') ('shot',function(a){ + require('child_process').exec('redis.sh', function(e, r){ + console.log(e,r); + }); + /* var redis = a.redis , client = redis.createClient(); + client.on('error', function(e){ + if(!(/ECONNREFUSED/).test(e)){ return } + if(redis.none){ return } + redis.path = '/usr/local/bin/redis-server'; + if(!(require('fs').existsSync||require('path').existsSync)(redis.path)){ + redis.none = true; + return; + } + if(process.env.gun_redis_lock){ return } + process.env.gun_redis_lock = process.pid; + console.log('gun', process.pid, 'starting redis'); + require('child_process').spawn(redis.path).on('exit',function(c,s){ + if(process.env.gun_redis_lock == process.pid){ + process.env.gun_redis_lock = ''; // 0 and false don't work, cause they are cast to strings! + } + }); + }); + */ return function(opt){ opt = opt || {}; opt.src = opt.src || ''; @@ -67,15 +89,7 @@ module.exports = require('theory') else { return 0 } } shot.start = function(){ - client.on('error', function(e){ - if(!(/ECONNREFUSED/).test(e)){ return } - console.log("gun starting redis"); - if(!opt.redis.path){ - if(!(require('fs').existsSync||require('path').existsSync)('/usr/local/bin/redis-server')){ - //path = - } - } - }); + }; shot.start(); return {gun: a.gun}; diff --git a/test/blah.js b/test/blah.js new file mode 100644 index 00000000..f08ee2d3 --- /dev/null +++ b/test/blah.js @@ -0,0 +1,26 @@ +module.exports=require('theory') +({name: 'blah' +, state: {way:'state', flow:-1} +, invincible: true +, dep: ['../shots'] +, init: function(a){ + console.log("BLAH"); + var blah = {}; + blah.put = function(m){ + console.log('stream', m); + } + blah.state = function(m){ + var w = blah.get(m); + console.log('state', w); + if(w){ + m.what.body = 1; + } + a.com.reply(m); + }; + blah.get = function(m){ + return !a.obj.empty(a(m,'what.form'))? a(m,'what.form') + : !a.obj.empty(a(m,'what.url.query'))? a(m,'what.url.query') + : false ; + }; + return blah; +}}); \ No newline at end of file diff --git a/test/server.js b/test/server.js index 79bb292d..bb0d5f0a 100644 --- a/test/server.js +++ b/test/server.js @@ -2,8 +2,9 @@ module.exports=require('theory') ({name: 'echo' , state: {way:'state', flow:-1} , invincible: true -//, dep: ['../gun'] +, dep: ['../shots'] , init: function(a){ + console.log("ECHO"); var echo = {}; echo.put = function(m){ console.log('stream', m);