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