Skip to content

Commit a43011a

Browse files
committed
Buggy unfinished ver
rfc doc
1 parent 9a28eb8 commit a43011a

File tree

14 files changed

+1548
-0
lines changed

14 files changed

+1548
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ lib
2727
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
2828
node_modules
2929
test/dump
30+
31+
# So o files
32+
*.so
33+
*.o

csrc/.clang-format

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
Language: Cpp
3+
AccessModifierOffset: -1
4+
AlignAfterOpenBracket: true
5+
AlignConsecutiveAssignments: false
6+
AlignEscapedNewlinesLeft: true
7+
AlignOperands: true
8+
AlignTrailingComments: true
9+
AllowAllParametersOfDeclarationOnNextLine: true
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: None
13+
AllowShortIfStatementsOnASingleLine: true
14+
AllowShortLoopsOnASingleLine: true
15+
AlwaysBreakAfterDefinitionReturnType: None
16+
AlwaysBreakBeforeMultilineStrings: true
17+
AlwaysBreakTemplateDeclarations: true
18+
BinPackArguments: true
19+
BinPackParameters: true
20+
BreakBeforeBinaryOperators: None
21+
BreakBeforeBraces: Attach
22+
BreakBeforeTernaryOperators: true
23+
BreakConstructorInitializersBeforeComma: false
24+
ColumnLimit: 100
25+
CommentPragmas: '^ IWYU pragma:'
26+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
27+
ConstructorInitializerIndentWidth: 4
28+
ContinuationIndentWidth: 4
29+
Cpp11BracedListStyle: true
30+
DerivePointerAlignment: true
31+
DisableFormat: false
32+
ExperimentalAutoDetectBinPacking: false
33+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
34+
IndentCaseLabels: true
35+
IndentWidth: 2
36+
IndentWrappedFunctionNames: false
37+
KeepEmptyLinesAtTheStartOfBlocks: true
38+
MacroBlockBegin: ''
39+
MacroBlockEnd: ''
40+
MaxEmptyLinesToKeep: 1
41+
NamespaceIndentation: None
42+
PenaltyBreakBeforeFirstCallParameter: 1
43+
PenaltyBreakComment: 300
44+
PenaltyBreakFirstLessLess: 120
45+
PenaltyBreakString: 1000
46+
PenaltyExcessCharacter: 1000000
47+
PenaltyReturnTypeOnItsOwnLine: 200
48+
PointerAlignment: Left
49+
SpaceAfterCStyleCast: false
50+
SpaceBeforeAssignmentOperators: true
51+
SpaceBeforeParens: ControlStatements
52+
SpaceInEmptyParentheses: false
53+
SpacesBeforeTrailingComments: 2
54+
SpacesInAngles: false
55+
SpacesInContainerLiterals: true
56+
SpacesInCStyleCastParentheses: false
57+
SpacesInParentheses: false
58+
SpacesInSquareBrackets: false
59+
Standard: Auto
60+
TabWidth: 4
61+
UseTab: Never
62+
SortIncludes: false
63+
...
64+

csrc/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.o
2+
*.a
3+
*.so
4+
*.db
5+
.vscode
6+
rmutil/test_vector

csrc/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
all: build-host
2+
3+
docker-alpine-build:
4+
docker build --rm . -f ./build/Dockerfile-build-image -t alpine_build
5+
6+
docker-redis-build: redis-alpine-module
7+
docker build --rm $(CURDIR) -f ./build/Dockerfile-with-module -t redis_custom
8+
9+
redis-alpine-module:
10+
docker run -it --rm -v ${PWD}:/src alpine_build make build-host
11+
12+
build-host:
13+
cd redis-filtered-sort && $(MAKE) all
14+
15+
test_run: docker-redis-build
16+
docker run --rm --name custom_redis redis_custom
17+
test_cli:
18+
docker exec -it custom_redis redis-cli
19+
clean:
20+
cd redis-filtered-sort && $(MAKE) $@

