Skip to content

Commit

Permalink
refactored classes and file naming
Browse files Browse the repository at this point in the history
  • Loading branch information
petrbela committed Apr 28, 2012
1 parent 6fdc16b commit a57495f
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 48 deletions.
4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
redis-dart

A Dart library for the Redis key-value store.

5 changes: 0 additions & 5 deletions lib/Connection.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#library('Connection');
#import("dart:io");
#import("dart:utf");
#import("ServerConfig.dart");

// Char constants
int CR = 13;
int LF = 10;
Expand Down
141 changes: 133 additions & 8 deletions lib/redis.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,134 @@
#library("redis");
#import("dart:io");
#import("dart:utf");
#import("Connection.dart");
#import("ServerConfig.dart");
#import("../third_party/log4dart/LogLib.dart");
#source("redis_interfaces.dart");
#source("utils.dart");
interface Redis default RedisImpl {

// ************ Keys Commands ************
// http://redis.io/commands#generic

Future<Object> Del(key);

Future<Object> Dump(key);

Future<Object> Exists(key);

Future<Object> Expire(key, seconds);

Future<Object> Expireat(key, timestamp);

Future<Object> Keys(pattern);

Future<Object> Migrate(host, port, key, destination_db, timeout);

Future<Object> Move(key, db);

Future<Object> ObjectCmd(subcommand, [arguments]);

Future<Object> Persist(key);

Future<Object> Pexpire(key, milliseconds);

Future<Object> Pexpireat(key, milliseconds_timestamp);

Future<Object> Pttl(key);

Future<Object> RandomKey();

Future<Object> Rename(key, newkey);

Future<Object> Renamenx(key, newkey);

Future<Object> Restore(key, ttl, serialized_value);

Future<Object> Sort(key);

Future<Object> TTL(key);

Future<Object> Type(key);


// ************ String commands ************
// http://redis.io/commands#string

/**
* Append a value to a key
* http://redis.io/commands/append
*/
Future<Object> Append(String key, String value);

/**
* Decrement the integer value of a key by one
* http://redis.io/commands/decr
*/
Future<Object> Decr(String key);

/**
* Get the value of a key
* http://redis.io/commands/get
*/
Future<Object> Get(String key);

/**
* Set the string value of a key
* http://redis.io/commands/set
*/
Future<Object> Set(String key, String value);


// ************ Connections Commands ************
// http://redis.io/commands#connection

Auth(password);

Echo(message);

Ping();

Quit();

Select(num index);


// ************ Server Commands ************
// http://redis.io/commands#server

Future<Object> Bgrewriteaof();

Future<Object> BackgroundSave();

Future<Object> ConfigGet(parameter);

Future<Object> ConfigSet(parameter, value);

Future<Object> ConfigResetstat();

Future<Object> DbSize();

Future<Object> DebugObject(key);

Future<Object> DebugSegfault();

Future<Object> FlushAll();

Future<Object> FlushDb();

Future<Object> Info();

Future<Object> LastSave();

Future<Object> Monitor();

Future<Object> Save();

Future<Object> Shutdown();

Future<Object> ShutdownSave();

Future<Object> ShutdownNoSave();

Future<Object> SlaveOf(host, port);

Future<Object> SlowLog(subcommand, [argument]);

Future<Object> Sync();

Future<Object> Time();
}

34 changes: 20 additions & 14 deletions lib/redis_interfaces.dart → lib/redis_implementation.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
interface redis {

}
#library("redis");
#import("dart:io");
#import("dart:utf");
#import("../third_party/log4dart/LogLib.dart");
#source("redis.dart");
#source("utils.dart");
#source("server_config.dart");
#source("connection.dart");


class redisImpl implements redis {

class RedisImpl implements Redis {

ServerConfig serverConfig;
Connection connection;

redisImpl([this.serverConfig]) {
RedisImpl([this.serverConfig]) {
if (serverConfig === null) {
serverConfig = new ServerConfig();
}
Expand Down Expand Up @@ -46,19 +50,21 @@ class redisImpl implements redis {
// return SendCommand ("SAVE");
// }

// ************ String commands ************
// http://redis.io/commands#string

Future<Object> Get(key) {
return SendCommand("GET $key\r\n");
Future<Object> Get(String key) {
return SendCommand("GET", [key]);
}

Future<Object> Set(key, value) {
return SendCommand("SET ${key} ${value}\r\n");
Future<Object> Set(String key, String value) {
return SendCommand("SET", [key, value]);
}


/*
Keys Commands
*/
// ************ Keys Commands ************
// http://redis.io/commands#generic

Future<Object> Del(key) {
var k = Strings.join(key, " ");
return SendCommand("DEL $k");
Expand Down
4 changes: 1 addition & 3 deletions lib/ServerConfig.dart → lib/server_config.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#library("ServerConfig");

class ServerConfig{
class ServerConfig {
String host;
int port;
int db;
Expand Down
35 changes: 35 additions & 0 deletions tests/RedisTest.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#library("redis_tests");

#import("../lib/redis.dart");
#import("dart:io");
#import('dart:builtin');
#import('../third_party/testing/unittest/unittest_vm.dart');

void testSet(Redis client) {
client.set("key1", "value1");
Expect.equals("value1", client.get("key1"));

Future f = conn.connect();
f.then((connected) {
Expect.equals(false, connected);
});

f.handleException((o) {
callbackDone();
//conn.close();
return true;
});
}

void testGet() {

}

void main() {
Utils.setVerboseState();
group("Connection tests:", () {
asyncTest("Test get value", 1, testGet);
asyncTest("Test set value", 1, testSet);
// asyncTest("Test socket failed connection",1, connectionFailTest);
});
}
18 changes: 0 additions & 18 deletions tests/log.txt

This file was deleted.

0 comments on commit a57495f

Please sign in to comment.