Crate ohmers [−] [src]
Object-hash mapping library for Redis.
Ohmers is a library for storing objects in Redis, a persistent key-value database. It is based on the Ruby library Ohm, and it uses the same key names, so it can be used in the same system.
Prerequisites
Have a redis server running and a redis-rs connection.
Getting started
Ohmers maps Rust structs to hash maps in Redis. First define the structs using the model! macro, and then use their methods to created, read, update, delete.
model!(Event { indices { name:String = "My Event".to_string(); }; venue:Reference<Venue> = Reference::new(); participants:Set<Person> = Set::new(); votes:Counter = Counter; }); model!(Venue { name:String = "My Venue".to_string(); events:Set<Event> = Set::new(); }); model!(Person { name:String = "A Person".to_string(); }); let p1 = create!(Person { name: "Alice".to_string(), }, &client).unwrap(); let p2 = create!(Person { name: "Bob".to_string(), }, &client).unwrap(); let p3 = create!(Person { name: "Charlie".to_string(), }, &client).unwrap(); let v1 = create!(Venue { name: "Home".to_string(), }, &client).unwrap(); let v2 = create!(Venue { name: "Work".to_string(), }, &client).unwrap(); let mut e1 = create!(Event { name: "Birthday Party".to_string(), }, &client).unwrap(); insert!(e1.participants, p1, &client).unwrap(); insert!(e1.participants, p2, &client).unwrap(); insert!(e1.participants, p3, &client).unwrap(); e1.venue.set(&v1); e1.save(&client).unwrap(); let mut e2 = create!(Event { name: "Work Meeting".to_string(), }, &client).unwrap(); insert!(e2.participants, p1, &client).unwrap(); insert!(e2.participants, p2, &client).unwrap(); e2.venue.set(&v2); e2.save(&client).unwrap();
Macros
collection! |
Properties declared as |
contains! |
Checks if an element is in a List or a Set. |
counter! | |
create! |
Creates a new instance of |
decr! | |
find! |
Returns a |
first! |
Retrieves an element from the beginning of |
incr! | |
insert! |
Insert |
last! |
Retrieves an element from the end of |
len! |
Number of elements in a List or Set property. |
model! |
Declares a struct.
Fields may be declared as a part of uniques, indices, or regular fields.
Every field must have a default value.
The struct will derive RustcEncodable, RustcDecodable, and Default.
More |
new! |
Creates a new instance of |
pop_back! |
Retrieves and remove an element from the end of |
pop_front! |
Retrieves and remove an element from the beginning of |
push_back! |
Adds |
push_front! |
Adds |
remove! |
Removes occurences of an element in a List or a Set. |
try_iter! |
Creates an iterable of all elements in |
try_range! |
Creates an iterable of |
Structs
Collection |
A wrapper for classes that are referenced from another classes property. |
Counter |
Atomic counter |
Iter |
Iterator for query results |
List |
A list of elements. |
Query |
A query of a set, or a result of set operations. |
Reference |
A Reference to another Ohmer object. |
Set |
An unordered collection of items. |
Enums
OhmerError | |
StalSet |
A set of values. It can be generated from a Redis key or from a set operation based on other sets. |
Traits
Ohmer |
Structs that can be stored in and retrieved from Redis.
You can use the |
Functions
all |
Gets an iterator for all elements. |
all_query |
Gets a query for all elements. |
get |
Gets an element by id. |
with |
Find an element by a unique index. |