Skip to content

Commit 1999ef8

Browse files
committed
store revision list in keyPrefix:revisions
fix #28
1 parent e2a0850 commit 1999ef8

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ So, if the `keyPrefix` was configured to be `my-app:index` and there had been 3
181181
$ redis-cli
182182

183183
127.0.0.1:6379> KEYS *
184-
1) my-app:index
184+
1) my-app:index:revisions
185185
2) my-app:index:9ab2021411f0cbc5ebd5ef8ddcd85cef
186186
3) my-app:index:499f5ac793551296aaf7f1ec74b2ca79
187187
4) my-app:index:f769d3afb67bd20ccdb083549048c86c
@@ -195,7 +195,7 @@ $ ember deploy:activate f769d3afb67bd20ccdb083549048c86c
195195
$ redis-cli
196196

197197
127.0.0.1:6379> KEYS *
198-
1) my-app:index
198+
1) my-app:index:revisions
199199
2) my-app:index:9ab2021411f0cbc5ebd5ef8ddcd85cef
200200
3) my-app:index:499f5ac793551296aaf7f1ec74b2ca79
201201
4) my-app:index:f769d3afb67bd20ccdb083549048c86c

lib/redis.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ module.exports = CoreObject.extend({
7777

7878
_listRevisions: function(keyPrefix) {
7979
var client = this._client;
80-
return client.zrevrange(keyPrefix, 0, -1);
80+
var listKey = keyPrefix + ':revisions';
81+
return client.zrevrange(listKey, 0, -1);
8182
},
8283

8384
_validateRevisionKey: function(revisionKey, revisions) {
@@ -110,7 +111,8 @@ module.exports = CoreObject.extend({
110111
_updateRecentUploadsList: function(keyPrefix, revisionKey) {
111112
var client = this._client;
112113
var score = new Date().getTime();
113-
return client.zadd(keyPrefix, score, revisionKey);
114+
var listKey = keyPrefix + ':revisions';
115+
return client.zadd(listKey, score, revisionKey);
114116
},
115117

116118
_activeRevision: function(keyPrefix) {
@@ -120,9 +122,10 @@ module.exports = CoreObject.extend({
120122

121123
_trimRecentUploadsList: function(keyPrefix, maxEntries) {
122124
var client = this._client;
125+
var listKey = keyPrefix + ':revisions';
123126

124127
return Promise.hash({
125-
revisionsToBeRemoved: client.zrange(keyPrefix, 0, -(maxEntries + 1)),
128+
revisionsToBeRemoved: client.zrange(listKey, 0, -(maxEntries + 1)),
126129
current: this._activeRevision(keyPrefix)
127130
}).then(function(results) {
128131
var revisions = results.revisionsToBeRemoved;
@@ -133,7 +136,7 @@ module.exports = CoreObject.extend({
133136
revisions.forEach(function(revision) {
134137
if (revision !== current) {
135138
client.del(keyPrefix + ":" + revision);
136-
client.zrem(keyPrefix, revision);
139+
client.zrem(listKey, revision);
137140
}
138141
});
139142
});

tests/helpers/fake-redis-client.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ module.exports = CoreObject.extend({
1111
set: function() { },
1212
del: function() { },
1313
zadd: function(key, score , tag) {
14-
this.recentRevisions.push(key + ':' + tag);
14+
var prefix = key.replace(':revisions','');
15+
this.recentRevisions.push(prefix + ':' + tag);
1516
},
16-
zrem: function(val,revision) {
17-
var i = this.recentRevisions.indexOf(revision)
17+
zrem: function(key, revision) {
18+
var i = this.recentRevisions.indexOf(revision);
1819
this.recentRevisions.splice(i,1);
1920
},
2021
zrange: function() {

tests/unit/lib/redis-nodetest.js

+14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ describe('redis', function() {
3232
},
3333
set: function(key, value) {
3434
fileUploaded = true;
35+
},
36+
zadd: function(key, value) {
37+
assert(key.match(/:revisions$/));
38+
},
39+
zrange: function(key, value) {
40+
assert(key.match(/:revisions$/));
3541
}
3642
})));
3743

@@ -87,6 +93,10 @@ describe('redis', function() {
8793
},
8894
zrange: function() {
8995
return this.recentRevisions.slice(0,2);
96+
},
97+
zrem: function(key) {
98+
assert(key.match(/:revisions$/));
99+
return this._super.apply(this, arguments);
90100
}
91101
})));
92102

@@ -233,6 +243,10 @@ describe('redis', function() {
233243
var redis = new Redis({}, new FakeRedis(FakeClient.extend({
234244
get: function() {
235245
return currentRevision;
246+
},
247+
zrevrange: function(key) {
248+
assert(key.match(/:revisions$/));
249+
return this._super.apply(this, arguments);
236250
}
237251
})));
238252

0 commit comments

Comments
 (0)