Skip to content

Loading…

Added redis handler #8

Closed
wants to merge 3 commits into from

5 participants

@DerKobe

Hi Pita,

I wrote a handler for the redis key/value store. The benchmark test looked good. I used it for etherpad-lite.

Cheers,
Kobe

@Pita
Owner

return error with the callback please

@Pita
Owner

debug message?

@Pita
Owner

also, please add the redis module to package.json and put default settings into defaultTestSettings.js

@DerKobe

I hope everything's fine now.

@Mic92

@DerKobe which configuration do you use to run it with etherpad-light?

@DerKobe

Take a look at https://github.com/DerKobe/ueberDB/blob/master/redis_db.js
There is an example of the etherpad-lite config block in the comments.

@JohnMcLear JohnMcLear closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 7, 2012
  1. Added redis handler

    Philip Claren committed
Showing with 93 additions and 4 deletions.
  1. +1 −0 defaultTestSettings.js
  2. +5 −4 package.json
  3. +87 −0 redis_db.js
View
1 defaultTestSettings.js
@@ -2,3 +2,4 @@ exports["mysql"] = {"user":"etherpadlite", host: "localhost", "password":"etherp
exports["postgres"] = {"user":"etherpadlite", host: "localhost", "password":"etherpadlite", database: "etherpadlite"};
exports["sqlite"] = {filename:"var/sqlite3.db"};
exports["dirty"] = {filename:"var/dirty.db"};
+exports["redis"] = {"host":"localhost", "port":6379, "database":0};
View
9 package.json
@@ -5,10 +5,11 @@
"keywords" : ["database", "keyvalue"],
"author" : "Peter 'Pita' Martischka <petermartischka@googlemail.com>",
"dependencies" : {
- "mysql" : "0.9.5",
- "dirty" : "0.9.6",
- "async" : "0.1.15",
- "channels": "0.0.2"
+ "mysql" : "0.9.5",
+ "dirty" : "0.9.6",
+ "async" : "0.1.15",
+ "channels" : "0.0.2",
+ "node-redis": "0.1.3"
},
"devDependencies": {
"log4js" : "0.4.1"
View
87 redis_db.js
@@ -0,0 +1,87 @@
+/**
+ * 2011 Peter 'Pita' Martischka
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS-IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * 2012 Philip 'DerKobe' Claren
+ *
+ * Install node-redis by mranney
+ * https://github.com/mranney/node_redis
+ *
+ * Default settings for etherpad-lite:
+ * ...
+ * "dbType" : "redis",
+ * "dbSettings" : {
+ * "host" : "localhost",
+ * "port" : 6379,
+ * "database" : 0
+ * },
+ * ...
+ *
+ */
+
+var redis = require("redis");
+
+exports.database = function(settings) {
+ this.client = null;
+
+ if(!settings) settings = {};
+ if(!settings.database) settings.database = 0;
+ if(!settings.host) settings.host = '127.0.0.1';
+ if(!settings.port) settings.port = 6379;
+
+ this.settings = settings;
+}
+
+exports.database.prototype.init = function(callback) {
+ this.client = redis.createClient(this.settings.port, this.settings.host);
+
+ this.client.database = this.settings.database;
+
+ this.client.on("error", callback);
+ this.client.on("connect", function() {
+ this.select(this.database, callback);
+ });
+}
+
+exports.database.prototype.get = function (key, callback) {
+ this.client.get(key, callback);
+}
+
+exports.database.prototype.set = function (key, value, callback) {
+ this.client.set(key,value,callback);
+}
+
+exports.database.prototype.remove = function (key, callback) {
+ this.client.del(key,callback);
+}
+
+exports.database.prototype.doBulk = function (bulk, callback) {
+ var multi = this.client.multi();
+
+ for(var i in bulk) {
+ if(bulk[i].type == "set") {
+ multi.set(bulk[i].key, bulk[i].value);
+ } else if(bulk[i].type == "remove") {
+ multi.del(bulk[i].key);
+ }
+ }
+
+ multi.exec(callback);
+}
+
+exports.database.prototype.close = function(callback) {
+ this.client.end(callback);
+}
Something went wrong with that request. Please try again.