0

I'm trying to do some tricks with a graph (node/edges) dataset. In this case a set of data where person x follows person y (direct relation). I want to load this data (from a mysql table) into redis (have it running). I've chosen to use Rediska because I use PHP and it seems stable.

Rediska has very limited documentation and examples, so I was hoping you guys can help me. I have little to no experience with noSQL, especially the naming conventions (userid:1:follows = 2?).

My questions:

  • how do I load a set of person x follows person y data into a redis data set
  • how do I find the "intersect" (SINTER) and end up with a php array (so I get person X and person Y both follow (a result set) of people))
  • and last not but leasy, how would I 'traverse' this graph data to find a relation: person x -> person y -> person z (person x and person z both follow person y, hence person z is in the result set)
ymschaap
  • 61
  • 1
  • 5
  • Just as an aside: rediska is not the recommended way to connect from php to redis as you can see here: http://redis.io/clients its best to use either PHPRedis (a C extension) or Predis (written in plain PHP). – Max Jun 13 '11 at 15:14

1 Answers1

1

Q1 How do you load a set of person x follows person y data into a redis data set?
you need to use a set as the data structure and throw in there the indexes of people following. For example, suppose you have 10 users with ids from 1 to 10 and you want to say that person:3, person:5 and person:10 are all following person:2 ...

sadd person:2:followers 3
sadd person:2:followers 5
sadd person:2:followers 10

This would give you a set of followers for person 2 containing the ids 3, 5 and 10. To query this data...

smembers person:2:followers

Q2 How do I find the intersect and end up with a php array(person:x:followers && person:y:followers)?

sinterstore tmp person:2:followers person:8:followers
sort tmp get person:*->name get person:*->age 

Q3 how would you traverse this graph data to find a relation: person x -> person y -> person z (person x and person z both follow person y, hence person z is in the result set)?

This question does not make sense (to me at least). Could you explain or reword it?
Lloyd Moore
  • 3,117
  • 1
  • 32
  • 32