Created
February 17, 2012 04:28
-
-
Save felipehummel/1850661 to your computer and use it in GitHub Desktop.
Refactor scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create(userId: String, feedItemId: String) { | |
println("user: "+userId + " clipou: "+feedItemId) | |
redisClientPool.withClient { client => | |
val itemsAdded = addItemToClips(redis, userId, feedItemId) | |
if (itemsAdded != 0) { | |
addClipToTimeline(client, userId, feedItemId) | |
userFollowersSet(client, userId) match { | |
case Some(followersIds) => followersIds.flatten { followerId => | |
addClipToTimeline(client, userId, feedItemId) | |
} | |
case None => println("No followers? Looser!") | |
} | |
} | |
} | |
} | |
def addClipToTimeline(client: RedisClient, userId: String, feedItemId: String) = | |
client.lpush("user:"+userId+":timeline","c|"+feedItemId+"|"+userId) | |
def userFollowersSet(client: RedisClient, userId: String) : Set[Option[String]] = | |
client.smembers("user:"+userId+":followers") | |
def addItemToClips(client: RedisClient, userId, feedItemId: String) : Int = | |
client.sadd("user:"+userId+":clips", feedItemId).getOrElse(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment