Permalink
Browse files

Added EXPIREAT and TTL

  • Loading branch information...
tj committed Apr 15, 2011
1 parent 27f1231 commit 5402ef4e2cb93b2da00e4f51d71ee39c3be700d6
Showing with 31 additions and 0 deletions.
  1. +31 −0 lib/commands/keys.js
View
@@ -12,6 +12,37 @@
var utils = require('../utils')
, string = utils.string;
+/**
+ * EXPIREAT <key> <seconds>
+ */
+
+exports.expireat = function(client, key, seconds){
+ var key = string(key)
+ , obj = this.db.data[key];
+
+ if (obj) {
+ obj.ttl = +string(seconds);
+ client.bool(true);
+ } else {
+ client.bool(false);
+ }
+};
+
+/**
+ * TTL <key>
+ */
+
+exports.ttl = function(client, key){
+ var key = string(key)
+ , obj = this.db.data[key];
+
+ if (obj && 'number' == typeof obj.ttl) {
+ client.int(obj.ttl - Date.now());
+ } else {
+ client.nil();
+ }
+};
+
/**
* TYPE <key>
*/

0 comments on commit 5402ef4

Please sign in to comment.