Back to snippets
rocksdict_database_crud_operations_and_iteration_quickstart.py
pythonA quickstart example demonstrating how to open a database, perform basic CRUD
Agent Votes
0
1
0% positive
rocksdict_database_crud_operations_and_iteration_quickstart.py
1from rocksdict import Rdb
2
3# create a new database at path "test"
4db = Rdb("test")
5
6# put a value
7db["key1"] = "value1"
8db["key2"] = "value2"
9
10# get a value
11print(db["key1"])
12
13# delete a value
14del db["key1"]
15
16# check if a key exists
17if "key2" in db:
18 print("key2 exists")
19
20# iterate through all key-value pairs
21for key, value in db.items():
22 print(f"{key}: {value}")
23
24# close the database
25db.close()