My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
TwitterAlikeExample  
Updated Dec 21, 2010 by anti...@gmail.com

We moved to Redis.io!

Redis home moved to http://redis.io, please visit our new home.

Comment by mduaf...@gmail.com, Mar 12, 2009

Speaking to your last point about global:timeline, what you have suggested is essentially 'lamport time'. Lamport time requires that each node produce increasing time values (which is where it differs from your suggestion), but I believe that adding this constraint could solve the problem (though I'm not sure if it would be worth the effort).

Mathew Duafala

Comment by project member anti...@gmail.com, Mar 12, 2009

thanks mduafala, I'll study better lamport time but I still can't figure how it is possible to distribute the list stored in global:timeline without the need of a merge operation later, even if I got an idea from what you said about this issue.

That is, append the element N to server 0, N+1 to server 1, N+2 to server 3, .. adn so on, so you end with an interleaved list that you can merge in O(N).

Comment by codeslin...@gmail.com, Mar 12, 2009

Yeah, antirez, that's how you'd have to do it. Once you split up a list like that, its all scatter-gather to do stuff with it from then on.

Comment by dov.mu...@gmail.com, Mar 16, 2009

Typo at the end of 'Updates' section: I believe ORDER BY (and not SORT BY) is the correct keyword for sorting in SQL.

Comment by project member anti...@gmail.com, Mar 16, 2009

@dov.murik: thanks fixed

Comment by arjenrei...@gmail.com, Mar 24, 2009

You can also use an encrypted user_id and user_name stored in the cookie.

Comment by smullen....@gmail.com, Mar 25, 2009

Why was the choice made to concatenate UID, posting time, and post rather than using an array? Is there a speed difference?

Comment by project member anti...@gmail.com, Mar 25, 2009

@smullen.uclick when you don't need to access this fields separately, it's better to use a separator: atomicity of get/set of the three elements, memory saving, speed.

Comment by videlalv...@gmail.com, Mar 27, 2009

Is there a reason why the PHP client library is written using PHP4?

Comment by project member anti...@gmail.com, Mar 28, 2009

@videlalvaro backward compatibility and PHP5 features not needed. There is a new PHP lib in development, written in C as PHP module, but the pure-PHP lib will be maintained anyway.

Cheers, Salvatore

Comment by videlalv...@gmail.com, Mar 30, 2009

@antirez Nice :-) Any release date for this PHP module?

Comment by stevedu...@gmail.com, Apr 7, 2009
Comment by seas...@gmail.com, Apr 12, 2009

@antirez Amazing example. Is there any Java API release?

Comment by pole...@gmail.com, May 3, 2009

In this example:

SADD uid:1000:following 1001
SADD uid:1001:followers 1000

How would you atomically do both commands? What would happen if redis crashed after doing the first operation but before doing the second operation?

Comment by project member anti...@gmail.com, May 4, 2009

@poleris in order to perform this operations atomically currently there is no way. Also in the client crashes after the first operation the effect will be to have just the first set modified.

After Redis-1.0 stable will be released I'll start to work on 1) a LOCKing primitive, that will allow the atomicity. 2) A way to send multiple commands and tell Redis to only exec the commands when we can be sure all can be processed without interruption. This is also a guarantee of atomicity itself. Example:

PREPARE
SADD foo 1
SADD bar 1
COMMIT

What will happen is that the two SADD will be executed only when you call COMMIT, so either both or none will be executed. Also the commands are guaranteed to be performed one after the other without any other command executed in the middle, so atomically.

For now it's simply too important to release 1.0-stable, so this features will be shifted after 1.0 stable. Please feel free to post your exact need in the Redis DB google group, there is almost always a locking free way of doing a lot of things.

Comment by or.else....@gmail.com, Jun 21, 2009

Isn't this auth cookie business susceptible to cookie hijacking? If I go to an Internet café of some kind, login to their Wi-Fi, and run a packet sniffer, I'd perhaps find a stray Set-Cookie: line floating around. I could then create the same cookie in my browser and just like that, I'm logged in as the other user.

Comment by k...@freemail.hu, Oct 6, 2009

Posts or login names with Non-Latin1 charaters does not display at all. (I tried hungarian ones) My ugly workaround was: retwis.php

@@ -60,7 +60,7 @@

}
function utf8entities($s) {
- return htmlentities($s,ENT_COMPAT,'UTF-8'); + return htmlspecialchars($s);
}
function goback($msg) {

Comment by nkch...@gmail.com, Nov 7, 2009

is it possible and meaningful to design a high level programming language or system which generate redis instructions as low level code? redis as a VM, a funny idea suddenly come out to me

Comment by project member anti...@gmail.com, Nov 10, 2009

@nkchenz: I guess not, Redis is not turing-complete ;)

Comment by kwreczy...@gmail.com, Nov 10, 2009

