Skip to content

Commit 449996f

Browse files
committed
first commit
0 parents  commit 449996f

File tree

17 files changed

+4505
-0
lines changed

17 files changed

+4505
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/sh
2+
#
3+
# k2hash_rust
4+
#
5+
# Copyright 2025 LY Corporation.
6+
#
7+
# Rust driver for k2hash that is a NoSQL Key Value Store(KVS) library.
8+
# For k2hash, see https://github.com/yahoojapan/k2hash for the details.
9+
#
10+
# For the full copyright and license information, please view
11+
# the license file that was distributed with this source code.
12+
#
13+
# AUTHOR: Hirotaka Wakabayashi
14+
# CREATE: Fri, 17 Jul 2025
15+
# REVISION:
16+
#
17+
18+
echo $(basename $0)
19+
20+
if test -f "/etc/os-release"; then
21+
. /etc/os-release
22+
OS_NAME=$ID
23+
OS_VERSION=$VERSION_ID
24+
elif test -f "/etc/centos-release"; then
25+
echo "[OK] /etc/centos-release falling back to CentOS-7"
26+
OS_NAME=centos
27+
OS_VERSION=7
28+
else
29+
echo "Unknown OS, neither /etc/os-release nor /etc/centos-release"
30+
exit 1
31+
fi
32+
33+
echo "[OK] HOSTNAME=${HOSTNAME} OS_NAME=${OS_NAME} OS_VERSION=${OS_VERSION}"
34+
35+
case "${OS_NAME}-${OS_VERSION}" in
36+
ubuntu*|debian*)
37+
DEBIAN_FRONTEND="noninteractive" sudo apt-get update -y
38+
DEBIAN_FRONTEND="noninteractive" sudo apt-get install -y curl
39+
curl -s https://packagecloud.io/install/repositories/antpickax/stable/script.deb.sh | sudo bash
40+
DEBIAN_FRONTEND="noninteractive" sudo apt-get install -y k2hash-dev
41+
;;
42+
centos-7)
43+
sudo yum install -y epel-release-7
44+
sudo yum install -y --enablerepo=epel git curl which
45+
curl -s https://packagecloud.io/install/repositories/antpickax/stable/script.rpm.sh | sudo bash
46+
sudo yum install -y k2hash-devel
47+
;;
48+
centos-8|fedora*)
49+
sudo dnf install -y epel-release-8
50+
sudo dnf install -y git curl
51+
curl -s https://packagecloud.io/install/repositories/antpickax/stable/script.rpm.sh | sudo bash
52+
sudo dnf install -y k2hash-devel
53+
;;
54+
esac
55+
56+
exit $?
57+
58+
#
59+
# Local variables:
60+
# tab-width: 4
61+
# c-basic-offset: 4
62+
# End:
63+
# vim600: expandtab sw=4 ts=4 fdm=marker
64+
# vim<600: expandtab sw=4 ts=4
65+
#

