### Build and Install Packaged Release Source: https://github.com/redict/redict/blob/main/deps/jemalloc/INSTALL.md Use this sequence to build and install jemalloc from a packaged release. Ensure you are in the root directory of the source tree. ```bash ./configure make make install ``` -------------------------------- ### Build and Start Redict with TLS Support Source: https://context7.com/redict/redict/llms.txt Build Redict with TLS enabled using 'BUILD_TLS=yes'. Start the server with TLS enabled, specifying certificate and key files. This secures client connections. ```bash # Build with TLS support make BUILD_TLS=yes # Generate test certificates (development only) ./utils/gen-test-certs.sh # Start server with TLS on port 6379 (disable plaintext) ./src/redict-server \ --tls-port 6379 \ --port 0 \ --tls-cert-file ./tests/tls/redict.crt \ --tls-key-file ./tests/tls/redict.key \ --tls-ca-cert-file ./tests/tls/ca.crt ``` -------------------------------- ### Set Installation Prefix Source: https://github.com/redict/redict/blob/main/deps/jemalloc/INSTALL.md Specify the base directory for jemalloc installation. This affects the locations of include, lib, and man files. ```bash ./configure --prefix=/usr/local ``` -------------------------------- ### Build and Install Developer Sources Source: https://github.com/redict/redict/blob/main/deps/jemalloc/INSTALL.md If building from unpackaged developer sources, this sequence may be necessary. It includes an autogen step. ```bash ./autogen.sh make make install ``` -------------------------------- ### Lua string.rep example Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Shows how to repeat a string multiple times using string.rep. ```lua string.rep("abc", 3) ``` -------------------------------- ### Customizing Jemalloc Installation Paths Source: https://github.com/redict/redict/blob/main/deps/jemalloc/INSTALL.md Define these make variables when invoking make to customize installation directories for headers, libraries, and man pages. DESTDIR can prepend to these paths for staging. ```makefile INCLUDEDIR="?" LIBDIR="?" MANDIR="?" DESTDIR="?" CC="?" CFLAGS="?" CPPFLAGS="?" LDFLAGS="?" PATH="?" ``` -------------------------------- ### Lua string.match example Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Demonstrates string.match finding the first sequence of alphabetic characters in a string. ```lua string.match("hello world", "%a+") ``` -------------------------------- ### Lua Multiple Assignments Example Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Demonstrates how multiple assignments work in Lua, including the order of evaluation and value adjustment. The example shows that the 'i' in 'a[i]' is evaluated before 'i' is updated. ```lua i = 3 i, a[i] = i+1, 20 ``` ```lua x, y = y, x ``` ```lua x, y, z = y, z, x ``` -------------------------------- ### Jemalloc Development Build with Autogen Source: https://github.com/redict/redict/blob/main/deps/jemalloc/INSTALL.md For significant code changes, use autogen.sh instead of configure. This example demonstrates setting up a separate object directory for configuration and building. ```bash autoconf mkdir obj cd obj ../configure --enable-autogen make ``` -------------------------------- ### io.input Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Sets or gets the default input file. ```APIDOC ## io.input ([file]) ### Description Sets the default input file. If called with a filename, it opens the file. If called with a file handle, it sets that handle as the default. If called without parameters, it returns the current default input file. ### Parameters * **file** (string or file handle, optional) - The filename or file handle to set as the default input. ### Returns * (file handle) - The current default input file handle. ``` -------------------------------- ### Build and Run Redict Server Source: https://context7.com/redict/redict/llms.txt Standard build process for Redict. Use BUILD_TLS=yes for TLS support or USE_SYSTEM_JEMALLOC=yes for system jemalloc. Start the server with or without a config file and connect using redict-cli. ```bash # Standard build make # Build with TLS support make BUILD_TLS=yes # Build with system jemalloc instead of vendored copy make USE_SYSTEM_JEMALLOC=yes # Start the server (default config) ./src/redict-server # Start the server with a config file ./src/redict-server /path/to/redict.conf # Connect via CLI ./src/redict-cli # Connect to a specific host/port ./src/redict-cli -h 127.0.0.1 -p 6379 # Ping to verify connectivity 127.0.0.1:6379> PING # => PONG ``` -------------------------------- ### Lua Coroutine Example Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Demonstrates the creation and execution flow of Lua coroutines, including yielding and resuming. ```lua function foo (a) print("foo", a) return coroutine.yield(2*a) end co = coroutine.create(function (a,b) print("co-body", a, b) local r = foo(a+1) print("co-body", r) local r, s = coroutine.yield(a+b, a-b) print("co-body", r, s) return b, "end" end) print("main", coroutine.resume(co, 1, 10)) print("main", coroutine.resume(co, "r")) print("main", coroutine.resume(co, "x", "y")) print("main", coroutine.resume(co, "x", "y")) ``` -------------------------------- ### Install Hiredict SSL Package Configuration Source: https://github.com/redict/redict/blob/main/deps/hiredict/CMakeLists.txt Configures and installs the package configuration files for hiredict_ssl, enabling it to be found by other CMake projects. This includes the .pc and -config.cmake files. ```cmake CONFIGURE_FILE(util/hiredict_ssl.pc.in hiredict_ssl.pc @ONLY) CONFIGURE_FILE(util/hiredis_ssl.pc.in hiredis_ssl.pc @ONLY) INSTALL(TARGETS hiredict_ssl EXPORT hiredict_ssl-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) IF (MSVC AND BUILD_SHARED_LIBS) INSTALL(FILES $ DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS Debug RelWithDebInfo) ENDIF() INSTALL(FILES include/hiredict/hiredict_ssl.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredict) INSTALL(FILES shim/hiredis_ssl.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredict_ssl.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis_ssl.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) export(EXPORT hiredict_ssl-targets FILE "${CMAKE_CURRENT_BINARY_DIR}/hiredict_ssl-targets.cmake" NAMESPACE hiredict::) IF(WIN32) SET(CMAKE_CONF_INSTALL_DIR share/hiredict_ssl) ELSE() SET(CMAKE_CONF_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/hiredict_ssl) ENDIF() configure_package_config_file(util/hiredict_ssl-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/hiredict_ssl-config.cmake INSTALL_DESTINATION ${CMAKE_CONF_INSTALL_DIR} PATH_VARS INCLUDE_INSTALL_DIR) INSTALL(EXPORT hiredict_ssl-targets FILE hiredict_ssl-targets.cmake NAMESPACE hiredict:: DESTINATION ${CMAKE_CONF_INSTALL_DIR}) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredict_ssl-config.cmake DESTINATION ${CMAKE_CONF_INSTALL_DIR}) ``` -------------------------------- ### LGPL Notice for Interactive Programs Source: https://github.com/redict/redict/blob/main/LICENSES/LGPL-3.0-only.txt If your program interacts with the terminal, display this short notice upon starting in interactive mode. It informs users about warranty, free software status, and how to get more details. ```text Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. ``` -------------------------------- ### Start Redict Sentinel Process Source: https://context7.com/redict/redict/llms.txt Launch Redict Sentinel with a configuration file using './src/redict-sentinel' or './src/redict-server --sentinel'. Sentinel provides high availability through automatic failover and service discovery. ```bash # Start a Sentinel process (using sentinel.conf) ./src/redict-sentinel /path/to/sentinel.conf # or equivalently: ./src/redict-server /path/to/sentinel.conf --sentinel ``` -------------------------------- ### Selective Jemalloc Installation Targets Source: https://github.com/redict/redict/blob/main/deps/jemalloc/INSTALL.md These make targets allow for the installation of specific jemalloc components, including binaries, headers, libraries, and documentation. ```makefile install_bin install_include install_lib_shared install_lib_static install_lib_pc install_lib install_doc_html install_doc_man install_doc ``` -------------------------------- ### Linenoise Hints Callback Implementation Source: https://github.com/redict/redict/blob/main/deps/linenoise/README.markdown Example implementation of a hints callback. It checks the input buffer and returns a hint string with specified color and bold attributes, or NULL if no hint is applicable. ```c char *hints(const char *buf, int *color, int *bold) { if (!strcasecmp(buf,"git remote add")) { *color = 35; *bold = 0; return " "; } return NULL; } ``` -------------------------------- ### Run Redict Server Manually with TLS (Module) Source: https://github.com/redict/redict/blob/main/TLS.md Start a Redict server with TLS enabled using the module mode. Load the TLS module and specify the TLS port, certificate file, key file, and CA certificate file. ```bash ./src/redict-server --tls-port 6379 --port 0 \ --tls-cert-file ./tests/tls/redict.crt \ --tls-key-file ./tests/tls/redict.key \ --tls-ca-cert-file ./tests/tls/ca.crt \ --loadmodule src/redict-tls.so ``` -------------------------------- ### Run Redict Server Manually with TLS (Built-in) Source: https://github.com/redict/redict/blob/main/TLS.md Start a Redict server with TLS enabled using the built-in mode. Specify the TLS port, certificate file, key file, and CA certificate file. ```bash ./src/redict-server --tls-port 6379 --port 0 \ --tls-cert-file ./tests/tls/redict.crt \ --tls-key-file ./tests/tls/redict.key \ --tls-ca-cert-file ./tests/tls/ca.crt ``` -------------------------------- ### io.output Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Sets or gets the default output file. ```APIDOC ## io.output ([file]) ### Description Sets the default output file. If called with a filename, it opens the file. If called with a file handle, it sets that handle as the default. If called without parameters, it returns the current default output file. ### Parameters * **file** (string or file handle, optional) - The filename or file handle to set as the default output. ### Returns * (file handle) - The current default output file handle. ``` -------------------------------- ### Linenoise Completion Callback Example Source: https://github.com/redict/redict/blob/main/deps/linenoise/README.markdown Implement a completion callback that inspects the current input buffer (`buf`) and adds potential completions to the `linenoiseCompletions` object (`lc`) using `linenoiseAddCompletion`. ```c void completion(const char *buf, linenoiseCompletions *lc) { if (buf[0] == 'h') { linenoiseAddCompletion(lc,"hello"); linenoiseAddCompletion(lc,"hello there"); } } ``` -------------------------------- ### Lua string.reverse example Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Illustrates the string.reverse function to reverse the order of characters in a string. ```lua string.reverse("hello") ``` -------------------------------- ### Lua Lexical Scoping Example Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Demonstrates Lua's lexical scoping rules, showing how local variables are accessed within nested blocks and inner functions. ```lua x = 10 -- global variable do -- new block local x = x -- new 'x', with value 10 print(x) --> 10 x = x+1 do -- another block local x = x+1 -- another 'x' print(x) --> 12 end print(x) --> 11 end print(x) --> 10 (the global one) ``` -------------------------------- ### Calling a Lua Function from C Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Demonstrates the C protocol for calling a Lua function. It involves pushing the function and its arguments onto the stack, calling lua_call, and then handling the results. This example shows how to replicate the Lua code 'a = f("how", t.x, 14)' in C. ```c lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */ lua_pushstring(L, "how"); /* 1st argument */ lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */ lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */ lua_remove(L, -2); /* remove 't' from the stack */ lua_pushinteger(L, 14); /* 3rd argument */ lua_call(L, 3, 1); /* call 'f' with 3 arguments and 1 result */ lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global 'a' */ ``` -------------------------------- ### Lua Closure and Upvalue Example Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Illustrates how closures capture external local variables (upvalues) and how each closure instance can have its own state for variables declared within the loop. ```lua a = {} local x = 20 for i=1,10 do local y = 0 a[i] = function () y=y+1; return x+y end end ``` -------------------------------- ### CONFIG SET / CONFIG GET — Runtime Configuration Source: https://context7.com/redict/redict/llms.txt Read and modify Redict server configuration parameters at runtime without requiring a restart. Changes take effect immediately. ```APIDOC ## CONFIG SET / CONFIG GET — Runtime Configuration ### Description Read and modify server configuration parameters at runtime without restarting. Changes made with `CONFIG SET` take effect immediately. ### Method Not applicable (Command-line interface) ### Endpoint Not applicable (Command-line interface) ### Example Usage ```bash # Get current maxmemory setting 127.0.0.1:6379> CONFIG GET maxmemory # => 1) "maxmemory" # 2) "268435456" # Dynamically adjust memory limit 127.0.0.1:6379> CONFIG SET maxmemory 512mb # => OK # Change eviction policy at runtime 127.0.0.1:6379> CONFIG SET maxmemory-policy allkeys-lru # => OK # Set multiple parameters in one call (7.0+) 127.0.0.1:6379> CONFIG SET hz 15 loglevel verbose # => OK # Persist current in-memory config back to redict.conf 127.0.0.1:6379> CONFIG REWRITE # => OK # Reset statistics counters 127.0.0.1:6379> CONFIG RESETSTAT # => OK ``` ``` -------------------------------- ### Create a user with specific command permissions using ACLs Source: https://context7.com/redict/redict/llms.txt Creates an 'app_user' restricted to 'GET' and 'SET' commands on keys matching the 'session:*' pattern. ```redis # User that can only run GET and SET on session keys 127.0.0.1:6379> ACL SETUSER app_user on >app_pass ~session:* &* +get +set ``` -------------------------------- ### Get Current Hook Function in Lua Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Retrieves the current hook function set for the Lua state. No setup is required. ```c lua_Hook lua_gethook (lua_State *L); ``` -------------------------------- ### Get Lua Call Stack Traceback Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Returns a string with a traceback of the call stack. An optional message can be prepended, and the starting level for the traceback can be specified. ```lua debug.traceback ([thread,] [message [, level]]) ``` -------------------------------- ### module Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Creates a module, setting up its name, environment, and loaded status. ```APIDOC ## module ### Description Creates a module. If there is a table in `package.loaded[name]`, this table is the module. Otherwise, if there is a global table `t` with the given name, this table is the module. Otherwise creates a new table `t` and sets it as the value of the global `name` and the value of `package.loaded[name]`. This function also initializes `t._NAME` with the given name, `t._M` with the module (`t` itself), and `t._PACKAGE` with the package name (the full module name minus last component; see below). Finally, `module` sets `t` as the new environment of the current function and the new value of `package.loaded[name]`, so that `require` returns `t`. This function can receive optional _options_ after the module name, where each option is a function to be applied over the module. ### Parameters * `name` (string) - The name of the module. * `options` (function, optional) - Functions to be applied to the module table. ``` -------------------------------- ### Append Install Suffix Source: https://github.com/redict/redict/blob/main/deps/jemalloc/INSTALL.md Append a suffix to installed file names to allow multiple jemalloc versions to coexist in the same directory. ```bash --with-install-suffix=-v2 ``` -------------------------------- ### HyperLogLog Operations in Redict Source: https://context7.com/redict/redict/llms.txt Use PFADD to add elements to a HyperLogLog, PFCOUNT to get approximate cardinality, and PFMERGE to combine multiple HyperLogLogs. Useful for tracking unique visitors or estimating set sizes with low memory overhead. ```bash 127.0.0.1:6379> PFADD page:home:visitors "user1" "user2" "user3" "user1" # => (integer) 1 -- internal registers were modified 127.0.0.1:6379> PFADD page:about:visitors "user2" "user4" "user5" # => (integer) 1 # Approximate unique count for a single key 127.0.0.1:6379> PFCOUNT page:home:visitors # => (integer) 3 # Approximate unique count across multiple keys (union) 127.0.0.1:6379> PFCOUNT page:home:visitors page:about:visitors # => (integer) 5 # Merge multiple HLLs into a new key 127.0.0.1:6379> PFMERGE site:total:visitors page:home:visitors page:about:visitors # => OK 127.0.0.1:6379> PFCOUNT site:total:visitors # => (integer) 5 ``` -------------------------------- ### Get a single field from a Hash Source: https://context7.com/redict/redict/llms.txt Retrieve the value of a specific field from a hash using HGET. Ensure the key and field exist to get a value. ```redis 127.0.0.1:6379> HGET user:1001 name # => "Alice" ``` -------------------------------- ### Piping Hiccup Output to Hdr_decoder Source: https://github.com/redict/redict/blob/main/deps/hdr_histogram/README.md Example of how to pipe the output of the hiccup example to the hdr_decoder for processing, demonstrating a common workflow for analyzing histogram data. ```bash $ ./examples/hiccup | ./examples/hdr_decoder ``` -------------------------------- ### Configure Version String Source: https://github.com/redict/redict/blob/main/deps/jemalloc/INSTALL.md Manually set the version string for jemalloc. This is mandatory for configuration. ```bash ./configure --with-version=1.0.0-1-gabcdef1234567890 ``` -------------------------------- ### Initialize and Record Histogram Values in C Source: https://github.com/redict/redict/blob/main/deps/hdr_histogram/README.md Demonstrates how to initialize an HDR histogram, record single values, multiple values, and values with corrected omissions. Includes printing percentiles in CLASSIC or CSV format. ```C #include struct hdr_histogram* histogram; // Initialise the histogram hdr_init( 1, // Minimum value INT64_C(3600000000), // Maximum value 3, // Number of significant figures &histogram) // Pointer to initialise // Record value hdr_record_value( histogram, // Histogram to record to value) // Value to record // Record value n times hdr_record_values( histogram, // Histogram to record to value, // Value to record 10) // Record value 10 times // Record value with correction for co-ordinated omission. hdr_record_corrected_value( histogram, // Histogram to record to value, // Value to record 1000) // Record with expected interval of 1000. // Print out the values of the histogram hdr_percentiles_print( histogram, stdout, // File to write to 5, // Granularity of printed values 1.0, // Multiplier for results CLASSIC); // Format CLASSIC/CSV supported. ``` -------------------------------- ### coroutine.resume Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Starts or continues the execution of a coroutine. ```APIDOC ## coroutine.resume ### Description Starts or continues the execution of coroutine `co`. The first time you resume a coroutine, it starts running its body. The values `val1`, `...` are passed as the arguments to the body function. If the coroutine has yielded, `resume` restarts it; the values `val1`, `...` are passed as the results from the yield. If the coroutine runs without any errors, `resume` returns **true** plus any values passed to `yield` (if the coroutine yields) or any values returned by the body function (if the coroutine terminates). If there is any error, `resume` returns **false** plus the error message. ### Parameters * `co` (thread) - The coroutine to resume. * `val1, ...` (any) - Optional arguments to pass to the coroutine. ``` -------------------------------- ### Example Lua C Function: Average and Sum Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html An example C function that receives a variable number of numerical arguments from Lua, calculates their average and sum, and returns these two values back to Lua. It includes type checking for arguments. ```c static int foo (lua_State *L) { int n = lua_gettop(L); /* number of arguments */ lua_Number sum = 0; int i; for (i = 1; i <= n; i++) { if (!lua_isnumber(L, i)) { lua_pushstring(L, "incorrect argument"); lua_error(L); } sum += lua_tonumber(L, i); } lua_pushnumber(L, sum/n); /* first result */ lua_pushnumber(L, sum); /* second result */ return 2; /* number of results */ } ``` -------------------------------- ### Standard LGPL Notice for Source Files Source: https://github.com/redict/redict/blob/main/LICENSES/LGPL-3.0-only.txt Include this notice at the beginning of each source file to clearly state the program's name, copyright, and licensing terms under the GNU General Public License. ```text Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ``` -------------------------------- ### file:seek Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Sets and gets the file position. ```APIDOC ## `file:seek ([whence] [, offset])` Sets and gets the file position, measured from the beginning of the file, to the position given by `offset` plus a base specified by the string `whence`, as follows: * **"set":** base is position 0 (beginning of the file); * **"cur":** base is current position; * **"end":** base is end of file; In case of success, function `seek` returns the final file position, measured in bytes from the beginning of the file. If this function fails, it returns **nil**, plus a string describing the error. The default value for `whence` is `"cur"`, and for `offset` is 0. Therefore, the call `file:seek()` returns the current file position, without changing it; the call `file:seek("set")` sets the position to the beginning of the file (and returns 0); and the call `file:seek("end")` sets the position to the end of the file, and returns its size. ``` -------------------------------- ### Buffer Initialization Source: https://github.com/redict/redict/blob/main/deps/lua/doc/contents.html Initializes a string buffer. ```APIDOC ## luaL_buffinit ### Description Initializes a string buffer. ### Function Signature `void luaL_buffinit(lua_State *L, luaL_Buffer *B);` ``` -------------------------------- ### Enable Abort on Illegal Jemalloc Options Source: https://github.com/redict/redict/blob/main/deps/jemalloc/TUNING.md Recommended option to combine with other tunings. Aborts immediately if any specified configuration options are illegal. ```text abort_conf:true ``` -------------------------------- ### Lua Non-Tail Call Examples Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Provides examples of function calls that are NOT tail calls, even when involving 'return'. These include calls with adjusted results, arithmetic operations, multiple return values, or discarded results, which do not reuse the caller's stack frame. ```lua return (f(x)) ``` ```lua return 2 * f(x) ``` ```lua return x, f(x) ``` ```lua f(x); return ``` ```lua return x or f(x) ``` -------------------------------- ### Get current maxmemory setting Source: https://context7.com/redict/redict/llms.txt Retrieves the current value of the 'maxmemory' configuration parameter. ```redis # Get current maxmemory setting 127.0.0.1:6379> CONFIG GET maxmemory # => 1) "maxmemory" # 2) "268435456" ``` -------------------------------- ### Configure TLS for Replication and Cluster Source: https://github.com/redict/redict/blob/main/TLS.md Enable TLS for Redict replication using '--tls-replication yes' and for Redict Cluster nodes using '--tls-cluster yes'. ```bash --tls-replication yes ``` ```bash --tls-cluster yes ``` -------------------------------- ### Get the length of a List Source: https://context7.com/redict/redict/llms.txt Use LLEN to retrieve the number of elements currently in a list. ```redis 127.0.0.1:6379> LLEN jobs:queue # => (integer) 1 ``` -------------------------------- ### Configure Per-CPU Arenas in Jemalloc Source: https://github.com/redict/redict/blob/main/deps/jemalloc/TUNING.md Enable dynamic thread-to-arena association based on running CPU for potential locality improvements. Try 'percpu' or 'phycpu' if thread migration is infrequent. ```text percpu_arena:percpu ``` ```text percpu_arena:phycpu ``` -------------------------------- ### Uninstall Jemalloc Source: https://github.com/redict/redict/blob/main/deps/jemalloc/INSTALL.md To remove the installed jemalloc build artifacts, use the 'make uninstall' command. ```bash make uninstall ``` -------------------------------- ### Get all members of a Set Source: https://context7.com/redict/redict/llms.txt Use SMEMBERS to retrieve all the members of a set. Note that sets are unordered. ```redis 127.0.0.1:6379> SMEMBERS tags:article:1 # => 1) "redict" # 2) "database" # 3) "nosql" ``` -------------------------------- ### luaL_buffinit Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Initializes a luaL_Buffer for use. ```APIDOC ## luaL_buffinit ### Description Initializes a buffer `B`. This function does not allocate any space; the buffer must be declared as a variable. ### Signature `void luaL_buffinit (lua_State *L, luaL_Buffer *B);` ``` -------------------------------- ### Build Redict with TLS Support Source: https://github.com/redict/redict/blob/main/TLS.md Use 'BUILD_TLS=yes' to build TLS support as a Redict built-in, or 'BUILD_TLS=module' to build it as a Redict module. Sentinel mode does not support the TLS module. ```bash make BUILD_TLS=yes ``` ```bash make BUILD_TLS=module ``` -------------------------------- ### Lua string.lower example Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Shows the basic usage of string.lower to convert all uppercase letters in a string to lowercase. ```lua string.lower("Hello World") ``` -------------------------------- ### Redict Configuration File (redict.conf) Source: https://context7.com/redict/redict/llms.txt Key directives for configuring Redict, including networking, persistence, security, memory management, and logging. Ensure correct settings for your environment. ```conf # Bind to loopback only (safe default) bind 127.0.0.1 -::1 # Default port port 6379 # Enable protected mode (blocks remote connections without auth) protected-mode yes # Harden: restrict debug/config/module commands enable-protected-configs no enable-debug-command no enable-module-command no # Persistence: RDB snapshot triggers save 3600 1 300 100 60 10000 # Append-only file for durability appendonly yes appendfilename "appendonly.aof" appendfsync everysec # Maximum memory and eviction policy maxmemory 256mb maxmemory-policy allkeys-lru # Number of logical databases (0-15) databases 16 # Logging loglevel notice logfile "" # Load a module at startup # loadmodule /path/to/module.so # Include additional config fragments # include /path/to/fragments/*.conf ``` -------------------------------- ### Configure Lua Initialization Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html The LUA_INIT environment variable can specify a file or string to be executed before any script. '@filename' executes a file, otherwise the string is executed. ```bash export LUA_INIT=@my_init.lua ``` ```bash export LUA_INIT='a=1; print(a)' ``` -------------------------------- ### Lua Function Definition Syntax Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Illustrates the basic syntax for defining a function in Lua. ```lua function f () _body_ end ``` -------------------------------- ### Lua: Get Binary Operation Handler Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Helper function to retrieve a metamethod for a binary operation from either operand. ```lua function getbinhandler (op1, op2, event) return metatable(op1)[event] or metatable(op2)[event] end ``` -------------------------------- ### Lua string.len example Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Illustrates the string.len function, showing that embedded null characters are counted towards the length. ```lua string.len("a\000bc\000") ``` -------------------------------- ### Configure and Run Hiredict Tests Source: https://github.com/redict/redict/blob/main/deps/hiredict/CMakeLists.txt Enables testing for Hiredict, creating a test executable and linking it with the hiredict library. It conditionally links hiredict_ssl, event, and defines test flags based on build configurations. ```cmake IF(NOT DISABLE_TESTS) ENABLE_TESTING() ADD_EXECUTABLE(hiredict-test src/test.c) TARGET_LINK_LIBRARIES(hiredict-test hiredict) IF(ENABLE_SSL_TESTS) ADD_DEFINITIONS(-DHIREDICT_TEST_SSL=1) TARGET_LINK_LIBRARIES(hiredict-test hiredict_ssl) ENDIF() IF(ENABLE_ASYNC_TESTS) ADD_DEFINITIONS(-DHIREDICT_TEST_ASYNC=1) TARGET_LINK_LIBRARIES(hiredict-test event) ENDIF() ADD_TEST(NAME hiredict-test COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/util/test.sh) ENDIF() ``` -------------------------------- ### Lua Syntactic Sugar for Function Definitions Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Demonstrates Lua's syntactic sugar for defining functions, simplifying common declaration patterns. ```lua function t.a.b.c.f () _body_ end ``` -------------------------------- ### GET — Retrieve a String Value Source: https://context7.com/redict/redict/llms.txt Returns the string value of a key. Returns nil if the key does not exist or is not a string. ```APIDOC ## GET — Retrieve a String Value Returns the string value of a key in O(1). Returns `nil` if the key does not exist or if the key's type is not a string. ### Method GET ### Endpoint /GET ### Parameters #### Query Parameters - **key** (string) - Required - The key whose value is to be retrieved. ### Request Example ```bash 127.0.0.1:6379> GET name # => "Redict" 127.0.0.1:6379> GET missing_key # => (nil) ``` ### Response #### Success Response (200) - **value** (string) - The string value of the key, or nil if the key does not exist or is not a string. ``` -------------------------------- ### Get geohash string for a city using GEOHASH Source: https://context7.com/redict/redict/llms.txt Retrieves the geohash string representation for the city 'Paris' from the 'cities' geospatial index. ```redis # Get geohash string for a member 127.0.0.1:6379> GEOHASH cities "Paris" # => 1) "u09tunquc70" ``` -------------------------------- ### io.popen Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Opens a pipe to or from a process. ```APIDOC ## io.popen (prog [, mode]) ### Description Starts a program in a separate process and returns a file handle to read from or write to the program's standard input/output. This function is system-dependent. ### Parameters * **prog** (string) - The program to execute. * **mode** (string, optional) - The mode to open the pipe. Defaults to "r" (read from program). Use "w" to write to the program. ### Returns * (file handle) - A file handle for interacting with the process. * (nil, string, number) - `nil`, an error message, and an error code if the process cannot be started. ``` -------------------------------- ### Lua Comments Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Shows examples of short comments that run until the end of the line and long comments that are enclosed by matching long brackets. ```lua -- This is a short comment ``` ```lua --[[ This is a long comment It can span multiple lines. ]] ``` -------------------------------- ### Create a New Table with lua_createtable Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Creates a new, empty table and pushes it onto the Lua stack. Allows pre-allocation for array and non-array elements to optimize performance when the table size is known. ```c void lua_createtable (lua_State *L, int narr, int nrec); ``` -------------------------------- ### Get Current Hook Mask in Lua Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Retrieves the current hook mask for the Lua state. The mask indicates which events trigger the hook. ```c int lua_gethookmask (lua_State *L); ``` -------------------------------- ### Get Lua Stack Information Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Retrieves information about the Lua runtime stack. Fills a lua_Debug structure with details of the activation record at a given level. ```c int lua_getstack (lua_State *L, int level, lua_Debug *ar); ``` -------------------------------- ### Run Redict Test Suites Source: https://context7.com/redict/redict/llms.txt Execute Redict's comprehensive test suites using various scripts like './runtest' for the full suite, './runtest-cluster' for cluster mode, './runtest-moduleapi' for module API tests, and './runtest-sentinel' for Sentinel tests. ```bash # Full test suite ./runtest # Cluster-mode tests ./runtest-cluster # Module API tests ./runtest-moduleapi # Sentinel tests ./runtest-sentinel ``` -------------------------------- ### Get Current Hook Count in Lua Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Retrieves the current hook count set for the Lua state. This count determines how often the hook is called. ```c int lua_gethookcount (lua_State *L); ``` -------------------------------- ### package.seeall (module) Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Sets a metatable for a module so that it inherits values from the global environment. This is an option for the `module` function. ```APIDOC ## `package.seeall (module)` ### Description Sets a metatable for `module` with its `__index` field referring to the global environment, so that this module inherits values from the global environment. To be used as an option to function `module`. ### Parameters * `module` (table) - The module to set the metatable for. ``` -------------------------------- ### Run Redict Tests with External Server Source: https://github.com/redict/redict/blob/main/tests/README.md Execute the test suite against an external Redict server by specifying host and port. Tests tagged with `external:skip` will be automatically skipped. ```bash ./runtest --host --port ``` -------------------------------- ### Retrieve a range of elements from a List Source: https://context7.com/redict/redict/llms.txt Use LRANGE to get a slice of elements from a list by their indices. Use 0 and -1 to retrieve the entire list. ```redis 127.0.0.1:6379> LRANGE jobs:queue 0 -1 # => 1) "job1" # 2) "job2" # 3) "job3" ``` -------------------------------- ### Generate Header Files with cl Source: https://github.com/redict/redict/blob/main/deps/jemalloc/msvc/ReadMe.txt Use this command within the Cygwin environment and Visual Studio command prompt to generate necessary header files for the build. ```shell sh -c "CC=cl ./autogen.sh" ``` -------------------------------- ### Get all fields and values from a Hash Source: https://context7.com/redict/redict/llms.txt Use HGETALL to retrieve all field-value pairs from a hash. This command returns a flat list of alternating fields and values. ```redis 127.0.0.1:6379> HGETALL user:1001 # => 1) "name" # 2) "Alice" # 3) "email" # 4) "alice@example.com" # 5) "age" # 6) "30" ``` -------------------------------- ### luaL_prepbuffer Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Returns an address to a space of size LUAL_BUFFERSIZE where a string can be copied to be added to a buffer. ```APIDOC ## `luaL_prepbuffer` ### Description Returns an address to a space of size `LUAL_BUFFERSIZE` where you can copy a string to be added to buffer `B` (see [`luaL_Buffer`](#luaL_Buffer)). After copying the string into this space you must call [`luaL_addsize`](#luaL_addsize) with the size of the string to actually add it to the buffer. ### Signature ```c char *luaL_prepbuffer (luaL_Buffer *B); ``` ``` -------------------------------- ### Enable Heap Profiling Source: https://github.com/redict/redict/blob/main/deps/jemalloc/INSTALL.md Enable heap profiling and leak detection functionality. The configure script selects the best available backtracing method. ```bash --enable-prof ``` -------------------------------- ### Get Function Information in Lua Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Retrieves detailed information about a function or function invocation. Requires a valid lua_Debug structure and a 'what' string specifying the desired information. ```c int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); ``` ```c lua_Debug ar; lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* get global 'f' */ lua_getinfo(L, ">S", &ar); printf("%d\n", ar.linedefined); ``` -------------------------------- ### io.open Source: https://github.com/redict/redict/blob/main/deps/lua/doc/manual.html Opens a file with a specified mode. ```APIDOC ## io.open (filename [, mode]) ### Description Opens a file with the given filename and mode. Returns a file handle or `nil` on error. ### Parameters * **filename** (string) - The name of the file to open. * **mode** (string, optional) - The mode to open the file in. Defaults to "r". * "r": read mode * "w": write mode * "a": append mode * "r+": update mode, read/write, preserve data * "w+": update mode, read/write, truncate data * "a+": append update mode, read/write, append only * Append 'b' for binary mode (e.g., "rb", "wb"). ### Returns * (file handle) - A file handle for the opened file. * (nil, string, number) - `nil`, an error message, and an error code if opening fails. ```