Skip to content

Commit

Permalink
native: make the redis host/port configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
asmuth committed Mar 9, 2012
1 parent 5fb0706 commit 845cba3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



### todo

+ implement CosineInputMatrix
+ forbid ':' and '|' in item_ids
+ recommendify::base no key part issue
+ make max_row length configurable

32 changes: 27 additions & 5 deletions ext/recommendify.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdlib.h>
#include <hiredis/hiredis.h>

#include "version.h"
#include "version.h"
#include "cc_item.h"
#include "jaccard.c"
#include "cosine.c"
Expand All @@ -27,7 +27,11 @@ int main(int argc, char **argv){
int batch_size = 200; /* FIXPAUL: make option */
int maxItems = 50; /* FIXPAUL: make option */


struct {
char host[1024];
int port;
} redis_addr;

/* option parsing */
if(argc < 2)
return print_usage(argv[0]);
Expand All @@ -44,25 +48,43 @@ int main(int argc, char **argv){
if(!similarityFunc){
printf("invalid option: %s\n", argv[1]);
return 1;
} else if(argc != 4){
} else if(argc < 4 || argc > 5){
printf("wrong number of arguments\n");
print_usage(argv[0]);
return 1;
}

redisPrefix = argv[2];
itemID = argv[3];
redis_addr.host[0] = 0;

/* configure redis location */
if(argc > 4){
char* has_port = strchr(argv[4], ':');
if(has_port){
strncpy(redis_addr.host, argv[4], strlen(argv[4]) - strlen(has_port));
redis_addr.host[strlen(argv[4]) - strlen(has_port)] = 0;
redis_addr.port = atoi(has_port + 1);
} else {
strncpy(redis_addr.host, argv[4], sizeof(redis_addr.host));
}
}

/* default redis location */
if(strlen(redis_addr.host) == 0)
strcpy(redis_addr.host, "localhost");

if(!redis_addr.port)
redis_addr.port = 6379;

/* connect to redis */
struct timeval timeout = { 1, 500000 };
c = redisConnectWithTimeout("127.0.0.2", 6379, timeout);
c = redisConnectWithTimeout(redis_addr.host, redis_addr.port, timeout);

if(c->err){
printf("connection to redis failed: %s\n", c->errstr);
return 1;
}


/* get item count */
reply = redisCommand(c,"HGET %s:items %s", redisPrefix, itemID);
Expand Down

0 comments on commit 845cba3

Please sign in to comment.