8000 Support value in bytes by chenray844 · Pull Request #3 · AYMENJD/rocksdb-python · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Support value in bytes #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions rocksdb/client.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from concurrent.futures import ThreadPoolExecutor
from .rocksdb_ext import RocksDBext, Response

import rocksdb, asyncio
import rocksdb
import asyncio

logger = getLogger(__name__)

Expand Down Expand Up @@ -143,7 +144,7 @@ async def get(self, options: ReadOptions, key: str) -> Response:

return await future

async def put(self, options: WriteOptions, key: str, value: str) -> Response:
async def put(self, options: WriteOptions, key: str, value: str | bytes) -> Response:
"""Set the database entry for `key` to `value`

Args:
Expand All @@ -166,8 +167,8 @@ async def put(self, options: WriteOptions, key: str, value: str) -> Response:

if not isinstance(key, str):
raise TypeError("key must be str")
elif not isinstance(value, str):
raise TypeError("value must be str")
elif not isinstance(value, (str, bytes)):
raise TypeError("value must be str | bytes")
elif not isinstance(options, WriteOptions):
raise TypeError(f"Invalid class '{type(options).__name__}'")

Expand Down Expand Up @@ -276,7 +277,8 @@ async def getOptions(self) -> Response:
`Response`
"""

future = self.loop.run_in_executor(self.executer, self.__rocksdb.GetOptions)
future = self.loop.run_in_executor(
self.executer, self.__rocksdb.GetOptions)

return await future

Expand Down Expand Up @@ -369,7 +371,8 @@ async def flush(self, options: FlushOptions) -> Response:
if not isinstance(options, FlushOptions):
raise TypeError(f"Invalid class '{type(options).__name__}'")

future = self.loop.run_in_executor(self.executer, self.__rocksdb.Flush, options)
future = self.loop.run_in_executor(
self.executer, self.__rocksdb.Flush, options)

return await future

Expand Down
3 changes: 2 additions & 1 deletion rocksdb/ext/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ PYBIND11_MODULE(rocksdb_ext, m) {
.def(py::init<rocksdb::Status &, std::string *>())
.def_readwrite("status", &Response::status)
.def_readwrite("options", &Response::options)
.def_readwrite("value", &Response::value);
.def_readwrite("value", &Response::value)
.def("value_bytes", &Response::value_bytes);

// RocksDB options aka rocksdb::Options
py::class_<rocksdb::Options>(m, "_Options")
Expand Down
5 changes: 5 additions & 0 deletions rocksdb/ext/rocksdb.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <exception>
#include <iostream>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <rocksdb/db.h>
Expand All @@ -24,6 +25,10 @@ class Response {

this->status = s;
}

const py::bytes value_bytes() {
return py::bytes(this->value);
};
};

class RocksDB {
Expand Down
0