### Install Build Prerequisites Source: https://github.com/apache/kvrocks/blob/unstable/README.md Installs necessary packages for building Kvrocks on Ubuntu/Debian systems. Ensure you have `sudo` privileges. ```shell sudo apt update sudo apt install -y git build-essential cmake libtool python3 libssl-dev ``` -------------------------------- ### Install Build Prerequisites (openSUSE/SUSE) Source: https://github.com/apache/kvrocks/blob/unstable/README.md Installs necessary packages for building Kvrocks on openSUSE and SUSE Linux Enterprise systems. ```shell sudo zypper install -y gcc11 gcc11-c++ make wget git autoconf automake python3 curl cmake ``` -------------------------------- ### Install Build Prerequisites (macOS) Source: https://github.com/apache/kvrocks/blob/unstable/README.md Installs necessary packages for building Kvrocks on macOS using Homebrew. Includes linking OpenSSL if necessary. ```shell brew install git cmake autoconf automake libtool openssl # please link openssl by force if it still cannot be found after installing brew link --force openssl ``` -------------------------------- ### Install Build Prerequisites (CentOS/RedHat) Source: https://github.com/apache/kvrocks/blob/unstable/README.md Installs necessary packages for building Kvrocks on CentOS/RedHat systems. This includes enabling SCL and installing development tools. CMake is downloaded and installed separately. ```shell sudo yum install -y centos-release-scl-rh sudo yum install -y git devtoolset-11 autoconf automake libtool libstdc++-static python3 openssl-devel # download and install cmake via https://cmake.org/download wget https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-linux-x86_64.sh -O cmake.sh sudo bash cmake.sh --skip-license --prefix=/usr # enable gcc and make in devtoolset-11 source /opt/rh/devtoolset-11/enable ``` -------------------------------- ### Build Kvrocks from Source Source: https://context7.com/apache/kvrocks/llms.txt Install dependencies, clone the repository, and build Kvrocks. Supports different build types like RelWithDebInfo, Debug, and with TLS support. ```shell # Install dependencies (Ubuntu/Debian) sudo apt install -y git build-essential cmake libtool python3 libssl-dev # Clone and build git clone https://github.com/apache/kvrocks.git cd kvrocks ./x.py build # default RelWithDebInfo build ./x.py build -DENABLE_OPENSSL=ON # with TLS support ./x.py build -DCMAKE_BUILD_TYPE=Debug # Run ./build/kvrocks -c kvrocks.conf # Connect with redis-cli redis-cli -p 6666 127.0.0.1:6666> PING PONG ``` -------------------------------- ### Install Build Prerequisites (Arch Linux) Source: https://github.com/apache/kvrocks/blob/unstable/README.md Installs necessary packages for building Kvrocks on Arch Linux systems. ```shell sudo pacman -Sy --noconfirm autoconf automake python3 git wget which cmake make gcc ``` -------------------------------- ### Run Kvrocks Locally Source: https://github.com/apache/kvrocks/blob/unstable/README.md Starts the Kvrocks server using the specified configuration file. ```shell $ ./build/kvrocks -c kvrocks.conf ``` -------------------------------- ### Conventional Commit Message Examples Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Examples of conventional commit messages with scopes for different components. ```text feat(rdb): add DUMP support for SortedInt type fix(replication): prevent WAL exhaustion from slow consumers fix(string): add empty string value check for INCR to match Redis behavior perf(hash): use MultiGet to reduce RocksDB calls in HMSET chore(deps): Bump rocksdb to v10.10.1 chore(ci): bump crate-ci/typos action to v1.43.1 chore(tests): replace to slices.Reverse() in go test ``` -------------------------------- ### Basic String Operations with redis-cli Source: https://context7.com/apache/kvrocks/llms.txt Demonstrates standard Redis string commands like SET, GET, MSET, MGET, INCR, INCRBY, SETEX, TTL, GETEX, and GETDEL using redis-cli. ```shell redis-cli -p 6666 << 'EOF' SET user:1001 "Alice" GET user:1001 # "Alice" SET counter 100 INCR counter # (integer) 101 INCRBY counter 49 # (integer) 150 SET session:abc "token123" EX 3600 # expires in 1 hour TTL session:abc # (integer) 3600 MSET k1 v1 k2 v2 k3 v3 MGET k1 k2 k3 # 1) "v1" # 2) "v2" # 3) "v3" GETEX session:abc PERSIST # remove TTL GETDEL user:1001 # get-and-delete atomically # "Alice" EOF ``` -------------------------------- ### Build Kvrocks with TLS Support Source: https://github.com/apache/kvrocks/blob/unstable/README.md Builds Kvrocks with TLS support enabled. Requires OpenSSL development libraries to be installed. ```shell $ ./x.py build -DENABLE_OPENSSL=ON ``` -------------------------------- ### NAMESPACE ADD / SET / GET / DEL Source: https://context7.com/apache/kvrocks/llms.txt Commands for managing namespaces, providing multi-tenant data isolation with unique keyspaces and authentication tokens. ```APIDOC ## NAMESPACE ADD ### Description Creates a new namespace with a specified name and authentication token. ### Method NAMESPACE ADD ### Endpoint (Not applicable, command-line interface) ### Parameters - **namespace_name** (string) - Required - The name of the namespace. - **auth_token** (string) - Required - The authentication token for the namespace. ## NAMESPACE SET ### Description Updates the authentication token for an existing namespace. ### Method NAMESPACE SET ### Endpoint (Not applicable, command-line interface) ### Parameters - **namespace_name** (string) - Required - The name of the namespace. - **new_auth_token** (string) - Required - The new authentication token. ## NAMESPACE GET ### Description Retrieves a list of all namespaces and their associated authentication tokens. ### Method NAMESPACE GET ### Endpoint (Not applicable, command-line interface) ### Parameters - **filter** (string) - Optional - A filter pattern to retrieve specific namespaces (e.g., '*'). ## NAMESPACE DEL ### Description Deletes a specified namespace. ### Method NAMESPACE DEL ### Endpoint (Not applicable, command-line interface) ### Parameters - **namespace_name** (string) - Required - The name of the namespace to delete. ``` -------------------------------- ### Manage Namespaces for Data Isolation Source: https://context7.com/apache/kvrocks/llms.txt NAMESPACE ADD creates a new tenant namespace with a secret token. NAMESPACE SET updates the token. NAMESPACE GET lists namespaces. NAMESPACE DEL removes a namespace. Connect with namespace tokens for isolated access. ```shell redis-cli -p 6666 -a my_admin_password << 'EOF' # Create a namespace with a token NAMESPACE ADD tenant_acme acme_secret_token_xyz # OK # Update the token NAMESPACE SET tenant_acme new_acme_token_abc # OK # List all namespaces (returns alternating namespace/token pairs) NAMESPACE GET * # 1) "tenant_acme" # 2) "new_acme_token_abc" # 3) "__namespace" (default namespace) # 4) "my_admin_password" # Connect as a namespace user (all keys are scoped to tenant_acme) redis-cli -p 6666 -a new_acme_token_abc SET mykey "tenant_value" redis-cli -p 6666 -a new_acme_token_abc GET mykey # "tenant_value" # Delete namespace NAMESPACE DEL tenant_acme # OK EOF ``` -------------------------------- ### Fetch Dependencies Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Download and fetch necessary project dependencies. ```bash # Fetch dependencies ./x.py fetch-deps # Fetch dependency archives ``` -------------------------------- ### Run Go Integration Tests Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Execute the integration tests written in Go. ```bash # Run Go integration tests ./x.py test go ``` -------------------------------- ### Build and Run C++ Unit Tests Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Build the project with unit tests enabled and then execute the C++ unit tests. ```bash # Build and run C++ unit tests ./x.py build --unittest ./x.py test cpp ``` -------------------------------- ### Connect to Kvrocks Service Source: https://github.com/apache/kvrocks/blob/unstable/README.md Connects to a running Kvrocks service using `redis-cli` on the default port 6666. Demonstrates a basic GET command. ```shell $ redis-cli -p 6666 127.0.0.1:6666> get a (nil) ``` -------------------------------- ### Create and Query Full-Text Search Indexes Source: https://context7.com/apache/kvrocks/llms.txt FT.CREATE defines search indexes on HASH or JSON keys. FT.SEARCH and FT.SEARCHSQL are used to query these indexes using RediSearch query syntax or SQL. ```shell HSET product:1 name "Laptop" category "electronics" price "999.99" in_stock "true" ``` ```shell HSET product:2 name "Phone" category "electronics" price "499.00" in_stock "true" ``` ```shell HSET product:3 name "Desk" category "furniture" price "249.00" in_stock "false" ``` ```shell FT.CREATE idx:products \ ON HASH \ PREFIX 1 product: \ SCHEMA \ name TAG \ category TAG \ price NUMERIC \ in_stock TAG ``` ```shell FT.SEARCH idx:products "@category:{electronics} @price:[400 1100]" ``` ```shell FT.SEARCHSQL 'SELECT * FROM "idx:products" WHERE category = "electronics" AND price BETWEEN 400 AND 1100' ``` ```shell FT.CREATE idx:embeddings \ ON HASH \ PREFIX 1 emb: \ SCHEMA vec VECTOR HNSW 6 TYPE FLOAT64 DIM 3 DISTANCE_METRIC COSINE ``` ```shell HSET emb:1 vec "\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" ``` ```shell FT.EXPLAINSQL 'SELECT * FROM "idx:products" WHERE price < 500' simple ``` -------------------------------- ### Run Golangci-Lint Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Execute the golangci-lint linter for Go code, ensuring it meets project standards. ```bash # Run golangci-lint for Go tests ./x.py check golangci-lint ``` -------------------------------- ### Get Kvrocks Cluster Topology Version Source: https://github.com/apache/kvrocks/wiki/Kvrocks-集群方案简介 Use CLUSTERX VERSION to retrieve the current version number of the cluster topology stored on a node. This is used for verifying the correctness of the topology. ```redis CLUSTERX VERSION ``` -------------------------------- ### Run Local Kvrocks Server Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Execute a local Kvrocks server instance using a specified configuration file. ```bash # Run a local server ./build/kvrocks -c kvrocks.conf ``` -------------------------------- ### Stream Operations in Kvrocks Source: https://context7.com/apache/kvrocks/llms.txt Manage append-only log streams for event sourcing and message queuing. Supports adding entries with auto-generated IDs, reading ranges, getting stream length, and creating consumer groups for distributed processing. ```shell XADD events:orders "*" order_id 1001 status "placed" amount "49.99" XADD events:orders "*" order_id 1002 status "placed" amount "129.00" XRANGE events:orders - + XLEN events:orders XGROUP CREATE events:orders mygroup $ MKSTREAM ``` -------------------------------- ### Configure and Build Kvrocks with Ninja Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Configure the build system with Ninja for faster incremental builds. The default generator is Makefiles unless --ninja is specified. ```bash # Configure with Ninja when you want faster incremental builds. # The default generator is Makefiles unless --ninja is specified. ./x.py build --ninja ``` -------------------------------- ### Bitmap Operations in Kvrocks Source: https://context7.com/apache/kvrocks/llms.txt Perform bit-level operations on string keys, useful for compact boolean or counting data structures. Supports setting and getting bits, counting set bits, finding bit positions, and bitwise operations like AND. ```shell SETBIT user:active:2024-01-15 1001 1 SETBIT user:active:2024-01-15 1042 1 SETBIT user:active:2024-01-15 5000 1 GETBIT user:active:2024-01-15 1001 BITCOUNT user:active:2024-01-15 BITPOS user:active:2024-01-15 1 BITOP AND active:both user:active:2024-01-15 user:active:2024-01-16 BITCOUNT active:both ``` -------------------------------- ### Hash Field Operations in Kvrocks Source: https://context7.com/apache/kvrocks/llms.txt Perform operations on hash fields, including retrieving multiple fields, getting all fields, incrementing a field's value, checking the number of fields, and scanning fields. Supports per-field TTL expiration. ```shell HMGET product:42 name price stock HGETALL product:42 HINCRBY product:42 stock -5 HLEN product:42 HSCAN product:42 0 COUNT 100 HEXPIRE product:42 300 FIELDS 1 stock HPTTL product:42 FIELDS 1 stock ``` -------------------------------- ### Build Kvrocks Source: https://github.com/apache/kvrocks/blob/unstable/README.md Clones the Kvrocks repository and builds the project using the provided script. Use `./x.py build -h` for more build options. ```shell $ git clone https://github.com/apache/kvrocks.git $ cd kvrocks $ ./x.py build # `./x.py build -h` to check more options ``` -------------------------------- ### Configure Asynchronous Replication (Leader/Replica) Source: https://context7.com/apache/kvrocks/llms.txt Use SLAVEOF on the replica to point to the master. INFO replication checks status. SLAVEOF NO ONE promotes a replica to master. Master requires specific config and `masterauth` if `requirepass` is set. ```shell # --- On the master node (port 6666) --- # kvrocks.conf must have: db-name production-cluster # requirepass master_password # masterauth master_password (for replica-chain auth) # --- On the replica node (port 6667) --- # kvrocks.conf: db-name production-cluster (must match master) # masterauth master_password redis-cli -p 6667 << 'EOF' # Start replicating from master SLAVEOF 127.0.0.1 6666 # Check replication status INFO replication # # Replication # role:slave # master_host:127.0.0.1 # master_port:6666 # master_link_status:up # master_repl_offset:12345 # Promote replica to master (stop replication) SLAVEOF NO ONE EOF # Monitor replication lag on master redis-cli -p 6666 INFO replication | grep -E "connected_slaves|slave0" # connected_slaves:1 # slave0:ip=127.0.0.1,port=6667,state=online,offset=12345,lag=0 ``` -------------------------------- ### Build Kvrocks and Utilities Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Build the Kvrocks project and its utilities. Supports parallel jobs, unit tests, TLS support, and different build types. ```bash # Build kvrocks and utilities ./x.py build # Build to ./build directory ./x.py build -j N # Build with N parallel jobs ./x.py build --unittest # Build with unit tests ./x.py build -DENABLE_OPENSSL=ON # Build with TLS support ./x.py build --ninja # Use Ninja build system ./x.py build --skip-build # Only run CMake configure ./x.py build -DCMAKE_BUILD_TYPE=Debug # Debug build ``` -------------------------------- ### Run Kvrocks with Docker Source: https://context7.com/apache/kvrocks/llms.txt Deploy Kvrocks using Docker, including options for the latest stable release, nightly builds, and mounting custom configuration files. ```shell # Latest stable release docker run -it -p 6666:6666 apache/kvrocks --bind 0.0.0.0 # Nightly development image docker run -it -p 6666:6666 apache/kvrocks:nightly --bind 0.0.0.0 # With a custom config file mounted docker run -it -p 6666:6666 \ -v /path/to/kvrocks.conf:/kvrocks.conf \ -v /data/kvrocks:/tmp/kvrocks \ apache/kvrocks --config /kvrocks.conf ``` -------------------------------- ### BF.RESERVE / BF.ADD / BF.EXISTS Source: https://context7.com/apache/kvrocks/llms.txt Commands for scalable probabilistic membership testing using Bloom filters. Supports adding and checking for the existence of items. ```APIDOC ## BF.RESERVE / BF.ADD / BF.EXISTS ### Description Commands for Bloom filters, which provide O(1) probabilistic membership tests with a configurable false-positive rate. Kvrocks uses a scalable chained Bloom filter that can automatically grow. ### Method N/A (These are command-line examples for redis-cli) ### Endpoint N/A ### Parameters N/A ### Request Example ```shell redis-cli -p 6666 << 'EOF' # Create a bloom filter: capacity 1000, 1% false-positive rate BF.RESERVE blocked:ips 0.01 1000 BF.ADD blocked:ips "192.168.1.100" # (integer) 1 (newly added) BF.ADD blocked:ips "10.0.0.5" BF.EXISTS blocked:ips "192.168.1.100" # (integer) 1 (probably in set) BF.EXISTS blocked:ips "8.8.8.8" # (integer) 0 (definitely NOT in set) # Add multiple at once BF.MADD blocked:ips "1.2.3.4" "5.6.7.8" "9.10.11.12" # 1) (integer) 1 # 2) (integer) 1 # 3) (integer) 1 BF.MEXISTS blocked:ips "1.2.3.4" "8.8.8.8" # 1) (integer) 1 # 2) (integer) 0 BF.INFO blocked:ips # 1) "Capacity" 2) (integer) 1000 # 3) "Size" 4) (integer) ... # 5) "Number of filters" 6) (integer) 1 # 7) "Number of items inserted" 8) (integer) 5 # 9) "Expansion rate" 10) (integer) 2 EOF ``` ### Response `BF.ADD` and `BF.MADD` return an integer indicating if the item was newly added. `BF.EXISTS` and `BF.MEXISTS` return an integer (1 for possibly present, 0 for definitely not present). `BF.INFO` returns details about the Bloom filter's configuration and status. ``` -------------------------------- ### Check Code Format Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Verify that the code adheres to the project's formatting standards. This command fails if the code is not properly formatted. ```bash # Check code format (fails if not formatted) ./x.py check format ``` -------------------------------- ### Run Kvrocks Test Cases Source: https://github.com/apache/kvrocks/blob/unstable/README.md Execute build and unit tests for Kvrocks using the x.py script. Supports C++ and Golang test suites. ```shell $ ./x.py build --unittest ``` ```shell $ ./x.py test cpp # run C++ unit tests ``` ```shell $ ./x.py test go # run Golang (unit and integration) test cases ``` -------------------------------- ### Format Code Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Apply code formatting to the project. This must pass before submitting code changes. ```bash # Format code (must pass before submitting) ./x.py format ``` -------------------------------- ### FT.CREATE / FT.SEARCH / FT.SEARCHSQL Source: https://context7.com/apache/kvrocks/llms.txt Commands for full-text, numeric, tag, and vector search. Supports both RediSearch query syntax and an extended SQL dialect. ```APIDOC ## FT.CREATE / FT.SEARCH / FT.SEARCHSQL ### Description Commands for creating and querying full-text, numeric, tag, and vector search indexes. Kvrocks Search (KQIR) supports indexing HASH or JSON keys and offers both RediSearch query syntax and an extended SQL dialect. ### Method N/A (These are command-line examples for redis-cli) ### Endpoint N/A ### Parameters N/A ### Request Example ```shell redis-cli -p 6666 << 'EOF' # Store some documents as hashes HSET product:1 name "Laptop" category "electronics" price "999.99" in_stock "true" HSET product:2 name "Phone" category "electronics" price "499.00" in_stock "true" HSET product:3 name "Desk" category "furniture" price "249.00" in_stock "false" # Create a search index on all hashes with prefix "product:" FT.CREATE idx:products \ ON HASH \ PREFIX 1 product: \ SCHEMA \ name TAG \ category TAG \ price NUMERIC \ in_stock TAG # Query: electronics with price between 400 and 1100 FT.SEARCH idx:products "@category:{electronics} @price:[400 1100]" # 1) (integer) 2 # 2) "product:1" # 3) 1) "name" 2) "Laptop" 3) "category" 4) "electronics" ... # 4) "product:2" # ... # Equivalent SQL query FT.SEARCHSQL 'SELECT * FROM "idx:products" WHERE category = "electronics" AND price BETWEEN 400 AND 1100' # VECTOR index (HNSW) for semantic / nearest-neighbor search FT.CREATE idx:embeddings \ ON HASH \ PREFIX 1 emb: \ SCHEMA vec VECTOR HNSW 6 TYPE FLOAT64 DIM 3 DISTANCE_METRIC COSINE HSET emb:1 vec "\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" # ... (binary FLOAT64 vector data) # Inspect the query execution plan FT.EXPLAINSQL 'SELECT * FROM "idx:products" WHERE price < 500' simple EOF ``` ### Response Responses include the number of documents found, document IDs, and their fields for `FT.SEARCH`, and similar results for `FT.SEARCHSQL`. `FT.EXPLAINSQL` provides query plan details. ``` -------------------------------- ### Build kvrocks2redis Migration Tool Source: https://context7.com/apache/kvrocks/llms.txt Compile the kvrocks2redis utility using the provided build script. This tool is used for incremental synchronization of Kvrocks data to Redis. ```shell # Build the tool ./x.py build ``` -------------------------------- ### Configure Kvrocks Migration Settings Source: https://context7.com/apache/kvrocks/llms.txt Configure the kvrocks2redis migration tool by specifying log level, data directories, and namespace mappings to Redis databases. Ensure the output directory exists. ```shell cat > kvrocks2redis.conf << 'CONF' log-level INFO daemonize no data-dir /var/lib/kvrocks # kvrocks data directory output-dir /tmp/kvrocks2redis # for intermediate AOF and offset files cluster-enabled no # Map kvrocks default namespace to Redis DB 0 namespace.__namespace 127.0.0.1 6379 redis_password 0 # Map a named namespace to Redis DB 1 namespace.tenant_acme 127.0.0.1 6379 redis_password 1 CONF ``` ```shell # Run migration (will attempt incremental sync first, fall back to full parse) ./build/kvrocks2redis -c kvrocks2redis.conf ``` -------------------------------- ### Create, Add, and Query Time Series Data Source: https://context7.com/apache/kvrocks/llms.txt Use TS.CREATE to set up a time series with retention and duplicate policies. TS.ADD inserts samples with timestamps (or auto-generation). TS.RANGE queries data within a time window, supporting aggregation. ```shell redis-cli -p 6666 << 'EOF' # Create series: 7-day retention, last-write-wins duplicates TS.CREATE metrics:cpu RETENTION 604800000 DUPLICATE_POLICY LAST # Add samples (timestamp in milliseconds; 0 = auto server time) TS.ADD metrics:cpu 1700000000000 45.2 TS.ADD metrics:cpu 1700000060000 47.8 TS.ADD metrics:cpu 1700000120000 52.1 TS.ADD metrics:cpu 0 49.5 # current time # Query a time range TS.RANGE metrics:cpu 1700000000000 1700000120000 # 1) 1) (integer) 1700000000000 2) "45.2" # 2) 1) (integer) 1700000060000 2) "47.8" # 3) 1) (integer) 1700000120000 2) "52.1" # Aggregated range: average per 60-second bucket TS.RANGE metrics:cpu - + AGGREGATION avg 60000 # 1) 1) (integer) 1700000000000 2) "46.5" # 2) 1) (integer) 1700000120000 2) "52.1" # Query last value TS.GET metrics:cpu # 1) (integer) 1700000180000 2) "49.5" TS.INFO metrics:cpu # 1) "totalSamples" 2) (integer) 4 # ... EOF ``` -------------------------------- ### Kvrocks Lua Scripting with EVAL and Functions Source: https://context7.com/apache/kvrocks/llms.txt Run atomic server-side scripts using EVAL for inline scripts or load and execute functions using the Functions API (FUNCTION LOAD, FCALL). Scripts can improve performance when 'lua-strict-key-accessing' is enabled. ```shell redis-cli -p 6666 << 'EOF' # Inline script: atomic conditional set EVAL " local current = redis.call('GET', KEYS[1]) if current == ARGV[1] then redis.call('SET', KEYS[1], ARGV[2]) return 1 end return 0 " 1 mykey "expected_value" "new_value" # (integer) 1 # Load a named function library (Redis Functions API) FUNCTION LOAD "#!lua name=mylib\n local function myadd(keys, args) return redis.call('INCRBY', keys[1], args[1]) end redis.register_function('myadd', myadd) " # "mylib" FCALL myadd 1 counter 10 # (integer) 10 FUNCTION LIST LIBRARYNAME mylib WITHCODE # 1) 1) "library_name" 2) "mylib" # 3) "engine" 4) "LUA" # 5) "functions" ... FUNCTION DELETE mylib EOF ``` -------------------------------- ### Run Kvrocks using Docker Source: https://github.com/apache/kvrocks/blob/unstable/README.md Launches a Kvrocks instance using Docker, exposing the default port 6666. You can use the `nightly` image for the latest build. ```shell $ docker run -it -p 6666:6666 apache/kvrocks --bind 0.0.0.0 # or get the nightly image: $ docker run -it -p 6666:6666 apache/kvrocks:nightly ``` -------------------------------- ### Populate kvrocks Data Script Source: https://github.com/apache/kvrocks/blob/unstable/utils/kvrocks2redis/tests/README.md Use this script to populate data into kvrocks. Specify host, port, and password as needed. The FLUSHDB option can be used to clear existing data before populating. ```bash python3 populate-kvrocks.py [--host HOST] [--port PORT] [--password PASSWORD] [--flushdb FLUSHDB] ``` -------------------------------- ### Manage Bloom Filters Source: https://context7.com/apache/kvrocks/llms.txt BF.RESERVE initializes a Bloom filter with a specified capacity and false-positive rate. BF.ADD and BF.EXISTS test for membership. BF.MADD and BF.MEXISTS operate on multiple items. ```shell BF.RESERVE blocked:ips 0.01 1000 ``` ```shell BF.ADD blocked:ips "192.168.1.100" ``` ```shell BF.ADD blocked:ips "10.0.0.5" ``` ```shell BF.EXISTS blocked:ips "192.168.1.100" ``` ```shell BF.EXISTS blocked:ips "8.8.8.8" ``` ```shell BF.MADD blocked:ips "1.2.3.4" "5.6.7.8" "9.10.11.12" ``` ```shell BF.MEXISTS blocked:ips "1.2.3.4" "8.8.8.8" ``` ```shell BF.INFO blocked:ips ``` -------------------------------- ### Run Clang-Tidy Source: https://github.com/apache/kvrocks/blob/unstable/AGENTS.md Execute the clang-tidy linter to check for C++ code quality issues. ```bash # Run clang-tidy ./x.py check tidy ``` -------------------------------- ### Kvrocks Transactions with MULTI/EXEC/WATCH Source: https://context7.com/apache/kvrocks/llms.txt Execute atomic command batches using MULTI and EXEC. WATCH provides optimistic locking, aborting the transaction if watched keys change before EXEC. DISCARD cancels a queued transaction. ```shell redis-cli -p 6666 << 'EOF' SET balance:alice 1000 SET balance:bob 500 WATCH balance:alice MULTI DECRBY balance:alice 200 INCRBY balance:bob 200 EXEC # 1) (integer) 800 # 2) (integer) 700 # (If alice's balance was modified between WATCH and EXEC, EXEC returns nil) # DISCARD aborts a queued transaction MULTI SET temp "value" DISCARD # OK (transaction discarded, SET was never run) EOF ``` -------------------------------- ### Build Kvrocks with Lua Support Source: https://github.com/apache/kvrocks/blob/unstable/README.md Builds Kvrocks using Lua instead of LuaJIT. Set `ENABLE_LUAJIT` to `OFF`. ```shell $ ./x.py build -DENABLE_LUAJIT=OFF ``` -------------------------------- ### Create, Add, and Query T-Digest Quantiles Source: https://context7.com/apache/kvrocks/llms.txt TDIGEST.CREATE initializes a T-Digest structure with specified compression. TDIGEST.ADD inserts streaming data points. TDIGEST.QUANTILE retrieves estimated quantiles (e.g., p50, p95). ```shell redis-cli -p 6666 << 'EOF' TDIGEST.CREATE latency:api COMPRESSION 100 # Add observed latency values (milliseconds) TDIGEST.ADD latency:api 12.5 15.3 18.7 22.1 45.9 102.3 8.4 11.2 19.8 200.1 TDIGEST.QUANTILE latency:api 0.5 0.95 0.99 # 1) "17.25" p50 (median) # 2) "151.2" p95 # 3) "200.1" p99 TDIGEST.MIN latency:api # "8.4" TDIGEST.MAX latency:api # "200.1" TDIGEST.CDF latency:api 50.0 # fraction of values <= 50ms # "0.9" TDIGEST.INFO latency:api # 1) "Compression" 2) (integer) 100 # 3) "Capacity" 4) (integer) ... # 5) "Merged nodes" 6) (integer) ... # 7) "Observations" 8) (integer) 10 EOF ``` -------------------------------- ### Enable Link-Time Optimization (LTO) Source: https://github.com/apache/kvrocks/blob/unstable/CMakeLists.txt This section configures Link-Time Optimization (LTO) for the 'kvrocks_objs' target if supported by the compiler. It includes a check for IPO support and sets the appropriate property. For Clang, it also specifies the 'lld' linker. ```cmake if(ENABLE_LTO) include(CheckIPOSupported) check_ipo_supported(RESULT ipo_result OUTPUT ipo_output LANGUAGES CXX) if(ipo_result) set_property(TARGET kvrocks_objs PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_link_libraries(kvrocks_objs PUBLIC "-fuse-ld=lld") endif() else() message(WARNING "LTO is not supported: ${ipo_output}") endif() endif() ``` -------------------------------- ### Define kvrocks2redis Sync Tool Source: https://github.com/apache/kvrocks/blob/unstable/CMakeLists.txt Builds the 'kvrocks2redis' executable, a utility tool for synchronizing data, by linking the 'kvrocks_objs' library and external libraries. ```cmake file(GLOB KVROCKS2REDIS_SRCS utils/kvrocks2redis/*.cc) add_executable(kvrocks2redis ${KVROCKS2REDIS_SRCS}) target_link_libraries(kvrocks2redis PRIVATE kvrocks_objs ${EXTERNAL_LIBS}) ``` -------------------------------- ### HyperLogLog Operations in Kvrocks Source: https://context7.com/apache/kvrocks/llms.txt Estimate cardinality of sets using HyperLogLog, providing approximate unique counts with low memory usage. Supports adding elements, counting approximate cardinality, and merging multiple HyperLogLogs. ```shell PFADD page:views:home "user:1" "user:2" "user:3" "user:1" PFADD page:views:about "user:2" "user:4" "user:5" PFCOUNT page:views:home PFMERGE page:views:all page:views:home page:views:about PFCOUNT page:views:all ``` -------------------------------- ### Connect to Kvrocks Cluster with redis-cli Source: https://context7.com/apache/kvrocks/llms.txt Utilize redis-cli in cluster mode ('-c') to automatically handle key redirections to the correct node based on hash slots. ```shell # Use redis-cli in cluster mode to connect transparently redis-cli -c -p 6666 SET foo bar # -> Redirected to slot [12356] located at 127.0.0.1:6667 # OK ``` -------------------------------- ### Manage Native JSON Documents Source: https://context7.com/apache/kvrocks/llms.txt JSON commands allow storing, retrieving, and modifying JSON documents. Use JSONPath for precise targeting of elements within the document. ```shell JSON.SET user:2001 $ '{"name":"Alice","age":30,"tags":["admin","user"],"address":{"city":"NYC"}}' ``` ```shell JSON.GET user:2001 $ ``` ```shell JSON.GET user:2001 $.name $.address.city ``` ```shell JSON.SET user:2001 $.age 31 ``` ```shell JSON.NUMINCRBY user:2001 $.age 1 ``` ```shell JSON.ARRAPPEND user:2001 $.tags '"superuser"' ``` ```shell JSON.ARRLEN user:2001 $.tags ``` ```shell JSON.DEL user:2001 $.address ``` ```shell JSON.TYPE user:2001 $ ``` -------------------------------- ### Configure TLS/SSL Settings in Kvrocks Source: https://context7.com/apache/kvrocks/llms.txt Enable and configure TLS/SSL for client-facing and replication connections in Kvrocks. This includes specifying certificate files, protocols, and cipher suites. Client authentication can be enabled, disabled, or set to optional. ```ini # kvrocks.conf — TLS section tls-port 6667 # TLS listener (plain port 6666 still active) tls-cert-file /etc/kvrocks/kvrocks.crt tls-key-file /etc/kvrocks/kvrocks.key tls-ca-cert-file /etc/kvrocks/ca.crt tls-auth-clients yes # require client certificates # tls-auth-clients optional # accept but do not require client certs # tls-auth-clients no # no client cert required tls-protocols "TLSv1.2 TLSv1.3" tls-ciphers DEFAULT:!MEDIUM tls-replication yes # enable TLS on master-replica links tls-session-caching yes tls-session-cache-size 20480 tls-session-cache-timeout 300 ``` -------------------------------- ### Define Unit Test Executable Source: https://github.com/apache/kvrocks/blob/unstable/CMakeLists.txt Configures the 'unittest' executable for running C++ unit tests. It includes necessary directories and links against the 'kvrocks_objs' library, Google Test, and other external libraries. ```cmake file(GLOB_RECURSE TESTS_SRCS tests/cppunit/*.cc) add_executable(unittest ${TESTS_SRCS}) target_include_directories(unittest PRIVATE tests/cppunit) target_link_libraries(unittest PRIVATE kvrocks_objs gtest_main gmock ${EXTERNAL_LIBS}) ``` -------------------------------- ### TDIGEST.CREATE / TDIGEST.ADD / TDIGEST.QUANTILE Source: https://context7.com/apache/kvrocks/llms.txt Commands for creating, adding data to, and querying T-Digest structures for streaming quantile estimation. ```APIDOC ## TDIGEST.CREATE ### Description Creates a new T-Digest data structure with specified compression. ### Method TDIGEST.CREATE ### Endpoint (Not applicable, command-line interface) ### Parameters - **key** (string) - Required - The key for the T-Digest. - **COMPRESSION** (integer) - Optional - The compression factor for the T-Digest. ## TDIGEST.ADD ### Description Adds observed values to a T-Digest data structure. ### Method TDIGEST.ADD ### Endpoint (Not applicable, command-line interface) ### Parameters - **key** (string) - Required - The key of the T-Digest. - **values** (double list) - Required - The observed values to add. ## TDIGEST.QUANTILE ### Description Estimates quantiles for the data in a T-Digest. ### Method TDIGEST.QUANTILE ### Endpoint (Not applicable, command-line interface) ### Parameters - **key** (string) - Required - The key of the T-Digest. - **quantiles** (double list) - Required - The quantiles to estimate (e.g., 0.5, 0.95). ## TDIGEST.MIN ### Description Retrieves the minimum value from the T-Digest. ### Method TDIGEST.MIN ### Endpoint (Not applicable, command-line interface) ### Parameters - **key** (string) - Required - The key of the T-Digest. ## TDIGEST.MAX ### Description Retrieves the maximum value from the T-Digest. ### Method TDIGEST.MAX ### Endpoint (Not applicable, command-line interface) ### Parameters - **key** (string) - Required - The key of the T-Digest. ## TDIGEST.CDF ### Description Calculates the cumulative distribution function (fraction of values less than or equal to a given value) for the T-Digest. ### Method TDIGEST.CDF ### Endpoint (Not applicable, command-line interface) ### Parameters - **key** (string) - Required - The key of the T-Digest. - **value** (double) - Required - The value for which to calculate the CDF. ## TDIGEST.INFO ### Description Retrieves information about the T-Digest structure. ### Method TDIGEST.INFO ### Endpoint (Not applicable, command-line interface) ### Parameters - **key** (string) - Required - The key of the T-Digest. ``` -------------------------------- ### Enable Compilation Database Generation Source: https://github.com/apache/kvrocks/blob/unstable/CMakeLists.txt Enables the generation of a compilation database (compile_commands.json), which is useful for code analysis tools and IDE integration. ```cmake set(CMAKE_EXPORT_COMPILE_COMMANDS ON) ``` -------------------------------- ### List Operations with Blocking Support in Kvrocks Source: https://context7.com/apache/kvrocks/llms.txt Utilize list commands for queue-like operations, including pushing and popping from both ends, retrieving ranges, and blocking pops with timeouts. Supports atomic list movement between lists. ```shell RPUSH queue:jobs "job1" "job2" "job3" LPUSH queue:jobs "job0" LRANGE queue:jobs 0 -1 LPOP queue:jobs LLEN queue:jobs BLPOP queue:jobs 5 LMOVE queue:jobs queue:processing LEFT RIGHT ``` -------------------------------- ### Connect to Kvrocks using redis-cli with TLS Source: https://context7.com/apache/kvrocks/llms.txt Connect to a Kvrocks instance using redis-cli over TLS. Ensure you provide the correct port, certificate files for client authentication, and the CA certificate for verification. ```shell # Connect with redis-cli using TLS redis-cli -p 6667 \ --tls \ --cert /etc/kvrocks/client.crt \ --key /etc/kvrocks/client.key \ --cacert /etc/kvrocks/ca.crt \ PING # PONG ```