- がprogramically設定値を持つ構造体をインスタンス化する方法を把握しようとしています。
- 私は2つの特徴
ToRedisArgs
とFromRedisValue
はここで実装されることになるが、それでも私の非常にシンプルな2つの構造体のために、私はIMPLへの書き込みを何見当もつかないことを承知していますバックのRedis
から構造体にそれをフェッチ彼らは錆の中にいます。彼らは私の周りを閲覧しながら、私は別の訪問者、彼らの閲覧行動(所要時間、ページがなどを訪問し、他の相互作用)およびその他の統計情報を保存する必要が
extern crate redis;
use redis::Commands;
// fn fetch_an_integer() -> redis::RedisResult<isize> {
// // connect to redis
// let client = try!(redis::Client::open("redis://127.0.0.1/"));
// let con = try!(client.get_connection());
// // throw away the result, just make sure it does not fail
// let _ :() = try!(con.set("my_key", 42));
// // 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.
// con.get("my_key")
// }
fn fetch_a_struct() -> redis::RedisResult<MyStruct> {
// connect to redis
let client = try!(redis::Client::open("redis://127.0.0.1/"));
let con = try!(client.get_connection());
// throw away the result, just make sure it does not fail
let another_struct = AnotherStruct{x: "another_struct".to_string()};
let mut my_vec: Vec<AnotherStruct> = Vec::new();
my_vec.push(another_struct);
let my_struct = MyStruct{x: "my_struct".to_string(), y: 1, z: my_vec};
let _ :() = try!(con.set("my_key_struct", my_struct));
con.get("my_key_struct")
}
fn main() {
match fetch_a_struct() {
Err(err) => {
println!("{}", err)
},
Ok(x) => {
println!("{}", x.x)
}
}
}
struct MyStruct {
x: String,
y: i64,
z: Vec<AnotherStruct>,
}
struct AnotherStruct {
x: String
}
:私は簡単な例を作りましたそのため私はoutprocセッションストアとして、MongoDBの代わりにRedisを使用することを考えていました。
MongoDBでは、私はユーザコレクション、インタラクションコレクションなどを持っていましたが、Redisのそれと同等の方法はありますか?
RedisとRustの両方で完全な初心者であることは、少なくともこのようなことを達成するためのいくつかのアイデアを得るために私を助けてくれることを願っています。
「Rust *を使用してRedis *にデータを保存するにはどうすればよいですか」に加えて、「このタイプのデータ*をRedisに保存するにはどうすればよいですか? MongoDB、Redis、および伝統的なリレーショナルデータベースはすべて異なる強みを持ち、必ずしも相互に代わるものではありません。私は "このタイプのデータを保存するにはどうすればいいですか"というのは、スタックオーバーフローのための**広すぎる**だから、私はあなたの質問からそれを削除することをお勧めしたいと思います。 – Shepmaster