English 中文(简体)
How do you mix SQL DB vs. Key-Value store (i.e. Redis)
原标题:

I m reviewing my code and realize I spend a tremendous amount of time

  1. taking rows from a database,
  2. formatting as XML,
  3. AJAX GET to browser, and then
  4. converting back into a hashed javascript object as my local datastore.

On updates, I have to reverse the process (except using POST instead of XML.)

Having just started looking at Redis, I m thinking I can save a tremendous amount of time keeping the objects in a key-value store on the server and just using JSON to transfer directly to JS client. But my feeble mind can t anticipate what I m giving up by leaving a SQL DB (i.e. I m scared to give up the GROUP BY/HAVING queries)

For my data, I have:

  • many-many relationships, i.e. obj-tags, obj-groups, etc.
  • query objects by a combination of such, i.e. WHERE tag IN ( a , b , c ) AND group in ( x , y )
  • self joins, i.e. ALL the tags for each object WHERE tag= a (sql group_concat())
  • a lot of outer joins, i.e. OUTER JOIN rating ON o.id = rating.obj_id
  • and feeds, which seem to be a strong point in REDIS

How do you successfully mix key-value & SQL DBs?

For example, is practical to join a large list of obj.Ids from a REDIS set with SQL data using a SQL RANGE query (i.e. WHERE obj.id IN (1,4,6,7,8,34,876,9879,567,345, ...), or vice versa?

ideas/suggestions welcome.

最佳回答

You may want to take a look at MongoDB. It works with JSON style objects, and comes with SQL like indexing & querying. Redis is more suitable for storing data structures likes lists & sets, when you want a simple lookup instead of a complex query.

问题回答

Now that the actual problem is more defined (i.e. you spend a lot of time writing repetitive conversion code to move from one layer/representation to the next) maybe you could consider writing (or googling for) something that automatizes this, maybe?

Googles returns plenty of results for "convert table to XML" (and the reverse), would this help? Would something going directly from table to key/value pairs be better? Have you tried tackling this problem in a generalized way?

When you say "I spend a tremendous amount of time" do you mean this is a lot of development time, or are you referring to computing time?

Personally I d be wary of mixing a RDBMS with a non-RDBMS solution, because this will probably create problems when the two different paradigms clash.





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签