init project #2
13
.drone.yml
Normal file
13
.drone.yml
Normal file
@ -0,0 +1,13 @@
|
||||
kind: pipeline
|
||||
type: exec
|
||||
name: default
|
||||
steps:
|
||||
- name: build
|
||||
commands:
|
||||
- make clean && make
|
||||
trigger:
|
||||
branch:
|
||||
- master
|
||||
event:
|
||||
- pull_request
|
||||
- push
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -107,3 +107,6 @@ dkms.conf
|
||||
*.out
|
||||
*.app
|
||||
|
||||
*.xo
|
||||
.idea
|
||||
|
||||
|
29
src/Makefile
Normal file
29
src/Makefile
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
|
||||
|
||||
WARN=-Wall -W -Wno-missing-field-initializers
|
||||
# Compile flags for linux / osx
|
||||
ifeq ($(uname_S),Linux)
|
||||
SHOBJ_CFLAGS ?= -W -Wall -fno-common -g -ggdb -std=c11 -O2 $(WARN) $(OPTIMIZATION)
|
||||
SHOBJ_LDFLAGS ?= -shared
|
||||
else
|
||||
SHOBJ_CFLAGS ?= -W -Wall -dynamic -fno-common -g -ggdb -std=c11 -O2 $(WARN) $(OPTIMIZATION)
|
||||
SHOBJ_LDFLAGS ?= -bundle -undefined dynamic_lookup
|
||||
endif
|
||||
|
||||
.SUFFIXES: .c .so .xo .o
|
||||
|
||||
|
||||
.c.xo:
|
||||
$(CC) -I. $(CFLAGS) $(SHOBJ_CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
all: redis-migrate.so
|
||||
|
||||
|
||||
redis-migrate.xo: ./redismodule.h
|
||||
|
||||
redis-migrate.so: redis-migrate.xo
|
||||
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
|
||||
clean:
|
||||
rm -rf *.xo *.so *.o
|
44
src/redis-migrate.c
Normal file
44
src/redis-migrate.c
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
#include "redis-migrate.h"
|
||||
|
||||
/**
|
||||
* migrate data to current instance.
|
||||
* migrate host port begin-slot end-slot
|
||||
* @param ctx
|
||||
* @param argv
|
||||
* @param argc
|
||||
* @return
|
||||
*/
|
||||
int rm_migrateCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
if (argc != 5) {
|
||||
return RedisModule_WrongArity(ctx);
|
||||
}
|
||||
robj *host = (robj *) argv[1];
|
||||
robj *port = (robj *) argv[2];
|
||||
robj *begin_slot = (robj *) argv[3];
|
||||
robj *end_slot = (robj *) argv[4];
|
||||
RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_NOTICE, "host:%s, port:%s, begin:%s, end:%s", (char *) host->ptr,
|
||||
(char *) port->ptr, (char *) begin_slot->ptr, (char *) end_slot->ptr);
|
||||
|
||||
return RedisModule_ReplyWithSimpleString(ctx, "OK");
|
||||
}
|
||||
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
|
||||
int flag = RedisModule_Init(ctx, MODULE_NAME, REDIS_MIGRATE_VERSION, REDISMODULE_APIVER_1);
|
||||
if (flag == REDISMODULE_ERR) {
|
||||
return REDISMODULE_ERR;
|
||||
}
|
||||
RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_NOTICE, "init %s success", MODULE_NAME);
|
||||
flag = RedisModule_CreateCommand(ctx, "rm.migrate", rm_migrateCommand, "write deny-oom admin", 1, 1, 0);
|
||||
if (flag == REDISMODULE_ERR) {
|
||||
RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_WARNING, "init rm.migrate failed");
|
||||
return REDISMODULE_ERR;
|
||||
}
|
||||
return REDISMODULE_OK;
|
||||
}
|
24
src/redis-migrate.h
Normal file
24
src/redis-migrate.h
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
#ifndef REDIS_MIGRATE_REDIS_MIGRATE_H
|
||||
#define REDIS_MIGRATE_REDIS_MIGRATE_H
|
||||
|
||||
#include "redismodule.h"
|
||||
|
||||
#define MODULE_NAME "redis-migrate"
|
||||
#define REDIS_MIGRATE_VERSION 1
|
||||
#define LRU_BITS 24
|
||||
|
||||
typedef struct redisObject {
|
||||
unsigned type:4;
|
||||
unsigned encoding:4;
|
||||
unsigned lru:LRU_BITS; /* LRU time (relative to global lru_clock) or
|
||||
* LFU data (least significant 8 bits frequency
|
||||
* and most significant 16 bits access time). */
|
||||
int refcount;
|
||||
void *ptr;
|
||||
} robj;
|
||||
|
||||
int rm_migrateCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
|
||||
#endif //REDIS_MIGRATE_REDIS_MIGRATE_H
|
1548
src/redismodule.h
Normal file
1548
src/redismodule.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user