Skip to content

Instantly share code, notes, and snippets.

@felipehummel
Created February 17, 2012 04:28
Show Gist options
  • Save felipehummel/1850661 to your computer and use it in GitHub Desktop.
Save felipehummel/1850661 to your computer and use it in GitHub Desktop.
Refactor scala
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