English 中文(简体)
key value stores for extendable objects
原标题:

http://www.infoq.com/presentations/newport-evolving-key-value-programming-model is a video about KV stores, and the whole premise is that redis promotes a column-based style for storing the attributes of an object under separate keys rather than serialising an object and storing it under a single key.

(This question is not redis-specific, but more a general style and best practice for KV stores in general.)

Instead of a blob for, say, a person , redis encourages a column based style where the attributes in an object are stored as separate key, e.g.

R.set("U:123:firstname","Billy")
R.set("U:123:surname","Newport")
...

I am curious if this is best practice, and if people take different approaches.

  • E.g. you could pickle an object under a single key. This has the advantage of being fetched or set in a single request

  • Or a person could be a list with the first item being a field name index or such?

This got me thinking - I d like a hierarchical key store, e.g.

R.set(["U:123","firstname"],"Billy")
R.set(["U:123","surname"],"Newport")
R.get(["U:123"]) returns [("firstname","Billy"),("surname","Newport")]

And then to add in transactions:

with(R.get(["U:132"]) as user):
  user.set("firstname","Paul")
  user.set("lastname","Simon")

From a scaling perspective, the batching of gets and sets is going to be important?

Are there key stores that do have support for this or have other applicable approaches?

问题回答

You can get similar behavior in Redis by using an extra Set to keep track of the individual members of your object.

SET U:123:firstname Billy
SADD U:123:members firstname
SET U:123:surname Cobin
SADD U:123:members surname

GET U:123:firstname => Billy
GET U:123:firstname => Cobin
SORT U:123:members GET U:123:* -> [Billy, Cobin]
or
SMEMBERS U:123:members -> [firstname, surname]
MGET U:123:firstname U:123:firstname

Not a perfect match but good enough in many situations. There s an interesting article about how hurl uses this pattern with Redis





相关问题
Memcached Writes Extremely Slow

I m running memcached on ec2 instances and in some cases am seeing extremely slow writes (10s) for small amounts of data. I m using memcache-client from rails on the client side. Has anyone seen ...

can t install memcache php module

i m trying to install memcache module from http://pecl.php.net/package/memcache. Im using xampp in ubuntu (lampp) with php 5.3. After download the extension, I run phpize, make and make install, then ...

sphinx is returning stale results

Environment: Memcached, Rails 2.2.2 + cache_money, Sphinx + thinking sphinx The following yields stale results: - add a record; mysql contains the correct data - the record is probably cached in ...

Pylons and Memcached

Anyone happen to use this combination in their web application? I m having a bit of trouble finding some sort of tutorial or guideline for configuring this. Also seeing as how I started using Pylons ...

Memcached crashing under moderate load

When running memcached, after a few minutes of use it starts throwing the following errors and memcache stops responding. mcm_server_connect_next_avail():2328 I have searched the Google, and it ...

enyim and memcached : NOT_STORED errors

We are using memcached 1.2.4 via enyim and are finding it difficult to get some objects to cache. If I watch the memcache console it just says NOT_STORED . I think we need to use [serializable] but ...

PHP - Memcache - HTML Caching

I would like to create a caching system that will bypass some mechanisms in order to improve the performance. I have some examples: 1-) I have a dynamic PHP page that is updated every hour. The page ...

热门标签