Skip to content

Commit f866653

Browse files
committed
rfc doc
1 parent c57e797 commit f866653

File tree

3 files changed

+120
-66
lines changed

3 files changed

+120
-66
lines changed

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/README.md

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,2 @@
11
# Filtered Sort C lang ver
2-
3-
[ ] Сделать реализацию
4-
[ ] Сортировка (+-)
5-
[ ] Фильтрация
6-
[ ] Ввести thread pool, увести все операции в отдельные трэды
7-
[ ] Провести сравнительные тесты
8-
[ ] Привести все в порядок
9-
10-
###
11-
`cfsort id-set-key meta-key-pattern hash-key sort order json-filter curTime [offset] [limit] [expire] [keyOnly]`
12-
13-
`cfsortBust id-set-key curTime [expire]`
14-
15-
#!todo
16-
17-
### Build system
18-
* Сборка модуля docker'ом в отдельно контейнера под alpine linux.
19-
* Сборка custom redis контейнера с включенным модулем.
20-
21-
### Dependencies
22-
`jansson` - для lua cjson
23-
*использовать как можно меньше зависимостей.*
24-
###
25-
26-
#### Из хорошего
27-
Просмотрев архитектуру RedisModule и так же RediSearch RedisMl RedisAI Можно сказать что результат возможен.
28-
29-
Если использовать `low-level` API = так называемый прямой доступ к ключам,
30-
отдельный трэд и блокировку клиента, можно добиться нужного результата.
31-
32-
# Из плохого
33-
34-
Категорически избегать блокирующих операций. Как на чтение так и на запись.
35-
36-
Встает вопрос в работе с кластером, но лучше проверить.
37-
38-
39-
Update:
40-
41-
!!!! Категорически не будет работать в кластере, как и оригинальный скрипт.
42-
На данный момент lua скрипт падает с ошибкой " ReplyError: CROSSSLOT Keys in request don't hash to the same slot"
43-
!!!!!!!!!!!
44-
45-
46-
`
47-
5332a9007251add48219e2866d8e2b1c2943a915 127.0.0.1:7006@17006 slave 7819ac6cf3703f1e942a7f38cfa6a390e1a14cee 0 1562695256598 7 connected
48-
49-
d85d87b27c61066ac7c1506fec03c34b0e1422ac 127.0.0.1:7004@17004 slave 088ad3854d8953d6756b295cf74603ec9630cbf2 0 1562695255788 5 connected
50-
51-
ab68df2c82dccea54d9c9a5129dd96d64e48ec8b 127.0.0.1:6379@16379 myself,master - 0 1562695256000 1 connected 0-5460
52-
53-
e74a870ff4eac1507d6dfc0e8805d705f80b075c 127.0.0.1:7003@17003 slave ab68df2c82dccea54d9c9a5129dd96d64e48ec8b 0 1562695256806 4 connected
54-
55-
7819ac6cf3703f1e942a7f38cfa6a390e1a14cee 127.0.0.1:7002@17002 master - 0 1562695257000 3 connected 10923-16383
56-
57-
088ad3854d8953d6756b295cf74603ec9630cbf2 127.0.0.1:7001@17001 master - 0 1562695257831 2 connected 5461-10922
58-
59-
c7944ef74f4f3272c8b38fa4e98751e0481e5b26 127.0.0.1:7005@17005 slave ab68df2c82dccea54d9c9a5129dd96d64e48ec8b 0 1562695257316 6 connected`
60-
61-
`"no-cluster"**: The command should not register in Redis Cluster
62-
since is not designed to work with it because, for
63-
example, is unable to report the position of the
64-
keys, programmatically creates key names, or any
65-
other reason. `
66-
67-
2+
Full docs soon

0 commit comments

Comments
 (0)