Skip to content

Commit

Permalink
continue work on print
Browse files Browse the repository at this point in the history
  • Loading branch information
daTokenizer committed Nov 21, 2016
1 parent 4dfee11 commit 468fb17
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The module works by adding a new type to Redis -`DehydratorType`. It will be cea
* **Stream Coordination** - Make data from one stream wait for the corresponding data from another (preferebly using sliding-window style timing).
* **Event Rate Limitation** - Delay any event beyond current max throughput to the next available time slot, while preserving order.
* **Self Cleaning Claims-Check** - Store data for a well known period, without the need to search for it when it is expired or clear it from the data-store yourself.
* **Task Timer** - Assign actions and their respective payloads to a specific point in time.
* **Task Timer** - Postpone actions and their respective payloads to a specific point in time.

## What this repo includes:

Expand Down
63 changes: 49 additions & 14 deletions module.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ void printRedisStr(RedisModuleString *str, const char* name) {
printf("%s = %s\n", name, RedisModule_StringPtrLen(str, NULL));
}


char* string_append(char* a, const char* b)
{
char* retstr = RedisModule_Alloc(sizeof(a)+sizeof(b));
strcpy(retstr, a);
strcat(retstr, b);
// printf("printing: %s", retstr);
RedisModule_Free(a);
return retstr;
}

//##########################################################
//#
//# Linked List
Expand Down Expand Up @@ -233,29 +244,43 @@ ElementListNode* _listFind(ElementList* list, RedisModuleString* element_id)
}


void printNode(ElementListNode* node)
char* printNode(ElementListNode* node)
{
const char* element_id = RedisModule_StringPtrLen(node->element_id, NULL);
const char* element = RedisModule_StringPtrLen(node->element, NULL);
printf("[id=%s,elem=%s,ttl=%d,exp=%lld]", element_id, element, node->ttl, node->expiration); // TODO: remove
size_t element_id_len;
size_t element_len;
const char* element_id = RedisModule_StringPtrLen(node->element_id, &element_id_len);
const char* element = RedisModule_StringPtrLen(node->element, &element_len);
char* node_str = (char*)RedisModule_Alloc((element_id_len+element_len+50)*sizeof(char));
sprintf(node_str, "[id=%s,elem=%s,ttl=%d,exp=%lld]", element_id, element, node->ttl, node->expiration);
return node_str;

}


void printList(ElementList* list)
{
char* list_str = RedisModule_Alloc(32*sizeof(char));
ElementListNode* current = list->head;
// sprintf(list_str, "len=%d \nhead", list->len);
printf("len=%d \nhead", list->len);
// iterate over queue and find the element that has id = element_id
while(current != NULL)
{
list_str = string_append(list_str, "->");
printf("->");
printNode(current);


char* node_str = printNode(current);
printf("%s",node_str);
// list_str = string_append(list_str, node_str);
RedisModule_Free(node_str);

current = current->next; //move to next node
}
printf("\ntail->");
printNode(list->tail);
printf("\n");
printf("\ntail points to: %s",RedisModule_StringPtrLen(list->tail->element_id, NULL));
// list_str = string_append(list_str, "\ntail points to:");
// list_str = string_append(list_str, RedisModule_StringPtrLen(list->tail->element_id, NULL));
return list_str;
}


Expand Down Expand Up @@ -310,8 +335,9 @@ Dehydrator* validateDehydratorKey(RedisModuleCtx* ctx, RedisModuleKey* key, Redi
}
}

void printDehydrator(Dehydrator* dehydrator)
char* printDehydrator(Dehydrator* dehydrator)
{
char* dehy_str = "";
khiter_t k;

printf("\n======== timeout_queues =========\n");
Expand All @@ -321,11 +347,17 @@ void printDehydrator(Dehydrator* dehydrator)
{
ElementList* list = kh_value(dehydrator->timeout_queues, k);
printf(">>list: %d\n", kh_key(dehydrator->timeout_queues, k) );
printList(list);
// char* x = printList(list);
printList(list);
// printf(">>%s<<\n", x);
// RedisModule_Free(x);
// char* list_str = printList(list);
// dehy_str += list_str;
// free(list_str);
}
}

printf("\n======== element_nodes issues=========\n");
printf("\n======== element_nodes issues =========\n");
int found_problems = 0;
for (k = kh_begin(dehydrator->element_nodes); k != kh_end(dehydrator->element_nodes); ++k)
{
Expand All @@ -345,7 +377,9 @@ void printDehydrator(Dehydrator* dehydrator)
{
printf("no issues were found.\n");
}
printf("\n================================\n");
printf("================================\n");

return dehy_str;
}


Expand Down Expand Up @@ -612,9 +646,10 @@ int PrintCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
return REDISMODULE_OK;
}

printDehydrator(dehydrator);
char* dehy_str = printDehydrator(dehydrator);
RedisModule_CloseKey(key);
RedisModule_ReplyWithSimpleString(ctx, "DONE");
RedisModule_ReplyWithSimpleString(ctx, dehy_str);
// RedisModule_Free(dehy_str);
return REDISMODULE_OK;
}

Expand Down

0 comments on commit 468fb17

Please sign in to comment.