Skip to content
Browse files

[slide] added .expire() call on slideshow key

  • Loading branch information...
1 parent bb9c99f commit b2010a0462988e7c011e2553cce3d87119d0717e @indutny committed
Showing with 18 additions and 0 deletions.
  1. +3 −0 lib/slides.js
  2. +10 −0 lib/slides/consts.js
  3. +5 −0 lib/slides/slide.js
View
3 lib/slides.js
@@ -9,6 +9,9 @@ var slides = exports;
// Utils
exports.utils = require('./slides/utils');
+// Consts
+exports.consts = require('./slides/consts');
+
// Slideshow
exports.slideshow = require('./slides/slideshow');
View
10 lib/slides/consts.js
@@ -0,0 +1,10 @@
+/**
+ * Slides App
+ *
+ * - Consts
+ */
+
+var consts = exports;
+
+/** @const */
+consts.POS_EXPIRE = 3600 * 24;
View
5 lib/slides/slide.js
@@ -8,6 +8,7 @@ var slide = exports;
var mongoose = require('mongoose'),
slides = require('../slides'),
+ consts = require('../slides').consts,
slideshow = slides.slideshow;
/**
@@ -57,8 +58,10 @@ slide.routes = function(app, redis) {
Slide.find(query, function(err, slides) {
if (err) return res.jsonError(err);
if (!slides) return res.json(404);
+
redis.get('slideshow.' + slideshow._id + '.current', function(err, num) {
if (err) return res.jsonError(err);
+
res.json({
current: +(num || 0),
slides: slides.map(function(slide) {
@@ -70,6 +73,7 @@ slide.routes = function(app, redis) {
})
});
});
+
});
});
});
@@ -89,6 +93,7 @@ slide.routes = function(app, redis) {
var index = Math.max(0, req.body.index);
redis.set(key, index);
+ redis.expire(key, consts.POS_EXPIRE);
next(index);
} else if (req.body.delta) {
redis.get(key, function(err, value) {

0 comments on commit b2010a0

Please sign in to comment.
Something went wrong with that request. Please try again.