csrc/build/Dockerfile-build-image

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM alpine
2+
# RUN apk update \
3+
# && apk add --virtual build-dependencies \
4+
# build-base \
5+
# gcc \
6+
RUN apk add --no-cache --virtual .build-deps \
7+
coreutils \
8+
gcc \
9+
linux-headers \
10+
make \
11+
musl-dev \
12+
&& apk add \
13+
bash
14+
RUN mkdir /src
15+
VOLUME ["/src"]
16+
WORKDIR /src

csrc/build/Dockerfile-with-module

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM redis:5.0.5-alpine
2+
COPY ./redis-filtered-sort/module.so ./filtered_sort.so
3+
ENTRYPOINT ["docker-entrypoint.sh"]
4+
CMD ["redis-server", "--loadmodule", "./filtered_sort.so"]
5+
EXPOSE 6379

csrc/build/docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "3"
2+
services:
3+
redismodule:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile-build-image
7+
hostname: redismodule
8+
volumes:
9+
- ${PWD}:/src
10+
testredis:
11+
build:
12+
context: .
13+
dockerfile: Dockerfile-with-module

csrc/doc/rfc/00_design.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Proposal
2+
As described in Redis Module API modules have more benefints than general LUA scripts. In current environment, lua script locking db for a long period. The main reason of this module: provide non db-locking access for time-consuming operations.
3+
4+
# Design
5+
* Projects consists from one redis module `filtered_sort` and node.js wrapper `redis-filtered-sort`.
6+
7+
* By default, module going to have 2 build options: Docker based build for redis:5.0-alpine and local system `gcc`
8+
9+
* Exported functions for dev purpose prefixed with "c" prefix
10+
11+
* Current module behaviour copied from existing scripts for compat with lua.
12+
13+
* in Redis Cluster environment: all keys and sets MUST use {prefix} notation, to be stored on same node. Otherwise module won't work correctly.
14+
15+
16+
## Expected API and behaviour
17+
Module will export into Redis command namespace these commands:
18+
#### cfsort
19+
Sorts, filters and paginates provided SET `idSetKey` using data from `metaKeyPattern`.`hashKey` using `sortOrder`,`filter` and stores processed data for `expire` seconds
20+
21+
* **Method usage**: `cfsort idSetKey metaKeyPattern hashKey sortOrder filter(jsonFormattedString) curTime:unixtime [offset:int] [limit:int] [expire:int - ttl in seconds] [keyOnly]`;
22+
- **idSetKey**: Redis SET containing id values
23+
- **metaKeyPattern**: Pattern to find HASHes of record, "*" is replaced by id from `idSetKey`, eg: _*-metakey_ produce _id-231-metakey_
24+
- **hashKey**: field name from HASHkey formed from `metakeyPattern`
25+
- **filter**: Json string with filters
26+
* **General behaviour**: During work process function going to store postprocessed data into 2 temporary sets(sorted and filterd) in format `{idSetKey}:{order}:{metaKey}:{hasKey}:{filterString}` and reuse them while `ttl` not past.
27+
28+
Creates index of this sets in ZSET `tempKeysSet`.
29+
> _Definitely I don't understand why this needed, but we have cacheBuster_ in lua. #SeeLater
30+
31+
- If `metaKeyPattern` and `hashKey` not provided, function going to use `idSetKey` values for sorting, otherwise fetch data from `metaKeyPattern.gsub("*", idSetMemberValue).providedHashKey` and use them for sort.
32+
33+
- Same as prev behaviour going to be used in filtering process.
34+
35+
- If more than one filter provided: `filterString` will contain only "#" filter;
36+
37+
38+
### cfsortBust :
39+
Checking caches for specified `idSetKey` that was created in result of `cfsort` method work. Deletes outdated tempKeys from ZSET `tempKeysSet`
40+
41+
**Method usage**: `cfsort idSetKey curTime:unixtime [expire:int]`
42+
43+
### cfsortAggregate:
44+
Groups elements by `aggregateParam` from set `idSet` using meta available under `metaKeyPattern` and reports count of each type of criteria.
45+
46+
Currently supports only `sum`;
47+
48+
* **Method usage**: `cfsortAggregate idSetKey metaKeyPattern aggregateParam`
49+
- **idSetKey**: Redis SET containing id values
50+
- **metaKeyPattern**: Pattern to find HASHes of record, "*" is replaced by id from `idSetKey`, eg: _*-metakey_ produce _id-231-metakey_
51+
- **aggregateParam** : JsonString containing aggregate criteria.
52+
```Javascript
53+
{
54+
"fieldName": "sum"
55+
}
56+
```
57+
58+
59+
## Filter Format `filter` parameter:
60+
Accepting `json` formated object:
61+
```Javascript
62+
{
63+
"fieldToFiler": {
64+
//Filter params...
65+
}
66+
"fieldToFilter": "String to find"
67+
}
68+
```
69+
70+
- **Available criteria**:
71+
- `lte`,`gte` - (int) value comparison
72+
- `eq`,`ne` - equal or not
73+
- `any` - Object containing criteria list to Exclude
74+
- `some` - Object containing criteria list to Include
75+
- `match` - String contains
76+
- `exists` - if value exists
77+
78+
- **MultiField(#multi)**: Reserved field name for assigning criterias to multiple fields from `meta` record(currently supports only _String contains check_)
79+
```Javascript
80+
{
81+
"#multi": {
82+
"fields": [
83+
//Field list
84+
...
85+
],
86+
"match": "criteria"
87+
}
88+
}
89+
```
90+
91+
92+
**Example**
93+
```Javascript
94+
{
95+
"metaFieldName": "contained string",
96+
"metaFieldName2": { //Filter params object
97+
"gte": 12,
98+
"lte": 13,
99+
},
100+
"metaFieldAnyParams": {
101+
"any": {
102+
"0": {
103+
"gte": 12,
104+
"lte": 13,
105+
},
106+
"1": {
107+
"gte": 28,
108+
"lte": 30,
109+
}
110+
}
111+
},
112+
113+
114+
}
115+
```
116+
117+

csrc/doc/rfc/01_bench.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Benchmarking
2+
...TODO

csrc/redis-filtered-sort/Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#set environment variable RM_INCLUDE_DIR to the location of redismodule.h
2+
ifndef RM_INCLUDE_DIR
3+
RM_INCLUDE_DIR=../lib/
4+
endif
5+
6+
ifndef RMUTIL_LIBDIR
7+
RMUTIL_LIBDIR=../lib/rmutil
8+
endif
9+
10+
# find the OS
11+
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
12+
13+
# Compile flags for linux / osx
14+
ifeq ($(uname_S),Linux)
15+
SHOBJ_CFLAGS ?= -fno-common -g -ggdb
16+
SHOBJ_LDFLAGS ?= -shared -Bsymbolic
17+
else
18+
SHOBJ_CFLAGS ?= -dynamic -fno-common -g -ggdb
19+
SHOBJ_LDFLAGS ?= -bundle -undefined dynamic_lookup
20+
endif
21+
CFLAGS = -I$(RM_INCLUDE_DIR) -Wall -g -O0 -fPIC -lc -lm -std=gnu99
22+
CC=gcc
23+
24+
all: rmutil module.so
25+
26+
rmutil: FORCE
27+
$(MAKE) -C $(RMUTIL_LIBDIR)
28+
29+
module.so: module.o
30+
$(LD) -o $@ module.o $(SHOBJ_LDFLAGS) $(LIBS) -L$(RMUTIL_LIBDIR) -lrmutil -ljansson -lc
31+
32+
module_sample.so: module_sample.o
33+
$(LD) -o $@ module.o $(SHOBJ_LDFLAGS) $(LIBS) -L$(RMUTIL_LIBDIR) -lrmutil -ljansson -lc
34+
35+
clean:
36+
rm -rf *.xo *.so *.o
37+
cd $(RMUTIL_LIBDIR) && make clean
38+
39+
FORCE:

0 commit comments

Comments
 (0)