.github/workflows/rust.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# k2hash_rust
2+
#
3+
# Copyright 2025 LY Corporation.
4+
#
5+
# Rust driver for k2hash that is a NoSQL Key Value Store(KVS) library.
6+
# For k2hash, see https://github.com/yahoojapan/k2hash for the details.
7+
#
8+
# For the full copyright and license information, please view
9+
# the license file that was distributed with this source code.
10+
#
11+
# AUTHOR: Hirotaka Wakabayashi
12+
# CREATE: Fri, 17 Jul 2025
13+
# REVISION:
14+
#
15+
16+
name: Cargo Build & Test
17+
18+
on:
19+
push:
20+
pull_request:
21+
22+
env:
23+
CARGO_TERM_COLOR: always
24+
25+
jobs:
26+
build_and_test:
27+
name: Rust project - latest
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
toolchain:
32+
- stable
33+
- beta
34+
- nightly
35+
steps:
36+
- uses: actions/checkout@v4
37+
- name: Install dependencies
38+
run: |
39+
./.github/scripts/install_dependencies.sh
40+
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
41+
- run: cargo build --verbose
42+
- name: Run tests
43+
run: RUST_BACKTRACE=1 cargo test --workspace --all-features --all-targets --verbose
44+
- name: Build docs
45+
run: cargo doc --no-deps
46+
47+
#
48+
# Local variables:
49+
# tab-width: 4
50+
# c-basic-offset: 4
51+
# End:
52+
# vim600: expandtab sw=4 ts=4 fdm=marker
53+
# vim<600: expandtab sw=4 ts=4
54+
#

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# k2hash_rust
2+
#
3+
# Copyright 2025 LY Corporation.
4+
#
5+
# Rust driver for k2hash that is a NoSQL Key Value Store(KVS) library.
6+
# For k2hash, see https://github.com/yahoojapan/k2hash for the details.
7+
#
8+
# For the full copyright and license information, please view
9+
# the license file that was distributed with this source code.
10+
#
11+
# AUTHOR: Hirotaka Wakabayashi
12+
# CREATE: Fri, 17 Jul 2025
13+
# REVISION:
14+
#
15+
#
16+
17+
# Generated by Cargo
18+
# will have compiled files and executables
19+
debug/
20+
target/
21+
22+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
23+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
24+
Cargo.lock
25+
26+
# These are backup files generated by rustfmt
27+
**/*.rs.bk
28+
29+
# MSVC Windows builds of rustc generate these, which store debugging information
30+
*.pdb
31+
32+
# emacs backup files
33+
*~
34+
35+
# Local Variables:
36+
# c-basic-offset: 4
37+
# tab-width: 4
38+
# indent-tabs-mode: t
39+
# End:
40+
# vim600: noexpandtab sw=4 ts=4 fdm=marker
41+
# vim<600: noexpandtab sw=4 ts=4

AUTHORS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1. Hirotaka Wakabayashi <hiwakaba@lycorp.co.jp>
2+
3+
Develops and other improvements k2hash rust.
4+
5+
2. Takeshi Nakatani <ggtakec@gmail.com>
6+
7+
Develops and other improvements k2hash.
8+

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "k2hash_rust"
3+
version = "1.0.0"
4+
edition = "2021"
5+
description = "Official k2hash Rust Driver"
6+
build = "build.rs"
7+
8+
[dependencies]
9+
libc = "0.2"
10+
11+
# https://doc.rust-lang.org/cargo/reference/features.html#the-features-section
12+
[features]
13+
default-features = []

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
k2hash_rust (1.0.0) stable; urgency=low
2+
3+
* Initial commit
4+
5+
-- Hirotaka Wakabayashi <hiwakaba@lycorp.co.jp> Tue, 09 Sep 2025 09:28:07 +0900
6+

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 LY Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# k2hash_rust
2+
3+
## Overview
4+
[![crates.io](https://img.shields.io/crates/v/k2hash_rust.svg)](https://crates.io/crates/k2hash_rust)
5+
[![Documentation](https://docs.rs/k2hash_rust/badge.svg)](https://docs.rs/k2hash_rust)
6+
[![CI](https://github.com/yahoojapan/k2hash_rust/actions/workflows/rust.yml/badge.svg)](https://github.com/yahoojapan/k2hash_rust/actions/workflows/rust.yml)
7+
8+
**k2hash_rust** implements a [k2hash](https://k2hash.antpick.ax/) client in Rust.
9+
10+
![k2hash Rust](https://raw.githubusercontent.com/yahoojapan/k2hash_rust/main/images/top_k2hash_rust.png)
11+
12+
## Install
13+
14+
Firstly you must install the [k2hash](https://k2hash.antpick.ax/) shared library.
15+
```sh
16+
curl -o- https://raw.github.com/yahoojapan/k2hash_rust/master/utils/libk2hash.sh | bash
17+
```
18+
You can install **k2hash** library step by step from [source code](https://github.com/yahoojapan/k2hash). See [Build](https://k2hash.antpick.ax/build.html) for details.
19+
20+
Download the **k2hash_rust** package.
21+
22+
```sh
23+
cargo install k2hash_rust
24+
```
25+
26+
## Usage
27+
28+
Here is a simple example of **k2hash_rust** that saves a key and get it.
29+
30+
```rust
31+
use k2hash_rust::K2hash;
32+
33+
fn main() {
34+
let db = K2hash::open_mem().expect("open_mem failed");
35+
db.set("foo", "bar");
36+
let v = db.get("foo");
37+
println!("foo => {:?}", v);
38+
}
39+
```
40+
41+
Let's run eamples!
42+
```
43+
cargo run --example basic_usage
44+
```
45+
46+
## Development
47+
48+
Here is the step to start developing **k2hash_rust** on Fedora42.
49+
50+
```sh
51+
sudo dnf update -y
52+
```
53+
54+
```sh
55+
sudo dnf makecache && sudo yum install curl git -y && curl -s https://packagecloud.io/install/repositories/antpickax/stable/script.rpm.sh | sudo bash
56+
sudo dnf install libfullock-devel k2hash-devel -y
57+
git clone https://github.com/yahoojapan/k2hash_rust.git
58+
cd k2hash_rust
59+
cargo build
60+
cargo test
61+
```
62+
63+
### Documents
64+
- [About K2HASH](https://k2hash.antpick.ax/)
65+
- [About AntPickax](https://antpick.ax/)
66+
67+
### License
68+
69+
MIT License. See the LICENSE file.
70+
71+
## AntPickax
72+
73+
[AntPickax](https://antpick.ax/) is
74+
- an open source team in [LY Corporation](https://www.lycorp.co.jp/en/company/overview/).
75+
- a product family of open source software developed by [AntPickax](https://antpick.ax/).

build.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// k2hash_rust
3+
//
4+
// Copyright 2025 LY Corporation.
5+
//
6+
// Rust driver for k2hash that is a NoSQL Key Value Store(KVS) library.
7+
// For k2hash, see https://github.com/yahoojapan/k2hash for the details.
8+
//
9+
// For the full copyright and license information, please view
10+
// the license file that was distributed with this source code.
11+
//
12+
// AUTHOR: Hirotaka Wakabayashi
13+
// CREATE: Fri, 17 Jul 2025
14+
// REVISION:
15+
//
16+
//
17+
18+
fn main() {
19+
println!("cargo:rustc-link-search=native=/usr/lib");
20+
println!("cargo:rustc-link-search=native=/usr/local/lib");
21+
println!("cargo:rustc-link-lib=dylib=k2hash");
22+
}
23+
24+
//
25+
// Local variables:
26+
// tab-width: 4
27+
// c-basic-offset: 4
28+
// End:
29+
// vim600: expandtab sw=4 ts=4 fdm=marker
30+
// vim<600: expandtab sw=4 ts=4
31+
//

examples/keyqueue.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// k2hash_rust
3+
//
4+
// Copyright 2025 LY Corporation.
5+
//
6+
// Rust driver for k2hash that is a NoSQL Key Value Store(KVS) library.
7+
// For k2hash, see https://github.com/yahoojapan/k2hash for the details.
8+
//
9+
// For the full copyright and license information, please view
10+
// the license file that was distributed with this source code.
11+
//
12+
// AUTHOR: Hirotaka Wakabayashi
13+
// CREATE: Fri, 17 Jul 2025
14+
// REVISION:
15+
//
16+
17+
use k2hash_rust::{K2hash, KeyQueue, KeyQueueBuilder};
18+
19+
fn main() {
20+
let db = K2hash::open_mem().expect("open_mem failed");
21+
22+
let q = KeyQueue::new(db.handle(), true, None, None, None).expect("KeyQueue creation failed");
23+
let key = "hello".to_string();
24+
let value = "world".to_string();
25+
q.put(&key, &value).expect("Push failed");
26+
if let Some(value) = q.get() {
27+
println!("Popped key: {}, value: {}", value.0, value.1);
28+
} else {
29+
println!("KeyQueue is empty");
30+
}
31+
assert!(q.qsize() == 0);
32+
assert!(q.clear());
33+
assert!(q.close());
34+
// Example of using KeyQueueBuilder
35+
let db = K2hash::open_mem().expect("open_mem failed");
36+
37+
let fifo = true; // or false, depending on your needs
38+
let prefix = "test_prefix".to_string();
39+
let password = Some("your_password".to_string());
40+
let expire_duration = Some(60); // for 60 seconds expiration
41+
// Create the KeyQueue using KeyQueueBuilder
42+
let qb1 = KeyQueueBuilder::new(db.handle())
43+
.fifo(fifo)
44+
.prefix(prefix) // Optional prefix
45+
.password(password.expect("Error")) // Optional password
46+
.expire_duration(expire_duration.expect("Error")) // Optional expiration duration
47+
.build()
48+
.expect("KeyQueue creation failed");
49+
qb1.put(&key, &value).expect("Push failed");
50+
if let Some(value) = qb1.get() {
51+
println!("Popped key: {}, value: {}", value.0, value.1);
52+
} else {
53+
println!("KeyQueue is empty");
54+
}
55+
assert!(qb1.qsize() == 0);
56+
assert!(qb1.clear());
57+
assert!(qb1.close());
58+
}
59+
60+
//
61+
// Local variables:
62+
// tab-width: 4
63+
// c-basic-offset: 4
64+
// End:
65+
// vim600: expandtab sw=4 ts=4 fdm=marker
66+
// vim<600: expandtab sw=4 ts=4
67+
//

0 commit comments

Comments
 (0)