{"id":21344494,"url":"https://github.com/s00d/php-rocksdb-rc","last_synced_at":"2025-06-12T13:04:00.703Z","repository":{"id":242049910,"uuid":"808560054","full_name":"s00d/php-rocksdb-rc","owner":"s00d","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-08T19:02:18.000Z","size":101,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T04:11:48.642Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s00d.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-31T10:18:29.000Z","updated_at":"2025-02-23T08:59:52.000Z","dependencies_parsed_at":"2024-06-08T18:05:46.228Z","dependency_job_id":"15e1696a-8f14-445e-afd1-11bbe059e885","html_url":"https://github.com/s00d/php-rocksdb-rc","commit_stats":null,"previous_names":["s00d/php-rocksdb-rc"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s00d%2Fphp-rocksdb-rc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s00d%2Fphp-rocksdb-rc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s00d%2Fphp-rocksdb-rc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s00d%2Fphp-rocksdb-rc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s00d","download_url":"https://codeload.github.com/s00d/php-rocksdb-rc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003955,"owners_count":21196793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T01:19:18.079Z","updated_at":"2025-04-15T04:11:59.265Z","avatar_url":"https://github.com/s00d.png","language":"Rust","funding_links":[],"categories":["Databases"],"sub_categories":[],"readme":"# php-rocksdb-rc\n\nA PHP extension for interacting with RocksDB, built with Rust. This extension provides a simple interface for RocksDB operations such as putting, getting, deleting, and managing column families.\n\n## Overview\n\n`php-rocksdb-rc` is a PHP extension that allows you to use RocksDB, a high-performance embedded database for key-value data, directly from your PHP applications. This extension is written in Rust using the `ext-php-rs` and `rust-rocksdb` crates to provide a seamless integration between PHP and RocksDB.\n\n## Features\n\n- Basic CRUD operations on RocksDB\n- Support for column families\n- TTL support for key-value pairs\n- Advanced options like flushing and repairing the database\n- Backup and restore functionality\n- Write batch operations\n- Snapshot support\n- Transaction support\n\n## Installation\n\n### Pre-built Binaries\n\nYou can download pre-built binaries from the [releases page](https://github.com/yourusername/php-rocksdb-rc/releases). Download the appropriate binary for your system and PHP version.\n\n#### For Linux:\n\n1. Download the `.so` file for your PHP version and architecture.\n2. Place the file in your PHP extensions directory (usually `/usr/lib/php/extensions`).\n3. Add the following line to your `php.ini` file:\n\n    ```ini\n    extension=librocksdb.so\n    ```\n\n4. Restart your web server or PHP-FPM to load the extension.\n\n#### For macOS:\n\n1. Download the `.dylib` file for your PHP version and architecture.\n2. Place the file in your PHP extensions directory (usually `/usr/local/lib/php/extensions`).\n3. Add the following line to your `php.ini` file:\n\n    ```ini\n    extension=librocksdb.dylib\n    ```\n\n4. Restart your web server or PHP-FPM to load the extension.\n\n### Building from Source\n\nTo build the extension from source, you will need Rust and Cargo installed. Follow the steps below:\n\n#### Install Rust and Cargo\n\n1. **On Linux and macOS**:\n\n   The recommended way to install Rust is via `rustup`, a toolchain installer for Rust.\n\n    ```sh\n    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n    ```\n\n   Follow the on-screen instructions to complete the installation. After installation, you may need to restart your terminal or source your profile:\n\n    ```sh\n    source $HOME/.cargo/env\n    ```\n\n2. **On Windows**:\n\n   Download and run the `rustup-init.exe` installer from the [official Rust website](https://www.rust-lang.org/tools/install). Follow the on-screen instructions to complete the installation.\n\n   After installation, open a new command prompt or PowerShell window and ensure that `cargo` and `rustc` are in your PATH by running:\n\n    ```sh\n    rustc --version\n    cargo --version\n    ```\n\n#### Clone the Repository and Build the Extension\n\n1. Clone the repository:\n\n    ```sh\n    git clone https://github.com/yourusername/php-rocksdb-rc.git\n    cd php-rocksdb-rc\n    ```\n\n2. Build the extension:\n\n    ```sh\n    cargo build --release\n    ```\n\n3. Copy the built library to your PHP extensions directory:\n\n   - **On Linux**:\n\n       ```sh\n       cp target/release/librocksdb.so /usr/lib/php/extensions/\n       ```\n\n   - **On macOS**:\n\n       ```sh\n       cp target/release/librocksdb.dylib /usr/local/lib/php/extensions/\n       ```\n\n   - **On Windows**:\n\n       ```sh\n       copy target\\release\\librocksdb.dll C:\\path\\to\\php\\ext\\\n       ```\n\n4. Add the following line to your `php.ini` file:\n\n   - **On Linux and macOS**:\n\n       ```ini\n       extension=librocksdb.so\n       ```\n\n   - **On Windows**:\n\n       ```ini\n       extension=librocksdb.dll\n       ```\n\n5. Restart your web server or PHP-FPM to load the extension.\n\n### Additional Notes\n\n- Ensure that the path to the PHP extensions directory is correct. You can find the extension directory by running `php -i | grep extension_dir`.\n- If you encounter any issues during the installation of Rust, refer to the [official Rust installation guide](https://www.rust-lang.org/tools/install) for troubleshooting tips.\n- Make sure your PHP installation is compatible with the extension. You can check your PHP version by running `php -v`.\n\nBy following these steps, you should be able to build and install the PHP extension from source successfully.\n\n\n## Usage\n\nHere are some examples of how to use the `php-rocksdb-rc` extension:\n\n### Creating and Using a RocksDB Instance\n\n```php\n\u003c?php\n\n$db = new RocksDB(\"/path/to/db\", 3600); // 3600 seconds TTL\n\n// Put a value\n$db-\u003eput(\"key1\", \"value1\");\n\n// Get a value\n$value = $db-\u003eget(\"key1\");\necho $value; // Outputs: value1\n\n// Delete a value\n$db-\u003edelete(\"key1\");\n\n// Create a column family\n$db-\u003ecreateColumnFamily(\"new_cf\");\n\n// Put a value in a column family\n$db-\u003eput(\"key2\", \"value2\", \"new_cf\");\n\n// Get a value from a column family\n$value = $db-\u003eget(\"key2\", \"new_cf\");\necho $value; // Outputs: value2\n\n// List column families\n$column_families = RocksDB::listColumnFamilies(\"/path/to/db\");\nprint_r($column_families);\n\n// Drop a column family\n$db-\u003edropColumnFamily(\"new_cf\");\n\n// Flush the database\n$db-\u003eflush();\n\n// Repair the database\nRocksDB::repair(\"/path/to/db\");\n\n// Close the database\n$db-\u003eclose();\n?\u003e\n```\n\nThis example demonstrates basic put and get operations in RocksDB.\n\n```php\n\u003c?php\n$dbPath = __DIR__ . \"/temp/testdb\";\n$db = new RocksDB($dbPath, 3600); // 3600 seconds TTL\n$db-\u003eput(\"key1\", \"value1\");\n$db = null; // Free the connection\n\n$db = new RocksDB($dbPath, 3600);\n$value = $db-\u003eget(\"key1\");\nvar_dump($value); // Outputs: string(6) \"value1\"\n$db = null; // Free the connection\n?\u003e\n```\n\n### Example: Delete Operation\n\nThis example demonstrates how to delete a key-value pair from RocksDB.\n\n```php\n\u003c?php\n$dbPath = __DIR__ . \"/temp/testdb\";\n$db = new RocksDB($dbPath, 3600); // 3600 seconds TTL\n$db-\u003eput(\"key1\", \"value1\");\n$db-\u003edelete(\"key1\");\n$db = null; // Free the connection\n\n$db = new RocksDB($dbPath, 3600);\n$value = $db-\u003eget(\"key1\");\nvar_dump($value); // Outputs: NULL\n$db = null; // Free the connection\n?\u003e\n```\n\n### Example: Iterator Usage\n\nThis example demonstrates how to use an iterator to traverse key-value pairs in RocksDB.\n\n```php\n\u003c?php\n$dbPath = __DIR__ . \"/temp/testdb_iter\";\n$db = new RocksDB($dbPath, 3600); // 3600 seconds TTL\n$db-\u003eflush();\n$db-\u003eput(\"key_vvv\", \"value_a\");\n$db-\u003eput(\"key_ggg\", \"value_b\");\n$db-\u003eput(\"key_hhh\", \"value_c\");\n\n$db-\u003eseekToFirst();\n$result = [];\nwhile ($db-\u003evalid()) {\n    $res = $db-\u003enext();\n    $key = $res['key'];\n    $value = $res['value'];\n\n    $result[$key] = $value;\n}\nvar_dump($result); // Outputs an array with all key-value pairs\n$db = null; // Free the connection\n?\u003e\n```\n\n### Example: Backup and Restore\n\nThis example demonstrates how to create a backup of the RocksDB database and retrieve information about the backups.\n\n```php\n\u003c?php\n$dbPath = __DIR__ . \"/temp/testdb_backup\";\n$backupPath = __DIR__ . \"/temp/testdb_backup_files\";\n\n// Create and use RocksDB instance\n$db = new RocksDB($dbPath, 3600); // 3600 seconds TTL\n$db-\u003eput(\"key1\", \"value1\");\n\n// Initialize backup engine and create a backup\n$backup = new \\RocksDBBackup($dbPath, 3600); // 3600 seconds TTL\n$backup-\u003einit($backupPath);\n$backup-\u003ecreate();\n\n// Get backup info\n$info = $backup-\u003einfo();\nprint_r($info); // Outputs information about the backups\n\n// Restore from backup\n$restorePath = __DIR__ . \"/temp/testdb_restore\";\n$backup-\u003erestore(1, $restorePath); // Restore the first backup\n\n// Verify the restored data\n$restoredDb = new RocksDB($restorePath, 3600);\n$value = $restoredDb-\u003eget(\"key1\");\nvar_dump($value); // Outputs: string(6) \"value1\"\n\n// Cleanup\n$db = null;\n$restoredDb = null;\n?\u003e\n```\n\n### Example: Write Batch Operations\n\nThis example demonstrates how to use write batch operations to perform multiple writes in a single batch.\n\n```php\n\u003c?php\n$dbPath = __DIR__ . \"/temp/testdb_write_batch\";\n$db = new RocksDB($dbPath, 3600); // 3600 seconds TTL\n\n// Initialize write batch\n$writeBatch = new \\RocksDBWriteBatch($dbPath, 3600); // 3600 seconds TTL\n$writeBatch-\u003estart();\n$writeBatch-\u003eput(\"key1\", \"value1\");\n$writeBatch-\u003eput(\"key2\", \"value2\");\n$writeBatch-\u003edelete(\"key1\");\n$writeBatch-\u003ewrite(); // Write the batch to the database\n\n// Verify the data\n$value1 = $db-\u003eget(\"key1\");\n$value2 = $db-\u003eget(\"key2\");\nvar_dump($value1); // Outputs: NULL (since key1 was deleted)\nvar_dump($value2); // Outputs: string(6) \"value2\"\n\n// Cleanup\n$db = null;\n?\u003e\n```\n\n### Example: Transactions\n\nThis example demonstrates how to use transactions to ensure atomicity of multiple operations.\n\n```php\n\u003c?php\n$dbPath = __DIR__ . \"/temp/testdb_transaction\";\n$db = new RocksDB($dbPath, 3600); // 3600 seconds TTL\n\n// Initialize transaction\n$transaction = new \\RocksDBTransaction($dbPath, 3600); // 3600 seconds TTL\n$transaction-\u003estart();\n$transaction-\u003eput(\"key1\", \"value1\");\n$transaction-\u003eput(\"key2\", \"value2\");\n$transaction-\u003edelete(\"key1\");\n$transaction-\u003ecommit(); // Commit the transaction\n\n// Verify the data\n$value1 = $db-\u003eget(\"key1\");\n$value2 = $db-\u003eget(\"key2\");\nvar_dump($value1); // Outputs: NULL (since key1 was deleted)\nvar_dump($value2); // Outputs: string(6) \"value2\"\n\n// Cleanup\n$db = null;\n?\u003e\n```\n\n### Example: Snapshots\n\nThis example demonstrates how to use snapshots to capture the state of the database at a specific point in time.\n\n```php\n\u003c?php\n$dbPath = __DIR__ . \"/temp/testdb_snapshot\";\n$db = new RocksDB($dbPath, 3600); // 3600 seconds TTL\n\n// Put some initial data\n$db-\u003eput(\"key1\", \"value1\");\n$db-\u003eput(\"key2\", \"value2\");\n\n// Create a snapshot\n$snapshot = new \\RocksDBSnapshot($dbPath, 3600); // 3600 seconds TTL\n$snapshot-\u003ecreate();\n\n// Modify the database after taking the snapshot\n$db-\u003eput(\"key1\", \"new_value1\");\n$db-\u003edelete(\"key2\");\n\n// Verify the data in the snapshot\n$snapshotValue1 = $snapshot-\u003eget(\"key1\");\n$snapshotValue2 = $snapshot-\u003eget(\"key2\");\nvar_dump($snapshotValue1); // Outputs: string(6) \"value1\" (original value)\nvar_dump($snapshotValue2); // Outputs: string(6) \"value2\" (original value)\n\n// Verify the current data in the database\n$currentValue1 = $db-\u003eget(\"key1\");\n$currentValue2 = $db-\u003eget(\"key2\");\nvar_dump($currentValue1); // Outputs: string(10) \"new_value1\"\nvar_dump($currentValue2); // Outputs: NULL (since key2 was deleted)\n\n// Cleanup\n$db = null;\n$snapshot = null;\n?\u003e\n```\n\n\n### Detailed API\n\n#### `__construct(path: String, ttl_secs: Option\u003cu64\u003e)`\nCreates a new RocksDB instance with the specified path and TTL.\n\n```php\n\u003c?php\n$db = new RocksDB(\"/path/to/db\", 3600); // 3600 seconds TTL\n?\u003e\n```\n\n#### `put(key: String, value: String, cf_name: Option\u003cString\u003e)`\nInserts a key-value pair into the database.\n\n```php\n\u003c?php\n$db-\u003eput(\"key1\", \"value1\");\n$db-\u003eput(\"key2\", \"value2\", \"new_cf\"); // Using column family\n?\u003e\n```\n\n#### `get(key: String, cf_name: Option\u003cString\u003e)`\nRetrieves the value associated with the given key.\n\n```php\n\u003c?php\n$value = $db-\u003eget(\"key1\");\necho $value; // Outputs: value1\n\n$value = $db-\u003eget(\"key2\", \"new_cf\"); // From column family\necho $value; // Outputs: value2\n?\u003e\n```\n\n#### `merge(key: String, value: String, cf_name: Option\u003cString\u003e)`\nMerges a value into the database using JSON Patch.\n\n```php\n\u003c?php\n$db-\u003emerge(\"json_obj_key\", '[ { \"op\": \"replace\", \"path\": \"/employees/1/first_name\", \"value\": \"lucy\" } ]');\n$db-\u003emerge(\"json_obj_key\", '[ { \"op\": \"replace\", \"path\": \"/employees/0/last_name\", \"value\": \"dow\" } ]');\n?\u003e\n```\n\n\nThis method uses JSON Patch to update the JSON object in the database. For more details on JSON Patch, refer to  [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902).\n\n#### `delete(key: String, cf_name: Option\u003cString\u003e)`\nDeletes the key-value pair associated with the given key.\n\n```php\n\u003c?php\n$db-\u003edelete(\"key1\");\n$db-\u003edelete(\"key2\", \"new_cf\"); // From column family\n?\u003e\n```\n\n#### `listColumnFamilies(path: String)`\nLists all column families in the database.\n\n```php\n\u003c?php\n$column_families = RocksDB::listColumnFamilies(\"/path/to/db\");\nprint_r($column_families);\n?\u003e\n```\n\n#### `createColumnFamily(cf_name: String)`\nCreates a new column family with the specified name.\n\n```php\n\u003c?php\n$db-\u003ecreateColumnFamily(\"new_cf\");\n?\u003e\n```\n\n#### `dropColumnFamily(cf_name: String)`\nDrops the column family with the specified name.\n\n```php\n\u003c?php\n$db-\u003edropColumnFamily(\"new_cf\");\n?\u003e\n```\n\n#### `getProperty(property: String, cf_name: Option\u003cString\u003e)`\nRetrieves a database property.\n\n```php\n\u003c?php\n$property = $db-\u003egetProperty(\"rocksdb.stats\");\necho $property;\n\n$property = $db-\u003egetProperty(\"rocksdb.stats\", \"new_cf\"); // From column family\necho $property;\n?\u003e\n```\n\n#### `flush(cf_name: Option\u003cString\u003e)`\nFlushes all memtable data to SST files.\n\n```php\n\u003c?php\n$db-\u003eflush();\n$db-\u003eflush(\"new_cf\"); // Flush column family\n?\u003e\n```\n\n#### `repair(path: String)`\nRepairs a RocksDB database at the specified path.\n\n```php\n\u003c?php\nRocksDB::repair(\"/path/to/db\");\n?\u003e\n```\n\n#### `close()`\nCloses the RocksDB instance.\n\n```php\n\u003c?php\n$db-\u003eclose();\n?\u003e\n```\n\n#### `all(cf_name: Option\u003cString\u003e)`\nReturns all key-value pairs in the database or column family.\n\n```php\n\u003c?php\n$data = $db-\u003eall();\nprint_r($data);\n\n$data = $db-\u003eall(\"new_cf\"); // From column family\nprint_r($data);\n?\u003e\n```\n\n#### `keys(cf_name: Option\u003cString\u003e)`\nReturns all keys in the database or column family.\n\n```php\n\u003c?php\n$keys = $db-\u003ekeys();\nprint_r($keys);\n\n$keys = $db-\u003ekeys(\"new_cf\"); // From column family\nprint_r($keys);\n?\u003e\n```\n\n### Iterator Methods\n\n#### `seekToFirst()`\nSeeks to the first key in the database or column family.\n\n```php\n\u003c?php\n$db-\u003eseekToFirst();\n?\u003e\n```\n\n#### `seekToLast()`\nSeeks to the last key in the database or column family.\n\n```php\n\u003c?php\n$db-\u003eseekToLast();\n?\u003e\n```\n\n#### `seek(key: String)`\nSeeks to the specified key in the database or column family.\n\n```php\n\u003c?php\n$db-\u003eseek(\"key1\");\n?\u003e\n```\n\n#### `seekForPrev(key: String)`\nSeeks to the specified key or previous key in the database or column family.\n\n```php\n\u003c?php\n$db-\u003eseekForPrev(\"key1\");\n?\u003e\n```\n\n#### `valid()`\nChecks if the current iterator position is valid.\n\n```php\n\u003c?php\n$isValid = $db-\u003evalid();\necho $isValid ? 'true' : 'false';\n?\u003e\n```\n\n#### `next()`\nMoves to the next key-value pair in the database or column family.\n\n```php\n\u003c?php\n$kv = $db-\u003enext();\nprint_r($kv);\n?\u003e\n```\n\n#### `prev()`\nMoves to the previous key-value pair in the database or column family.\n\n```php\n\u003c?php\n$kv = $db-\u003eprev();\nprint_r($kv);\n?\u003e\n```\n\n#### `compact_range(start: Option\u003cString\u003e, end: Option\u003cString\u003e, cf_name: Option\u003cString\u003e)`\nCompacts the key-value pairs in the specified range within the database or column family.\n\n```php\n\u003c?php\n$db-\u003ecompact_range(\"key_start\", \"key_end\");\n$db-\u003ecompact_range(\"key_start\", \"key_end\", \"new_cf\"); // In column family\n?\u003e\n```\n\n#### `get_live_files()`\nReturns the names of the live SST files in the database.\n\n```php\n\u003c?php\n$live_files = $db-\u003eget_live_files();\nprint_r($live_files);\n?\u003e\n```\n\n#### `set_options(options: HashMap\u003cString, String\u003e, cf_name: Option\u003cString\u003e)`\nSets the database options.\n\n```php\n\u003c?php\n$options = [\n    \"write_buffer_size\" =\u003e \"4194304\",\n    \"max_write_buffer_number\" =\u003e \"3\",\n];\n$db-\u003eset_options($options);\n$db-\u003eset_options($options, \"new_cf\"); // For column family\n?\u003e\n```\n\n#### `set_compression(compression_type: String, cf_name: Option\u003cString\u003e)`\nSets the compression type for the database or column family.\n\n```php\n\u003c?php\n$db-\u003eset_compression(\"snappy\");\n$db-\u003eset_compression(\"zlib\", \"new_cf\"); // For column family\n?\u003e\n```\n\nThis method supports the following compression types: \"none\", \"snappy\", \"zlib\", \"bzip2\", \"lz4\", \"lz4hc\", \"zstd\".\n\n#### `set_write_buffer_size(size: usize, cf_name: Option\u003cString\u003e)`\nSets the size of the write buffer for the database or column family.\n\n```php\n\u003c?php\n$db-\u003eset_write_buffer_size(4194304);\n$db-\u003eset_write_buffer_size(4194304, \"new_cf\"); // For column family\n?\u003e\n```\n\nThis method sets the amount of data to build up in memory (backed by an unsorted log on disk) before converting to a sorted on-disk file.\n\n#### `set_cache_size(size: usize, cf_name: Option\u003cString\u003e)`\nSets the size of the block cache for the database or column family.\n\n```php\n\u003c?php\n$db-\u003eset_cache_size(8388608);\n$db-\u003eset_cache_size(8388608, \"new_cf\"); // For column family\n?\u003e\n```\n\nThis method sets the amount of memory to use for the block cache, which is used to accelerate the read operations by caching the data blocks in memory.\n\n### Backup Methods\n\n#### `__construct(path: String, ttl_secs: Option\u003cu64\u003e)`\nCreates a new RocksDBBackup instance.\n\n```php\n\u003c?php\n$backup = new \\RocksDBBackup(\"/path/to/db\", 3600); // 3600 seconds TTL\n?\u003e\n```\n\n#### `init(backup_path: String)`\nInitializes the backup engine with the specified path.\n\n```php\n\u003c?php\n$backup-\u003einit(\"/path/to/backup\");\n?\u003e\n```\n\n#### `create()`\nCreates a backup of the database.\n\n```php\n\u003c?php\n$backup-\u003einit(\"/path/to/backup\");\n$backup-\u003ecreate();\n?\u003e\n```\n\n#### `info()`\nReturns information about the backups.\n\n```php\n\u003c?php\n$backup-\u003einit(\"/path/to/backup\");\n$info = $backup-\u003einfo();\nprint_r($info);\n?\u003e\n```\n\n#### `purgeOld(num_backups_to_keep: usize)`\nPurges old backups, keeping the specified number of backups.\n\n```php\n\u003c?php\n$backup-\u003einit(\"/path/to/backup\");\n$backup-\u003epurgeOld(2);\n?\u003e\n```\n\n#### `restore(backup_id: u32, restore_path: String)`\nRestores the database from a backup.\n\n```php\n\u003c?php\n$backup-\u003einit(\"/path/to/backup\");\n$backup-\u003erestore(1, \"/path/to/restore\");\n?\u003e\n```\n\n### Write Batch Methods\n\n#### `__construct(path: String, ttl_secs: Option\u003cu64\u003e)`\nCreates a new RocksDBWriteBatch instance.\n\n```php\n\u003c?php\n$write_batch = new \\RocksDBWriteBatch(\"/path/to/db\", 3600); // 3600 seconds TTL\n?\u003e\n```\n\n#### `start()`\nStarts a new write batch.\n\n```php\n\u003c?php\n$write_batch-\u003estart();\n?\u003e\n```\n\n#### `put(key: String, value: String, cf_name: Option\u003cString\u003e)`\nPuts a key-value pair into the current write batch.\n\n```php\n\u003c?php\n$write_batch-\u003estart();\n$write_batch-\u003eput(\"key1\", \"value1\");\n$write_batch-\u003eput(\"key2\", \"value2\", \"new_cf\"); // Using column family\n?\u003e\n```\n\n#### `merge(key: String, value: String, cf_name: Option\u003cString\u003e)`\nMerges a value into the current write batch.\n\n```php\n\u003c?php\n$write_batch-\u003estart();\n$write_batch-\u003emerge(\"json_obj_key\", \"employees[1].first_name = lucy\");\n$write_batch-\u003emerge(\"json_obj_key\", \"employees[0].last_name = dow\", \"new_cf\"); // Using column family\n?\u003e\n```\n\n#### `delete(key: String, cf_name: Option\u003cString\u003e)`\nDeletes a key-value pair from the current write batch.\n\n```php\n\u003c?php\n$write_batch-\u003estart();\n$write_batch-\u003edelete(\"key1\");\n$write_batch-\u003edelete(\"key2\", \"new_cf\"); // From column family\n?\u003e\n```\n\n#### `write()`\nWrites the current write batch to the database.\n\n```php\n\u003c?php\n$write_batch-\u003estart();\n$write_batch-\u003ewrite();\n?\u003e\n```\n\n#### `clear()`\nClears the current write batch.\n\n```php\n\u003c?php\n$write_batch-\u003estart();\n$write_batch-\u003eclear();\n?\u003e\n```\n\n#### `destroy()`\nDestroys the current write batch.\n\n```php\n\u003c?php\n$write_batch-\u003estart();\n$write_batch-\u003edestroy();\n?\u003e\n```\n\n### Transaction Methods\n\n#### `__construct(path: String, ttl_secs: Option\u003cu64\u003e)`\nCreates a new RocksDBTransaction instance.\n\n```php\n\u003c?php\n$transaction = new \\RocksDBTransaction(\"/path/to/db\", 3600); // 3600 seconds TTL\n?\u003e\n```\n\n#### `start()`\nStarts a new transaction.\n\n```php\n\u003c?php\n$transaction-\u003estart();\n?\u003e\n```\n\n#### `commit()`\nCommits the current transaction.\n\n```php\n\u003c?php\n$transaction-\u003ecommit();\n?\u003e\n```\n\n#### `rollback()`\nRolls back the current transaction.\n\n```php\n\u003c?php\n$transaction-\u003erollback();\n?\u003e\n```\n\n#### `setSavepoint()`\nSets a savepoint within the current transaction.\n\n```php\n\u003c?php\n$transaction-\u003esetSavepoint();\n?\u003e\n```\n\n#### `rollbackToSavepoint()`\nRolls back the transaction to the last savepoint.\n\n```php\n\u003c?php\n$transaction-\u003erollbackToSavepoint();\n?\u003e\n```\n\n#### `put(key: String, value: String, cf_name: Option\u003cString\u003e)`\nPuts a key-value pair into the current transaction.\n\n```php\n\u003c?php\n$transaction-\u003eput(\"key1\", \"value1\");\n$transaction-\u003eput(\"key2\", \"value2\", \"new_cf\"); // Using column family\n?\u003e\n```\n\n#### `get(key: String, cf_name: Option\u003cString\u003e)`\nGets the value associated with the given key within the current transaction.\n\n```php\n\u003c?php\n$value = $transaction-\u003eget(\"key1\");\necho $value; // Outputs: value1\n\n$value = $transaction-\u003eget(\"key2\", \"new_cf\"); // From column family\necho $value; // Outputs: value2\n?\u003e\n```\n\n#### `delete(key: String, cf_name: Option\u003cString\u003e)`\nDeletes a key-value pair within the current transaction.\n\n```php\n\u003c?php\n$transaction-\u003edelete(\"key1\");\n$transaction-\u003edelete(\"key2\", \"new_cf\"); // From column family\n?\u003e\n```\n\n#### `merge(key: String, value: String, cf_name: Option\u003cString\u003e)`\nMerges a value within the current transaction.\n\n```php\n\u003c?php\n$transaction-\u003emerge(\"json_obj_key\", \"employees[1].first_name = lucy\");\n$transaction-\u003emerge(\"json_obj_key\", \"employees[0].last_name = dow\", \"new_cf\"); // Using column family\n?\u003e\n```\n\n## Important Note\n\nBefore creating a new instance of any class (e.g., `RocksDB`, `RocksDBBackup`, `RocksDBWriteBatch`, `RocksDBTransaction`), ensure to destroy the previous instance to free up the database connection.\n\n```php\n\u003c?php\n$db = new \\RocksDB($dbPath);\n$db = null; // Free the connection\n\n$iterator = new \\RocksDBIterator($dbPath); // Now you can create a new instance\n?\u003e\n```\n\n## Enabling Autocompletion in PhpStorm\n\nTo enable autocompletion for the `librocksdb` extension in PhpStorm, follow these steps:\n\n1. **Download the Stub File**\n\n   Download the `.php_rocksdb_rc.php` file from [here](.php_rocksdb_rc.php).\n\n2. **Place the Stub File in Your Project**\n\n   Save the `.php_rocksdb_rc.php` file in your project directory.\n\nAfter completing these steps, you should have autocompletion support for the `librocksdb` extension in PhpStorm.\n\n## Contributing\n\nContributions are welcome! Please submit pull requests or issues on the [GitHub repository](https://github.com/yourusername/php-rocksdb-rc).\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\nThis project uses the following open-source libraries:\n- [ext-php-rs](https://github.com/davidcole1340/ext-php-rs)\n- [rust-rocksdb](https://github.com/rust-rocksdb/rust-rocksdb)\n\n## Conclusion\n\nThe `php-rocksdb-rc` extension provides a powerful and efficient way to interact with RocksDB from PHP. With support for basic CRUD operations, column families, TTL, backups, write batches, transactions, and snapshots, it offers a comprehensive set of features for managing key-value data in PHP applications. The provided examples demonstrate how to use these features effectively. Happy coding!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs00d%2Fphp-rocksdb-rc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs00d%2Fphp-rocksdb-rc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs00d%2Fphp-rocksdb-rc/lists"}