aboutsummaryrefslogtreecommitdiff
path: root/examples/redis-unstable/src/functions.h
diff options
context:
space:
mode:
Diffstat (limited to 'examples/redis-unstable/src/functions.h')
-rw-r--r--examples/redis-unstable/src/functions.h127
1 files changed, 0 insertions, 127 deletions
diff --git a/examples/redis-unstable/src/functions.h b/examples/redis-unstable/src/functions.h
deleted file mode 100644
index e8a3042..0000000
--- a/examples/redis-unstable/src/functions.h
+++ /dev/null
@@ -1,127 +0,0 @@
1/*
2 * Copyright (c) 2021-Present, Redis Ltd.
3 * All rights reserved.
4 *
5 * Licensed under your choice of (a) the Redis Source Available License 2.0
6 * (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the
7 * GNU Affero General Public License v3 (AGPLv3).
8 */
9
10#ifndef __FUNCTIONS_H_
11#define __FUNCTIONS_H_
12
13/*
14 * functions.c unit provides the Redis Functions API:
15 * * FUNCTION LOAD
16 * * FUNCTION LIST
17 * * FUNCTION CALL (FCALL and FCALL_RO)
18 * * FUNCTION DELETE
19 * * FUNCTION STATS
20 * * FUNCTION KILL
21 * * FUNCTION FLUSH
22 * * FUNCTION DUMP
23 * * FUNCTION RESTORE
24 * * FUNCTION HELP
25 *
26 * Also contains implementation for:
27 * * Save/Load function from rdb
28 * * Register engines
29 */
30
31#include "server.h"
32#include "script.h"
33#include "redismodule.h"
34
35typedef struct functionLibInfo functionLibInfo;
36
37typedef struct engine {
38 /* engine specific context */
39 void *engine_ctx;
40
41 /* Create function callback, get the engine_ctx, and function code
42 * engine_ctx - opaque struct that was created on engine initialization
43 * li - library information that need to be provided and when add functions
44 * code - the library code
45 * timeout - timeout for the library creation (0 for no timeout)
46 * err - description of error (if occurred)
47 * returns C_ERR on error and set err to be the error message */
48 int (*create)(void *engine_ctx, functionLibInfo *li, sds code, size_t timeout, sds *err);
49
50 /* Invoking a function, r_ctx is an opaque object (from engine POV).
51 * The r_ctx should be used by the engine to interaction with Redis,
52 * such interaction could be running commands, set resp, or set
53 * replication mode
54 */
55 void (*call)(scriptRunCtx *r_ctx, void *engine_ctx, void *compiled_function,
56 robj **keys, size_t nkeys, robj **args, size_t nargs);
57
58 /* get current used memory by the engine */
59 size_t (*get_used_memory)(void *engine_ctx);
60
61 /* Return memory overhead for a given function,
62 * such memory is not counted as engine memory but as general
63 * structs memory that hold different information */
64 size_t (*get_function_memory_overhead)(void *compiled_function);
65
66 /* Return memory overhead for engine (struct size holding the engine)*/
67 size_t (*get_engine_memory_overhead)(void *engine_ctx);
68
69 /* free the given function */
70 void (*free_function)(void *engine_ctx, void *compiled_function);
71
72 /* Free the engine context. */
73 void (*free_ctx)(void *engine_ctx);
74} engine;
75
76/* Hold information about an engine.
77 * Used on rdb.c so it must be declared here. */
78typedef struct engineInfo {
79 sds name; /* Name of the engine */
80 engine *engine; /* engine callbacks that allows to interact with the engine */
81 client *c; /* Client that is used to run commands */
82} engineInfo;
83
84/* Hold information about the specific function.
85 * Used on rdb.c so it must be declared here. */
86typedef struct functionInfo {
87 sds name; /* Function name */
88 void *function; /* Opaque object that set by the function's engine and allow it
89 to run the function, usually it's the function compiled code. */
90 functionLibInfo* li; /* Pointer to the library created the function */
91 sds desc; /* Function description */
92 uint64_t f_flags; /* Function flags */
93} functionInfo;
94
95/* Hold information about the specific library.
96 * Used on rdb.c so it must be declared here. */
97struct functionLibInfo {
98 sds name; /* Library name */
99 dict *functions; /* Functions dictionary */
100 engineInfo *ei; /* Pointer to the function engine */
101 sds code; /* Library code */
102};
103
104int functionsRegisterEngine(const char *engine_name, engine *engine_ctx);
105sds functionsCreateWithLibraryCtx(sds code, int replace, sds* err, functionsLibCtx *lib_ctx, size_t timeout);
106unsigned long functionsMemoryVM(void);
107unsigned long functionsMemoryEngine(void);
108unsigned long functionsNum(void);
109unsigned long functionsLibNum(void);
110dict* functionsLibGet(void);
111size_t functionsLibCtxFunctionsLen(functionsLibCtx *functions_ctx);
112functionsLibCtx* functionsLibCtxGetCurrent(void);
113functionsLibCtx* functionsLibCtxCreate(void);
114void functionsLibCtxClearCurrent(int async);
115void functionsLibCtxFree(functionsLibCtx *lib_ctx);
116void functionsLibCtxClear(functionsLibCtx *lib_ctx);
117void functionsLibCtxSwapWithCurrent(functionsLibCtx *lib_ctx);
118
119int functionLibCreateFunction(sds name, void *function, functionLibInfo *li, sds desc, uint64_t f_flags, sds *err);
120
121int luaEngineInitEngine(void);
122int functionsInit(void);
123void functionsFree(functionsLibCtx *lib_ctx, dict *engs);
124
125void createFunctionDumpPayload(rio *payload);
126
127#endif /* __FUNCTIONS_H_ */