Welcome! Log In Create A New Profile

Advanced

Most efficient way of modifying value

Posted by Jorge 
Jorge
Most efficient way of modifying value
October 19, 2010 07:30PM
Hello!

I would like to use memcached as a fast cache for a hospital order
database.

Each order has a location (5 possible values), procedure (about 100
possible values),
and patient status (3 different values).

So, my thinking was for each order, create a key as follows:

(location code)_(procedure code)_(status code)

and the value would be a list of all orders matching a given code.

So, doing a query on a given location, procedure and status will just
entail reading the value from the key.

My question is: what is the best way of modifying the value, as an in-
memory list.

Can this be done on the memcached server, or do I need the client to
pull the value out,
modify it, and put it back in?

Thanks!
nooby
Re: Most efficient way of modifying value
October 26, 2010 07:30PM
Hi,

If I understand correctly you want to modify the value without
having the client fetching the value first.
Obviously this means that whatever value was there in the first
place is not important so 'replace' operation should do the trick.
That is, replace the value if and only if it already exists there.

If you have many clients trying to do an update the last replace wins
which might not be what you want. You might want to look at compare
and set operation which obviously requires you to do a get first.

Also take a look at the memcached FAQ for the "ghetto lock" in this
case you would do a lock even if the value already existed because the
client will modify it anyway i guess.

i hope this helps...



On Oct 19, 1:16 pm, Jorge <[email protected]> wrote:
> Hello!
>
> I would like to use memcached as a fast cache for  a hospital order
> database.
>
> Each order has a location (5 possible values), procedure (about 100
> possible values),
> and patient status (3 different values).
>
> So, my thinking was for each order, create a key as follows:
>
> (location code)_(procedure code)_(status code)
>
> and the value would be a list of all orders matching a given code.
>
> So, doing a query on a given location, procedure and status will just
> entail reading the value from the key.
>
> My question is: what is the best way of modifying the value, as an in-
> memory list.
>
> Can this be done on the memcached server, or do I need the client to
> pull the value out,
> modify it, and put it back in?
>
> Thanks!
Dustin
Re: Most efficient way of modifying value
October 26, 2010 07:50PM
On Oct 26, 6:57 am, nooby <[email protected]> wrote:

>   Obviously this means that whatever value was there in the first
> place is not important so 'replace' operation should do the trick.
> That is, replace the value if and only if it already exists there.

I wouldn't recommend the replace operation in general. All it means
is ``only fail if I'm not destroying data somewhere.'' You can't make
any assumptions as to what data is being destroyed.

Any place where you'd use replace, you probably want either plain
set or set with a CAS.
Rohit Karlupia
Re: Most efficient way of modifying value
October 26, 2010 10:00PM
May be you are better off using redis which provides some in memory pre
built data structures like lists and sets.

thanks!
rohitk


On Tue, Oct 19, 2010 at 10:46 PM, Jorge <[email protected]> wrote:

> Hello!
>
> I would like to use memcached as a fast cache for a hospital order
> database.
>
> Each order has a location (5 possible values), procedure (about 100
> possible values),
> and patient status (3 different values).
>
> So, my thinking was for each order, create a key as follows:
>
> (location code)_(procedure code)_(status code)
>
> and the value would be a list of all orders matching a given code.
>
> So, doing a query on a given location, procedure and status will just
> entail reading the value from the key.
>
> My question is: what is the best way of modifying the value, as an in-
> memory list.
>
> Can this be done on the memcached server, or do I need the client to
> pull the value out,
> modify it, and put it back in?
>
> Thanks!
>
>
Dustin
Re: Most efficient way of modifying value
October 26, 2010 10:20PM
On Oct 19, 10:16 am, Jorge <[email protected]> wrote:

> My question is: what is the best way of modifying the value, as an in-
> memory list.

Just append the new value with some sort of separator.

> Can this be done on the memcached server, or do I need the client to
> pull the value out,
> modify it, and put it back in?

If you need something more complex than append, you can build save
an arbitrarily complex transformations with CAS.
Aaron Boxer
Re: Most efficient way of modifying value
October 26, 2010 11:30PM
Thanks, rhohitk. I found out about redis after some further
investigation; looks perfect for this problem.

On Tue, Oct 26, 2010 at 3:58 PM, Rohit Karlupia <[email protected]> wrote:
> May be you are better off using redis which provides some in memory pre
> built data structures like lists and sets.
> thanks!
> rohitk
>
> On Tue, Oct 19, 2010 at 10:46 PM, Jorge <[email protected]> wrote:
>>
>> Hello!
>>
>> I would like to use memcached as a fast cache for  a hospital order
>> database.
>>
>> Each order has a location (5 possible values), procedure (about 100
>> possible values),
>> and patient status (3 different values).
>>
>> So, my thinking was for each order, create a key as follows:
>>
>> (location code)_(procedure code)_(status code)
>>
>> and the value would be a list of all orders matching a given code.
>>
>> So, doing a query on a given location, procedure and status will just
>> entail reading the value from the key.
>>
>> My question is: what is the best way of modifying the value, as an in-
>> memory list.
>>
>> Can this be done on the memcached server, or do I need the client to
>> pull the value out,
>> modify it, and put it back in?
>>
>> Thanks!
>>
>
>
Sorry, only registered users may post in this forum.

Click here to login