redis - added mget and multi, finished initial topics listview on home page, finished get topics method calls

v1.18.x
psychobunny 12 years ago
parent 877219cb58
commit a16f72e11c

@ -42,7 +42,7 @@
height: 350px;
left: 0px;
bottom: 0px;
opacity: 0.8;
background: white;
}
#post_window input {
@ -68,15 +68,40 @@
}
#post_window .post-title-container {
opacity: 0.8;
height: 50px;
}
#post_window .post-content-container {
opacity: 0.8;
background: #000;
width: 100%;
height: 300px;
}
.topic-container {
list-style-type: none;
padding: 0;
margin: 0;
border: 1px solid #eee;
margin-top: 50px;
}
.topic-container li.topic-row:nth-child(odd) {
background-color:#fdfdfd;
}
.topic-container li.topic-row:nth-child(even) {
background-color:#fff;
}
.topic-container li.topic-row {
cursor: pointer;
border-bottom: 1px solid #eee;
padding: 10px;
}
.topic-container li.topic-row:hover {
background-color: #eee;
}
</style>
</head>

@ -1,5 +1,12 @@
<button id="new_post" class="btn btn-primary btn-large">New Post</button>
<ul class="topic-container">
<!-- BEGIN topics -->
<li class="topic-row">
<h4>{topics.title}</h4>
<p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} replies.</p>
</li>
<!-- END topics -->
</ul>
<script type="text/javascript">
var new_post = document.getElementById('new_post');
new_post.onclick = function() {

@ -33,6 +33,16 @@
});
};
RedisDB.mget = function(keys, callback, error_handler) {
db.mget(keys, function(error, data) {
return_handler(error, data, callback, error_handler);
});
};
RedisDB.multi = function() {
return db.multi();
}
RedisDB.del = function(key, callback) {
db.del(key);
}

@ -62,7 +62,7 @@ var fs = require('fs');
for (var d in data) {
if (data.hasOwnProperty(d)) {
if (data[d] instanceof String) {
if (data[d] instanceof String || data[d] === null) {
continue;
} else if (data[d].constructor == Array) {
namespace += d;

@ -12,23 +12,74 @@ var RDB = require('./redis.js'),
// *tid:1:uid
// *tid:1:posts (array of pid)
// *tid:1:timestamp
// *uid:1:topics
// *uid:1:tozpics
// *topic:slug:how-to-eat-chicken:tid
Topics.get_by_category = function(category, start, end) {
Topics.get_by_category = function(callback, category, start, end) {
}
Topics.get = function(start, end) {
Topics.generate_forum_body = function(callback, start, end) {
var forum_body = global.templates['home'];
Topics.get(function(data) {
console.log({'topics': data});
forum_body = forum_body.parse({'topics': data});
callback(forum_body);
}, start, end);
};
Topics.get = function(callback, start, end) {
if (start == null) start = 0;
if (end == null) end = start + 10;
RDB.lrange('topics:tid', start, end, function() {
global.socket.emit
RDB.lrange('topics:tid', start, end, function(tids) {
var title = [],
uid = [],
timestamp = [],
posts = [];
for (var i=0, ii=tids.length; i<ii; i++) {
title.push('tid:' + tids[i] + ':title');
uid.push('tid:' + tids[i] + ':uid');
timestamp.push('tid:' + tids[i] + ':timestamp');
posts.push('tid:' + tids[i] + ':posts');
}
/*RDB.mget(topic, function(topic_data) {
callback(topic_data);
});*/
RDB.multi()
.mget(title)
.mget(uid)
.mget(timestamp)
.mget(posts)
.exec(function(err, replies) {
title = replies[0];
uid = replies[1];
timestamp = replies[2];
posts = replies[3];
var topics = [];
for (var i=0, ii=title.length; i<ii; i++) {
topics.push({
'title' : title[i],
'uid' : uid[i],
'timestamp' : timestamp[i],
'posts' : posts[i],
'post_count' : 0
});
}
callback(topics);
});
});
}

@ -40,11 +40,11 @@ var express = require('express'),
// app.use(express.methodOverride());
app.get('/', function(req, res) {
//global.modules.topics.get(function() {
// res.send(templates['header'] + templates['home'] + templates['footer']);
//})
global.modules.topics.generate_forum_body(function(forum_body) {
res.send(templates['header'] + forum_body + templates['footer']);
})
res.send(templates['header'] + templates['home'] + templates['footer']);
//res.send(templates['header'] + templates['home'] + templates['footer']);
});
app.get('/login', function(req, res) {

Loading…
Cancel
Save