-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
3,386 additions
and
601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
test | ||
test | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.o | ||
*.a | ||
*.so | ||
*.db | ||
.vscode | ||
lib/rmutil/test_vector | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
include variables.include | ||
|
||
all: clean build | ||
|
||
docker-build: | ||
docker build . -f ./docker/Dockerfile -t $(DOCKER_IMAGE) | ||
docker-rebuild: | ||
docker build . --no-cache -f ./docker/Dockerfile -t $(DOCKER_IMAGE) | ||
|
||
build: | ||
cd redis-filtered-sort && $(MAKE) all | ||
|
||
clean: | ||
cd redis-filtered-sort && $(MAKE) $@ | ||
|
||
deps: jansson | ||
|
||
|
||
clean-deps: | ||
rm -rf $(JANSSON_LIBDIR)/* | ||
|
||
jansson: jansson_src jansson_configure | ||
(cd $(JANSSON_LIBDIR) && make CFLAGS='$(CFLAGS)') | ||
|
||
jansson_configure: | ||
(cd $(JANSSON_LIBDIR) && ./configure) | ||
|
||
jansson_clean: | ||
(cd $(JANSSON_LIBDIR) && make clean) | ||
|
||
jansson_src: $(JANSSON_LIBDIR)/src/jansson.h | ||
|
||
$(JANSSON_LIBDIR)/src/jansson.h: | ||
wget -O- $(JANSSON_LINK) | tar xvz --directory=$(JANSSON_LIBDIR) --strip-components=1 jansson-$(JANSSON_VERSION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM alpine AS build-mod | ||
RUN apk add --no-cache --virtual .build-deps \ | ||
coreutils \ | ||
gcc \ | ||
linux-headers \ | ||
make \ | ||
musl-dev \ | ||
&& apk add \ | ||
bash | ||
RUN mkdir /src | ||
WORKDIR /src | ||
|
||
ADD . /src/ | ||
RUN make deps && make | ||
|
||
FROM redis:5.0.5-alpine | ||
COPY --from=build-mod /src/redis-filtered-sort/filter_module.so /usr/local/lib/redis_filtered_sort.so | ||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
CMD ["redis-server", "--loadmodule", "/usr/local/lib/redis_filtered_sort.so"] | ||
EXPOSE 6379 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
include ../variables.include | ||
|
||
#override path defined in variables | ||
JANSSON_LIBDIR=../lib/jansson | ||
|
||
ifndef RM_INCLUDE_DIR | ||
RM_INCLUDE_DIR=../lib/ | ||
endif | ||
|
||
ifndef RMUTIL_LIBDIR | ||
RMUTIL_LIBDIR=../lib/rmutil | ||
endif | ||
|
||
SOURCEDIR=$(shell pwd -P) | ||
CC_SOURCES = $(wildcard $(SOURCEDIR)/*.c) | ||
CC_OBJECTS = $(patsubst $(SOURCEDIR)/%.c, $(SOURCEDIR)/%.o, $(CC_SOURCES)) | ||
|
||
all: rmutil $(CC_OBJECTS) filter_module.so | ||
rmutil: FORCE | ||
$(MAKE) -C $(RMUTIL_LIBDIR) | ||
|
||
filter_module.so: $(CC_OBJECTS) | ||
$(LD) -o $@ $(CC_OBJECTS) $(SHOBJ_LDFLAGS) $(LIBS) -L$(RMUTIL_LIBDIR) -L$(JANSSON_LIBDIR)/src/.libs -lrmutil -lpthread -lc -Bstatic -ljansson | ||
|
||
clean: | ||
rm -rf *.xo *.so *.o | ||
cd $(RMUTIL_LIBDIR) && make clean | ||
|
||
FORCE: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "filter_module.h" | ||
#include "fsort.h" | ||
#include "fsort_utils.h" | ||
|
||
int FSortBust_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { | ||
RedisModule_AutoMemory(ctx); | ||
|
||
if (argc <3 || argc > 4 ) { | ||
return RedisModule_WrongArity(ctx); | ||
} | ||
|
||
pthread_t tid; | ||
RedisModuleBlockedClient *bc = RedisModule_BlockClient(ctx,NULL,NULL,NULL,0); | ||
|
||
void **targ = RedisModule_Alloc(sizeof(void*)*3); | ||
targ[0] = bc; | ||
targ[1] = (void*)(unsigned long) argc; | ||
targ[2] = (void*)(RedisModuleString **)argv; | ||
|
||
if (pthread_create(&tid,NULL,fsort_bust_thread,targ) != 0) { | ||
RedisModule_AbortBlock(bc); | ||
return RedisModule_ReplyWithError(ctx,"-ERR Can't start thread"); | ||
} | ||
|
||
return REDISMODULE_OK; | ||
} | ||
|
||
int FSortAggregate_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { | ||
RedisModule_AutoMemory(ctx); | ||
|
||
if (argc != 4) { | ||
return RedisModule_WrongArity(ctx); | ||
} | ||
|
||
pthread_t tid; | ||
RedisModuleBlockedClient *bc = RedisModule_BlockClient(ctx,NULL,NULL,NULL,0); | ||
|
||
void **targ = RedisModule_Alloc(sizeof(void*)*3); | ||
targ[0] = bc; | ||
targ[1] = (void*)(unsigned long) argc; | ||
targ[2] = (void*)(RedisModuleString **)argv; | ||
|
||
if (pthread_create(&tid,NULL,fsort_aggregate_thread,targ) != 0) { | ||
RedisModule_AbortBlock(bc); | ||
return RedisModule_ReplyWithError(ctx,"-ERR Can't start thread"); | ||
} | ||
|
||
return REDISMODULE_OK; | ||
} | ||
|
||
int FSort_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { | ||
RedisModule_AutoMemory(ctx); | ||
|
||
if (argc < 7 ) { | ||
return RedisModule_WrongArity(ctx); | ||
} | ||
|
||
pthread_t tid; | ||
RedisModuleBlockedClient *bc = RedisModule_BlockClient(ctx,NULL,NULL,NULL,0); | ||
|
||
void **targ = RedisModule_Alloc(sizeof(void*)*3); | ||
targ[0] = bc; | ||
targ[1] = (void*)(unsigned long) argc; | ||
targ[2] = (void*)(RedisModuleString **)argv; | ||
|
||
if (pthread_create(&tid,NULL,fsort_fsort_thread,targ) != 0) { | ||
RedisModule_AbortBlock(bc); | ||
return RedisModule_ReplyWithError(ctx,"-ERR Can't start thread"); | ||
} | ||
|
||
return REDISMODULE_OK; | ||
} | ||
|
||
int RedisModule_OnLoad(RedisModuleCtx *ctx) { | ||
|
||
if (RedisModule_Init(ctx, "FilterSortModule", 1, REDISMODULE_APIVER_1) == REDISMODULE_ERR) { | ||
return REDISMODULE_ERR; | ||
} | ||
|
||
if (RedisModule_CreateCommand(ctx, "fsort", FSort_RedisCommand, "write", 1, 2, 1) == REDISMODULE_ERR) { | ||
return REDISMODULE_ERR; | ||
} | ||
|
||
if (RedisModule_CreateCommand(ctx, "fsortBust", FSortBust_RedisCommand, "write", 1, 1, 1) == REDISMODULE_ERR) { | ||
return REDISMODULE_ERR; | ||
} | ||
|
||
if (RedisModule_CreateCommand(ctx, "fsortaggregate", FSortAggregate_RedisCommand, "write", 1, 2, 1) == REDISMODULE_ERR) { | ||
return REDISMODULE_ERR; | ||
} | ||
|
||
return REDISMODULE_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef __FILTERMODULE_H | ||
#define __FILTERMODULE_H 1 | ||
|
||
#include <sys/types.h> | ||
|
||
#include "fsort.h" | ||
|
||
#include "pthread.h" | ||
|
||
|
||
#endif |
Oops, something went wrong.