Interacting directly with a datastore can have many pitfalls. The presentation goes through an example which exposes some of the pitfalls, then shows how Ohm helps to solve them or make them a non issue. Some basic features of Ohm also covered.
5. Ohm runs on redis
Remote dictionary server
Store multiple data-structure types
6. Ohm runs on redis
Remote dictionary server
Store multiple data-structure types
Lists, Sets, Sorted Sets, Strings, Hashes
7. Ohm runs on redis
Remote dictionary server
Store multiple data-structure types
Lists, Sets, Sorted Sets, Strings, Hashes
In memory datastore with persistence strategies
8. Ohm runs on redis
Remote dictionary server
Store multiple data-structure types
Lists, Sets, Sorted Sets, Strings, Hashes
In memory datastore with persistence strategies
Super fast & easy to scale
9. Ohm runs on redis
Remote dictionary server
Store multiple data-structure types
Lists, Sets, Sorted Sets, Strings, Hashes
In memory datastore with persistence strategies
Super fast & easy to scale
Atomic operations & transactions
10. Ohm runs on redis
Remote dictionary server
Store multiple data-structure types
Lists, Sets, Sorted Sets, Strings, Hashes
In memory datastore with persistence strategies
Super fast & easy to scale
Atomic operations & transactions
Key expiry
11. Ohm runs on redis
Remote dictionary server
Store multiple data-structure types
Lists, Sets, Sorted Sets, Strings, Hashes
In memory datastore with persistence strategies
Super fast & easy to scale
Atomic operations & transactions
Key expiry
redis-rb
52. symbol = {
:name => 'Ohm',
:description => 'Ancient syllable',
:phonemes => [
{
:sound => 'aaa',
:meaning => 'beginning of the universe',
:god => 'Brahma'
}, {
:sound => 'ooo',
:meaning => 'duration of the universe',
:god => 'Vishnu'
}, {
:sound => 'mmm',
:meaning => 'dissolution of the universe',
:god => 'Shiva'
}
]
}
53. require 'rubygems'
require 'ohm'
class AncientSymbol < Ohm::Model
attribute :name
attribute :description
index :name
collection :phonemes, Phoneme
def validate
assert_present :name
end
end
54. class Phoneme < Ohm::Model
attribute :sound
attribute :meaning
attribute :god
index :sound
index :god
reference :ancient_symbol, AncientSymbol
def validate
assert_present :sound
end
end
We&#x2019;re going to build up to why we need Ohm with an example of the pitfalls of trying to roll your own solution to interact with redis as a datastore.\n
\n
\n
\n
\n
\n
\n
\n
Get reference to database\n
\n
\n
Awesome - we&#x2019;re storing our information in redis!\nSo what&#x2019;s wrong with this approach?\n
\n
The key we&#x2019;re using for symbols isn&#x2019;t adequate for multiple symbols...\n
The key we&#x2019;re using for symbols isn&#x2019;t adequate for multiple symbols...\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Using a set because each element will be unique\nOrder isn&#x2019;t important\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
index: creates an index for an attribute you want to be able to search\ncollection: similar to has_many\n
\n
Validation behaves similarly to what we see in AR\nErrors are returned as an array of attributes and the associated failure\n
Error messages are not defined within the model, but with a presenter\n\nerror_messages is just an array of errors\n
Notice that the phoneme is added to the symbols phonemes\nAND a phoneme gets a reference to ancient_symbol\n
\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
All sets are created on the fly\n
\n
\n
\n
\n
\n
attribute->string set->unordered array list->array (great for queue) reference->foreign key collection->has_many\n