auto commit
This commit is contained in:
181
Rust/source/Cargo.lock
generated
181
Rust/source/Cargo.lock
generated
@@ -1,11 +1,28 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36ea56748e10732c49404c153638a15ec3d6211ec5ff35d9bb20e13b93576adf"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.19"
|
||||
@@ -19,6 +36,49 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "combine"
|
||||
version = "4.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc4369b5e4c0cddf64ad8981c0111e7df4f7078f4d6ba98fb31f2e17c4c57b7e"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dtoa"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191"
|
||||
dependencies = [
|
||||
"matches",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21"
|
||||
dependencies = [
|
||||
"matches",
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
@@ -31,6 +91,18 @@ version = "0.2.90"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae"
|
||||
|
||||
[[package]]
|
||||
name = "matches"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.44"
|
||||
@@ -50,6 +122,62 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redis"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eeb8f8d059ead7805e171fc22de8348a3d611c0f985aaa4f5cf6c0dfc7645407"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"combine",
|
||||
"dtoa",
|
||||
"itoa",
|
||||
"percent-encoding",
|
||||
"sha1",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha1"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.67"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
@@ -61,6 +189,57 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec_macros"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
|
||||
dependencies = [
|
||||
"matches",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"matches",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.0+wasi-snapshot-preview1"
|
||||
@@ -95,4 +274,6 @@ version = "1.0.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"redis",
|
||||
]
|
||||
|
||||
@@ -9,6 +9,15 @@ edition = "2018"
|
||||
[dependencies]
|
||||
chrono = "0.4.10"
|
||||
lazy_static = "1.4.0"
|
||||
#simple_redis = "*"
|
||||
redis = "0.20.0"
|
||||
libc="*"
|
||||
|
||||
#actix = "0.9.0"
|
||||
#actix-web = "2.0"
|
||||
#actix-rt = "1.0"
|
||||
#actix-redis = "0.8.0"
|
||||
#redis-async = "0.6.1"
|
||||
|
||||
[lib]
|
||||
name = "yitidgen"
|
||||
|
||||
@@ -3,6 +3,23 @@ mod yitgen;
|
||||
use yitgen::gen::YitIdHelper;
|
||||
use yitgen::contract::*;
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate redis;
|
||||
extern crate libc;
|
||||
|
||||
use redis::Commands;
|
||||
|
||||
use libc::{c_char, uint32_t};
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::str;
|
||||
|
||||
lazy_static! {
|
||||
//static ref TestValue: Vec<i32> = vec!(0);
|
||||
// static ref MAP: HashMap<u32, String> = HashMap::new();
|
||||
}
|
||||
|
||||
|
||||
// #[export_name = "SetIdGenerator"]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn SetIdGenerator(options: IdGeneratorOptions) {
|
||||
@@ -19,3 +36,64 @@ pub extern "C" fn NextId() -> i64 {
|
||||
YitIdHelper::NextId()
|
||||
}
|
||||
|
||||
static mut TestValue: i32 = 0;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Test() -> i32 {
|
||||
unsafe {
|
||||
TestValue += 1;
|
||||
return TestValue;
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn GetWorkerId(ip: *const c_char, port: i32) -> redis::RedisResult<isize> {
|
||||
// let c_str = unsafe {
|
||||
// assert!(!ip.is_null());
|
||||
// CStr::from_ptr(ip)
|
||||
// };
|
||||
//
|
||||
// let r_str = c_str.to_str();
|
||||
|
||||
// connect to redis
|
||||
// let client = redis::Client::open(format!("redis://{}:{}/", String::from(r_str).to_string(), port))?;
|
||||
let client = redis::Client::open(format!("redis://localhost:{}/", port))?;
|
||||
|
||||
let mut con = client.get_connection()?;
|
||||
// throw away the result, just make sure it does not fail
|
||||
unsafe {
|
||||
let _: () = con.set("my_key111", TestValue.clone())?;
|
||||
}
|
||||
con.get("my_key")
|
||||
// read back the key and return it. Because the return value
|
||||
// from the function is a result for integer this will automatically
|
||||
// convert into one.
|
||||
//
|
||||
|
||||
// match simple_redis::create(&format!("redis://{}:{}/", ip, port)) {
|
||||
// Ok(mut client) => {
|
||||
// println!("Created Redis Client");
|
||||
//
|
||||
// let valueString = TestValue.to_string();
|
||||
// let valueString2 = (*TestValue).to_string();
|
||||
//
|
||||
// match client.set("my_key", valueString) {
|
||||
// Err(error) => println!("Unable to set value in Redis: {}", error),
|
||||
// _ => println!("Value set in Redis")
|
||||
// };
|
||||
//
|
||||
// match client.set("my_key2", valueString2) {
|
||||
// Err(error) => println!("Unable to set value in Redis: {}", error),
|
||||
// _ => println!("Value set in Redis")
|
||||
// };
|
||||
//
|
||||
// match client.quit() {
|
||||
// Err(error) => println!("Error: {}", error),
|
||||
// _ => println!("Connection Closed.")
|
||||
// }
|
||||
// }
|
||||
// Err(error) => println!("Unable to create Redis client: {}", error)
|
||||
// }
|
||||
|
||||
//return 1;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use std::thread;
|
||||
use chrono::Utc;
|
||||
use std::time::Duration;
|
||||
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world! Rust");
|
||||
|
||||
@@ -22,6 +23,8 @@ fn main() {
|
||||
//... 可以继续设置其它 options 参数
|
||||
YitIdHelper::SetIdGenerator(options);
|
||||
|
||||
set_redis();
|
||||
|
||||
// 以下开始测试生成数据,默认5W,单线程,可以修改 multiThread=true 启用多线程。
|
||||
loop {
|
||||
let mut i = 0;
|
||||
@@ -51,3 +54,24 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_redis() {
|
||||
|
||||
// match simple_redis::create("redis://127.0.0.1:6379/") {
|
||||
// Ok(mut client) => {
|
||||
// println!("Created Redis Client");
|
||||
//
|
||||
// match client.set("my_key", "my_value") {
|
||||
// Err(error) => println!("Unable to set value in Redis: {}", error),
|
||||
// _ => println!("Value set in Redis")
|
||||
// };
|
||||
//
|
||||
// match client.quit() {
|
||||
// Err(error) => println!("Error: {}", error),
|
||||
// _ => println!("Connection Closed.")
|
||||
// }
|
||||
// },
|
||||
// Err(error) => println!("Unable to create Redis client: {}", error)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::super::contract::*;
|
||||
use std::{thread};
|
||||
use chrono::Utc;
|
||||
use std::thread::sleep;
|
||||
use lazy_static::lazy_static;
|
||||
// use lazy_static::lazy_static;
|
||||
|
||||
pub struct SnowWorkerM1 {
|
||||
///基础时间
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::sync::Mutex;
|
||||
use std::sync::Arc;
|
||||
use std::borrow::BorrowMut;
|
||||
|
||||
static mut instance2: Option<Arc<Mutex<SnowWorkerM1>>> = None;
|
||||
// static mut instance2: Option<Arc<Mutex<SnowWorkerM1>>> = None;
|
||||
|
||||
pub struct DefaultIdGenerator {
|
||||
pub Worker: SnowWorkerM1,
|
||||
|
||||
Reference in New Issue
Block a user