Someting is wrong with http://retwis.antirez.com/ application, I guess, redis server is off ;P

Comment by lorenzki...@gmail.com, Nov 24, 2009

Hi! Great app and great help for anyone learning redis. I have a question though:

You write "we don't need to lookup by time or user id in the example application so it is better to compact everything inside the post string."

However in the ruby clone of this app ("retwis-rb"), the author danlucraft took the opposite approach saving each individual piece of information under its own key ("post:id:1:user_id" => "1", "post:id:1:timestamp" => "Tue Nov 24 17:00:27 +0100 2009", "post:id:1:content" => "Hello World!").

You only save one item "post:1" => "1|Tue Nov 24 17:00:27 +0100 2009|Hello World!".

What are the pros/cons of each approach? I'd say, his solution is more general but requires three GETs per post. Yours is more specific and requires custom serialization, but gets by with only one GET per post.

In general, would I rather want many GETs for individual values or fewer gets for serialized data?

Comment by lorenzki...@gmail.com, Nov 25, 2009

Answer to my own question: This article describes both approaches (under "Attributes") http://www.paperplanes.de/2009/10/30/how_to_redis.html and also favors the one-key-to-serialzed-values approach taken here.

Comment by con...@gmail.com, Dec 22, 2009

Now what happens if a user posts something that contains "|" ? Isn't that encoding somehow unsecure?

Comment by zerkmss, Jan 12, 2010

@contag

the using of third argument of explode() will prevent all possible secure vulnerabilities

$aux = explode('|', $postdata, 3);

Comment by timmy.b...@gmail.com, Feb 26, 2010

I wrote a Retwis clone in python, based on retwis-rb : http://github.com/pims/retwis-py if someone prefers python to php :)

Comment by murtl...@gmail.com, May 23, 2010

There is one important thing missing. When you start to follow a person on twitter you get his/hers old updates included in your timeline. It seems to me that that would be impossible with a redis list since your can only insert values from left or right or maybe at a index-position but not at a date.

Comment by hema...@gmail.com, Jun 4, 2010

is it possible to simulate ORDER BY field1, field2 of SQL in redis? Can u give some example patterns for GET option within SORT command (if i want to search all the keys contains string 'abc')...

Comment by yuanzhil...@gmail.com, Jul 6, 2010

ok,try

Comment by twin...@gmail.com, Aug 2, 2010

The Redis Cluster project is going to be our next priority after the release of Redis 2.0.0. Redis Cluster is an higher level layer implemented as a different decoupled component using normal Redis instances as "Data Nodes". Redis Cluster will support adding and removing nodes while the system is running and fault tolerance. well, we need Redis Cluster!

Comment by sanjiv....@gmail.com, Sep 15, 2010

Two Questions. a) What was the optimal maximum record size per key for the said benchmark where the 5ms pageview was achieved. b) This question is directed more at the design of the twitter clone rather than the underlying redis architecture. How would this scale when a good subset of users has 1000+ followers. Wouldn't that mean 1000 writes for each post/tweet ?

Comment by kannan.d...@gmail.com, Sep 28, 2010

can you explain some more (with a case) why we need two keys for auth

SET uid:1000:auth fea5e81ac8ca77622bed1c2132a021f9 
SET auth:fea5e81ac8ca77622bed1c2132a021f9 1000 

why is "uid:1000:auth" not sufficient?

Comment by kannan.d...@gmail.com, Sep 28, 2010

this example is informative - tells how to think about a key-value app.

i have one minor suggestion, in post update the $followers array is modified but not persisted, it is more readable to set the user post separately.

old:

$followers[] = $User['id']; /* Add the post to our own posts too */

foreach($followers as $fid) {
    $r->push("uid:$fid:posts",$postid,false);
}

new:

$uid = $User['id'];

foreach($followers as $fid) {
    $r->push("uid:$fid:posts",$postid,false);
}
$r->push("uid:$uid:posts",$postid,false);
}}
Comment by lookis...@gmail.com, Dec 6, 2010

how to move my old data to new redis server when i try making it horizontally scalable?

Comment by vait...@gmail.com, Dec 8, 2010

Please, restart redis for your retwis demo.

Comment by kaushal....@gmail.com, Dec 21, 2010

test

Comment by and...@andrewzeneski.com, Jan 14, 2011

FYI I threw together a prototype, a clone of this PHP example, in Python using the Tornado framework. Its available on github (http://bit.ly/gYJhp6)

Comment by ZDWal...@gmail.com, Apr 30, 2011

I am trying out redis, with node.js. Here is my code on github(https://github.com/zdwalter/retwis-js-node-express)

still working on it.

Comment by waseda1...@gmail.com, Jun 5, 2011

great redis !


Sign in to add a comment
Powered by Google Project Hosting