Last active
August 29, 2015 14:04
-
-
Save fatihky/98d10c64a667e33fac38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = ()-> | |
S = this | |
if(!S.lobi) | |
null | |
c.lrange 'okey:' + S.lobi + ':odalar', 0, -1, (h, s)-> | |
if(h) | |
false | |
if(s.length == 0) | |
S.emit 'oda-listesi-sonuc', html: oda_listesi {} | |
odalar = [] | |
for i in s | |
odalar.push 'okey:' + S.lobi + ':odalar:' + i | |
c.mget odalar, (h2, s2)-> | |
if(h2) | |
false | |
if(s2.length == 0) | |
S.emit 'oda-listesi-sonuc', { html: oda_listesi {} } | |
odalar = [] | |
for i in s2 | |
odalar.push JSON.parse( s2[i] ) | |
console.log 'odalar: ' | |
console.dir odalar | |
S.emit 'oda-listesi-sonuc', { html: oda_listesi { odalar: odalar } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var c = require("redis").createClient(); | |
var oda_listesi = require("swig").compileFile('./sayfalar/sayfa-parcalari/oda-listesi.html'); | |
// SCRIPT LOAD "local a = {} \n local i = 0 \nfor i = 1, #KEYS, 1 do a[i] = 'okey:' .. ARGV[1] .. ':odalar:' .. KEYS[i] end return a" | |
// SCRIPT LOAD "local a = {} \n local o = {} \n local i = 0 \n o = redis.call('lrange', ARGV[1], 0, -1) \nfor i = 1, #o, 1 do a[i] = 'okey:' .. ARGV[1] .. ':odalar:' .. o[i] end return a" | |
//SCRIPT LOAD "local a = {} \n local o = {} \n local i = 0 \n o = redis.call('lrange', 'okey:' .. ARGV[1] .. ':odalar', 0, -1) \nfor i = 1, #o, 1 do a[i] = redis.call('get', 'okey:' .. ARGV[1] .. ':odalar:' .. o[i]) end return a" | |
var lua_fn = "local a = {} \n local o = {} \n local i = 0 \n o = redis.call('lrange', 'okey:' .. ARGV[1] .. ':odalar', 0, -1) \n for i = 1, #o, 1 do a[i] = redis.call('get', 'okey:' .. ARGV[1] .. ':odalar:' .. o[i]) end return a"; | |
var sha; | |
c.send_command('script', ['load', lua_fn], function(h, s){ | |
sha = s; | |
c.send_command('evalsha', [sha, 0, 'genel'], function(h2, s2) { | |
if(h) return; | |
console.log('sonuç: '); | |
console.dir(s2); | |
}); | |
}); | |
// yenisi | |
module.exports = function() | |
{ | |
var S = this; | |
if(!S.lobi) return; | |
c.send_command('evalsha', [sha, 0, S.lobi], function(h, s) | |
{ | |
if(h) return; | |
if(s.length === 0) | |
return S.emit('oda-listesi-sonuc', {html: oda_listesi({})}); | |
var odalar = []; | |
for(var i = 0; i < s.length; i++) | |
odalar[i] = JSON.parse(s[i]); | |
S.emit('oda-listesi-sonuc', {html: oda_listesi({odalar: odalar})}); | |
}); | |
}; | |
// eskisi | |
module.exports = function() | |
{ | |
var S = this; | |
if(!S.lobi) return; | |
c.lrange('okey:' + S.lobi + ':odalar', 0, -1, function(h, s) | |
{ | |
if(h) return; | |
if(s.length === 0) | |
return S.emit('oda-listesi-sonuc', { html: oda_listesi({}) }); | |
var odalar = []; | |
for(var i = 0; i < s.length; i++) | |
odalar.push( 'okey:' + S.lobi + ':odalar:' + s[i]); | |
c.mget(odalar, function(h2, s2) | |
{ | |
if(h2) return; | |
if(s2.length === 0) | |
return S.emit('oda-listesi-sonuc', { html: oda_listesi({}) }); | |
odalar = []; | |
for(var i = 0; i < s2.length; i++) | |
odalar.push( JSON.parse( s2[i] ) ); | |
console.log('odalar: '); | |
console.dir(odalar); | |
S.emit('oda-listesi-sonuc', { html: oda_listesi( { odalar: odalar } ) }); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment