Download presentation
1
NoSQL Concepts, Redis, MongoDB, CouchDB
NoSQL Databases NoSQL Concepts, Redis, MongoDB, CouchDB Svetlin Nakov Manager Technical Training Telerik Software Academy academy.telerik.com
2
Table of Contents NoSQL Databases Overview Redis MongoDB
Ultra-fast data structures server Redis Cloud: managed Redis MongoDB Powerful and mature NoSQL database MongoLab: managed MongoDB in the cloud
3
Overview, Models, Concepts, Examples
NoSQL Databases Overview, Models, Concepts, Examples
4
Non-Relational Data Models
Document model Set of documents, e.g. JSON strings Key-value model Set of key-value pairs Hierarchical key-value Hierarchy of key-value pairs Wide-column model Key-value model with schema Object model Set of OOP-style objects
5
What is NoSQL Database? NoSQL (cloud) databases
Use document-based model (non-relational) Schema-free document storage Still support indexing and querying Still support CRUD operations (create, read, update, delete) Still supports concurrency and transactions Highly optimized for append / retrieve Great performance and scalability NoSQL == “No SQL” or “Not Only SQL”?
6
Relational vs. NoSQL Databases
Relational databases Data stored as table rows Relationships between related rows Single entity spans multiple tables RDBMS systems are very mature, rock solid NoSQL databases Data stored as documents Single entity (document) is a single record Documents do not have a fixed structure
7
Relational vs. NoSQL Models
Relational Model Document Model Name Svetlin Nakov Gender male Phone Site Name: Svetlin Nakov Gender: male Phone: Address: - Street: Al. Malinov 31 - Post Code: 1729 - Town: Sofia - Country: Bulgaria Site: * 1 Street Al. Malinov 31 Post Code 1729 * 1 Town Sofia * 1 Country Bulgaria
8
Ultra-Fast Data Structures Server
Redis Ultra-Fast Data Structures Server
9
What is Redis? Redis is Redis stores data structures:
Ultra-fast in-memory key-value data store Powerful data structures server Open-source software: Redis stores data structures: Strings Lists Hash tables Sets / sorted sets
10
Hosted Redis Providers
Redis Cloud Fully managed Redis instance in the cloud Highly scalable, highly available Free 1 GB instance, stored in the Amazon cloud Supports data persistence and replication Redis To Go 5 MB free non-persistent Redis instance
11
C# API for Redis ServiceStack.Redis API Sample C# code:
github.com/ServiceStack/ServiceStack.Redis Sample C# code: string redisHost = "redis.garantiadata.com"; int redisPort = 14233; string redisPass = using (var redisClient = new RedisClient(redisHost, redisPort, redisPass)) { string key = "username"; string value = "nakov"; redisClient.Set<string>(key, value); Console.WriteLine(redisClient.Get<string>(key)); }
12
Redis on a Local Machine
Live Demo
13
Mature and Very Powerful NoSQL Database
MongoDB Mature and Very Powerful NoSQL Database
14
What is MongoDB? MongoDB – http://mongodb.org
Very powerful and mature NoSQL database Scalable, high-performance, open-source JSON-style document storage, schemaless Replication & high-availability support Auto sharding – clustering & data partitioning Indexing and powerful querying Map-Reduce – parallel data processing GridFS – store files of any size
15
Hosted MongoDB Providers
MongoLab Free 0.5 GB instance MongoHQ Free 0.5 GB instance (sandbox) MongoOd Free 100 MB instance
16
C# API for MongoDB The official MongoDB C# driver from 10gen
github.com/mongodb/mongo-csharp-driver Sample C# code: var connectionStr = var client = new MongoClient(connectionSt); var server = client.GetServer(); var db = server.GetDatabase("mongodb-name"); var persons = db.GetCollection<Person>("Persons"); persons.Insert<Person>(new Person(…)); var resultPersons = from p in persons.AsQueryable<Person>() where p.Address.Town == "Sofia" select p;
17
MongoDB on a Local Machine
Live Demo
18
NoSQL Databases
19
Exercises Write a simple "Dictionary" application in C# or JavaScript to perform the following in MongoDB: Add a dictionary entry (word + translation) List all words and their translations Find the translation of given word The UI of the application is up to you (it could be Web-based, GUI or console-based). You may use MongoLab. You may install the "Official MongoDB C# Driver" from NuGet or download it from its publisher:
20
Exercises (2) Implement the previous task (a simple "Dictionary" application) using Redis. You may hold the "word + meaning pairs" in a hash (see See the HSET, HKEYS and HGET commands You may use a local Redis instance or register for a free "Redis To Go" account at You may download the client libraries for your favorite programming language from or use the "ServiceStack.Redis" C# client from the NuGet package manager.
21
Exercises (3) * Implement а program, which synchronizes mouse movement and clicking between multiple computers. Users can "give control" to other users. Users sign in with username and password. Users "in control" can revoke their control. A user can be signed in on several machines at once. Store user data in MongoLab. Store the mouse sync data in the "Redis To Go" cloud. Note: In the real world data would pass through a server, as direct access from the client to the database is a security concern. This task is meant more as an experiment than a real-world scenario.
22
Free Trainings @ Telerik Academy
Telerik School Academy schoolacademy.telerik.com Telerik Software Academy academy.telerik.com Telerik Facebook facebook.com/TelerikAcademy Telerik Software Academy Forums forums.academy.telerik.com
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.