forked from RedisJSON/RedisJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrejson_api.h
71 lines (51 loc) · 1.83 KB
/
rejson_api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include "redismodule.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum JSONType {
JSONType_String = 0,
JSONType_Int = 1,
JSONType_Double = 2,
JSONType_Bool = 3,
JSONType_Object = 4,
JSONType_Array = 5,
JSONType_Null = 6,
JSONType__EOF
} JSONType;
typedef const void* RedisJSON;
typedef const void* JSONResultsIterator;
typedef struct RedisJSONAPI_V1 {
/* RedisJSONKey functions */
RedisJSON (*openKey)(RedisModuleCtx *ctx, RedisModuleString *key_name);
RedisJSON (*openKeyFromStr)(RedisModuleCtx *ctx, const char *path);
JSONResultsIterator (*get)(RedisJSON json, const char *path);
RedisJSON (*next)(JSONResultsIterator iter);
size_t (*len)(JSONResultsIterator iter);
void (*freeIter)(JSONResultsIterator iter);
RedisJSON (*getAt)(RedisJSON json, size_t index);
/* RedisJSON value functions
* Return REDISMODULE_OK if RedisJSON is of the correct JSONType,
* else REDISMODULE_ERR is returned
* */
// Return the length of Object/Array
int (*getLen)(RedisJSON json, size_t *count);
// Return the JSONType
JSONType (*getType)(RedisJSON json);
// Return int value from a Numeric field
int (*getInt)(RedisJSON json, long long *integer);
// Return double value from a Numeric field
int (*getDouble)(RedisJSON json, double *dbl);
// Return 0 or 1 as int value from a Bool field
int (*getBoolean)(RedisJSON json, int *boolean);
// Return a Read-Only String value from a String field
int (*getString)(RedisJSON json, const char **str, size_t *len);
// Return JSON String representation (for any JSONType)
// The caller gains ownership of `str`
int (*getJSON)(RedisJSON json, RedisModuleCtx *ctx, RedisModuleString **str);
// Return 1 if type of key is JSON
int (*isJSON)(RedisModuleKey *redis_key);
} RedisJSONAPI_V1;
#ifdef __cplusplus
}
#endif