{"action":"created","comment":{"url":"https://api.github.com/repos/twitter/finagle/pulls/comments/30470746","id":30470746,"diff_hunk":"@@ -0,0 +1,364 @@\n+package com.twitter.finagle.redis.integration\n+\n+import java.math.BigInteger\n+\n+import com.twitter.finagle.redis.naggati.RedisClientTest\n+import com.twitter.finagle.redis.{Client, ServerError}\n+import com.twitter.io.Charsets\n+import com.twitter.util.Await.result\n+import com.twitter.util.Future\n+import org.jboss.netty.buffer.{ChannelBuffer, ChannelBuffers}\n+import org.junit.runner.RunWith\n+import org.scalatest.junit.JUnitRunner\n+import org.scalatest.MustMatchers\n+\n+// Testing scripting features of redis Client\n+@RunWith(classOf[JUnitRunner])\n+class ScriptClientIntegrationSuite extends RedisClientTest with MustMatchers {\n+  def stringToBuffer(s: String): ChannelBuffer = {\n+    ChannelBuffers.wrappedBuffer(s.getBytes(Charsets.Utf8))\n+  }\n+\n+  def stringsToBuffers(s: String*): Seq[ChannelBuffer] = {\n+    s map stringToBuffer\n+  }\n+\n+  def stringToBufferMap(pairs: (String, String)*): Map[ChannelBuffer, ChannelBuffer] = {\n+    Map(pairs map {p => (stringToBuffer(p._1), stringToBuffer(p._2))} :_*)\n+  }\n+\n+  def bufferToString(buffer: ChannelBuffer): String = {\n+    buffer.toString(Charsets.Utf8)\n+  }\n+\n+  def buffersToStrings(buffers: Seq[ChannelBuffer]): Seq[String] = {\n+    buffers map bufferToString\n+  }\n+\n+//  def bufferToStringOpt(buffers: Option[ChannelBuffer]): Option[String] = {\n+//    buffers map bufferToString\n+//  }\n+\n+  def toHexString(bytes: Array[Byte]) = {\n+    String.format(\"%040x\", new BigInteger(1, bytes))\n+  }\n+\n+  def SHA1hexString(buffer: ChannelBuffer): String = {\n+    val md = java.security.MessageDigest.getInstance(\"SHA-1\")\n+    toHexString((md.digest(buffer.array())))\n+  }\n+\n+  def SHA1hex(buffer: ChannelBuffer): ChannelBuffer = {\n+    stringToBuffer(SHA1hexString(buffer))\n+  }\n+\n+  val scriptSet = \"redis.call('set', KEYS[1], ARGV[1])\"\n+\n+  val scriptSetReturn = \"return redis.call('set', KEYS[1], ARGV[1])\"\n+\n+  val scriptGet = \"return redis.call('get', KEYS[1])\"\n+\n+  val scriptGetLong = \"return tonumber(redis.call('get', KEYS[1]))\"\n+\n+  val scriptUse =\n+    \"\"\"\n+      |local v = redis.call('decrby', KEYS[1], ARGV[1])\n+      |if v >= 0 then\n+      |  return v\n+      |else\n+      |  local x = redis.call('incrby', KEYS[1], ARGV[1])\n+      |  assert(x == v+tonumber(ARGV[1]), 'something wrong!')\n+      |  error(KEYS[1] .. ' < ' .. ARGV[1] .. ' by: ' .. v)\n+      |end\n+    \"\"\".stripMargin\n+\n+  val scriptCompare =\n+    \"\"\"\n+      |local v = tonumber(redis.call('get', KEYS[1]))\n+      |return v >= tonumber(ARGV[1])\n+    \"\"\".stripMargin\n+\n+  val scriptTest =\n+    \"\"\"\n+      |local v = tonumber(redis.call('get', KEYS[1]))\n+      |if v > tonumber(ARGV[1]) then\n+      |  return { [\"ok\"] = \"1\" }\n+      |elseif v == tonumber(ARGV[1]) then\n+      |  return { [\"err\"] = KEYS[1] .. \" == \" .. ARGV[1] }\n+      |end\n+    \"\"\".stripMargin\n+\n+  val scriptHGetAll = \"return redis.call('hgetall', KEYS[1])\"\n+\n+  val scriptHMGet = \"return redis.call('hmget', KEYS[1], unpack(ARGV))\"\n+\n+  val scriptFactorial =\n+    \"\"\"\n+      |local function fact(n)\n+      |  if n == 0 then\n+      |    return 1\n+      |  else\n+      |    return n * fact(n-1)\n+      |  end\n+      |end\n+      |redis.call('set', KEYS[1], fact( tonumber(ARGV[1]) ) )\n+    \"\"\".stripMargin\n+\n+  def testScriptAndSha[T, X](testName: String, scripts: Seq[ChannelBuffer],\n+                             eval: Client => (ChannelBuffer, Seq[ChannelBuffer], Seq[ChannelBuffer]) => T,\n+                             evalSha: Client => (ChannelBuffer, Seq[ChannelBuffer], Seq[ChannelBuffer], Option[ChannelBuffer]) => T,\n+                             testCase: (String, Seq[ChannelBuffer], Client => (ChannelBuffer, Seq[ChannelBuffer], Seq[ChannelBuffer]) => T) => X) = {\n+    val sha1s = scripts map SHA1hex\n+\n+    def noSha1sExist(client: Client) = {\n+      result(client.scriptExists(sha1s: _*)).reduce(_ || _) mustBe false","path":"finagle-redis/src/test/scala/com/twitter/finagle/redis/commands/script/ScriptClientIntegrationSuite.scala","position":114,"original_position":114,"commit_id":"1d36bd1b797351b98cca20ec34e808963195d120","original_commit_id":"1d36bd1b797351b98cca20ec34e808963195d120","user":{"login":"mosesn","id":156562,"avatar_url":"https://avatars.githubusercontent.com/u/156562?v=3","gravatar_id":"","url":"https://api.github.com/users/mosesn","html_url":"https://github.com/mosesn","followers_url":"https://api.github.com/users/mosesn/followers","following_url":"https://api.github.com/users/mosesn/following{/other_user}","gists_url":"https://api.github.com/users/mosesn/gists{/gist_id}","starred_url":"https://api.github.com/users/mosesn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mosesn/subscriptions","organizations_url":"https://api.github.com/users/mosesn/orgs","repos_url":"https://api.github.com/users/mosesn/repos","events_url":"https://api.github.com/users/mosesn/events{/privacy}","received_events_url":"https://api.github.com/users/mosesn/received_events","type":"User","site_admin":false},"body":"`assert(!result(client.scriptExists(sha1s: _*)).reduce(_ || _))`","created_at":"2015-05-17T14:18:24Z","updated_at":"2015-05-17T14:18:24Z","html_url":"https://github.com/twitter/finagle/pull/381#discussion_r30470746","pull_request_url":"https://api.github.com/repos/twitter/finagle/pulls/381","_links":{"self":{"href":"https://api.github.com/repos/twitter/finagle/pulls/comments/30470746"},"html":{"href":"https://github.com/twitter/finagle/pull/381#discussion_r30470746"},"pull_request":{"href":"https://api.github.com/repos/twitter/finagle/pulls/381"}}},"pull_request":{"url":"https://api.github.com/repos/twitter/finagle/pulls/381","id":35350438,"html_url":"https://github.com/twitter/finagle/pull/381","diff_url":"https://github.com/twitter/finagle/pull/381.diff","patch_url":"https://github.com/twitter/finagle/pull/381.patch","issue_url":"https://api.github.com/repos/twitter/finagle/issues/381","number":381,"state":"open","locked":false,"title":"add scripting feature to finagle-redis with integration tests.","user":{"login":"timxzl","id":3528953,"avatar_url":"https://avatars.githubusercontent.com/u/3528953?v=3","gravatar_id":"","url":"https://api.github.com/users/timxzl","html_url":"https://github.com/timxzl","followers_url":"https://api.github.com/users/timxzl/followers","following_url":"https://api.github.com/users/timxzl/following{/other_user}","gists_url":"https://api.github.com/users/timxzl/gists{/gist_id}","starred_url":"https://api.github.com/users/timxzl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timxzl/subscriptions","organizations_url":"https://api.github.com/users/timxzl/orgs","repos_url":"https://api.github.com/users/timxzl/repos","events_url":"https://api.github.com/users/timxzl/events{/privacy}","received_events_url":"https://api.github.com/users/timxzl/received_events","type":"User","site_admin":false},"body":"supported commands: EVAL, EVALSHA, SCRIPT EXISTS, SCRIPT FLUSH, SCRIPT LOAD.","created_at":"2015-05-13T17:25:54Z","updated_at":"2015-05-17T14:18:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8f652b6409e8f77130e30fe4d6822b1028b6b9f2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/twitter/finagle/pulls/381/commits","review_comments_url":"https://api.github.com/repos/twitter/finagle/pulls/381/comments","review_comment_url":"https://api.github.com/repos/twitter/finagle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/twitter/finagle/issues/381/comments","statuses_url":"https://api.github.com/repos/twitter/finagle/statuses/1d36bd1b797351b98cca20ec34e808963195d120","head":{"label":"timxzl:master","ref":"master","sha":"1d36bd1b797351b98cca20ec34e808963195d120","user":{"login":"timxzl","id":3528953,"avatar_url":"https://avatars.githubusercontent.com/u/3528953?v=3","gravatar_id":"","url":"https://api.github.com/users/timxzl","html_url":"https://github.com/timxzl","followers_url":"https://api.github.com/users/timxzl/followers","following_url":"https://api.github.com/users/timxzl/following{/other_user}","gists_url":"https://api.github.com/users/timxzl/gists{/gist_id}","starred_url":"https://api.github.com/users/timxzl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timxzl/subscriptions","organizations_url":"https://api.github.com/users/timxzl/orgs","repos_url":"https://api.github.com/users/timxzl/repos","events_url":"https://api.github.com/users/timxzl/events{/privacy}","received_events_url":"https://api.github.com/users/timxzl/received_events","type":"User","site_admin":false},"repo":{"id":35559265,"name":"finagle","full_name":"timxzl/finagle","owner":{"login":"timxzl","id":3528953,"avatar_url":"https://avatars.githubusercontent.com/u/3528953?v=3","gravatar_id":"","url":"https://api.github.com/users/timxzl","html_url":"https://github.com/timxzl","followers_url":"https://api.github.com/users/timxzl/followers","following_url":"https://api.github.com/users/timxzl/following{/other_user}","gists_url":"https://api.github.com/users/timxzl/gists{/gist_id}","starred_url":"https://api.github.com/users/timxzl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timxzl/subscriptions","organizations_url":"https://api.github.com/users/timxzl/orgs","repos_url":"https://api.github.com/users/timxzl/repos","events_url":"https://api.github.com/users/timxzl/events{/privacy}","received_events_url":"https://api.github.com/users/timxzl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/timxzl/finagle","description":"A fault tolerant, protocol-agnostic RPC system","fork":true,"url":"https://api.github.com/repos/timxzl/finagle","forks_url":"https://api.github.com/repos/timxzl/finagle/forks","keys_url":"https://api.github.com/repos/timxzl/finagle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/timxzl/finagle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/timxzl/finagle/teams","hooks_url":"https://api.github.com/repos/timxzl/finagle/hooks","issue_events_url":"https://api.github.com/repos/timxzl/finagle/issues/events{/number}","events_url":"https://api.github.com/repos/timxzl/finagle/events","assignees_url":"https://api.github.com/repos/timxzl/finagle/assignees{/user}","branches_url":"https://api.github.com/repos/timxzl/finagle/branches{/branch}","tags_url":"https://api.github.com/repos/timxzl/finagle/tags","blobs_url":"https://api.github.com/repos/timxzl/finagle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/timxzl/finagle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/timxzl/finagle/git/refs{/sha}","trees_url":"https://api.github.com/repos/timxzl/finagle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/timxzl/finagle/statuses/{sha}","languages_url":"https://api.github.com/repos/timxzl/finagle/languages","stargazers_url":"https://api.github.com/repos/timxzl/finagle/stargazers","contributors_url":"https://api.github.com/repos/timxzl/finagle/contributors","subscribers_url":"https://api.github.com/repos/timxzl/finagle/subscribers","subscription_url":"https://api.github.com/repos/timxzl/finagle/subscription","commits_url":"https://api.github.com/repos/timxzl/finagle/commits{/sha}","git_commits_url":"https://api.github.com/repos/timxzl/finagle/git/commits{/sha}","comments_url":"https://api.github.com/repos/timxzl/finagle/comments{/number}","issue_comment_url":"https://api.github.com/repos/timxzl/finagle/issues/comments{/number}","contents_url":"https://api.github.com/repos/timxzl/finagle/contents/{+path}","compare_url":"https://api.github.com/repos/timxzl/finagle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/timxzl/finagle/merges","archive_url":"https://api.github.com/repos/timxzl/finagle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/timxzl/finagle/downloads","issues_url":"https://api.github.com/repos/timxzl/finagle/issues{/number}","pulls_url":"https://api.github.com/repos/timxzl/finagle/pulls{/number}","milestones_url":"https://api.github.com/repos/timxzl/finagle/milestones{/number}","notifications_url":"https://api.github.com/repos/timxzl/finagle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/timxzl/finagle/labels{/name}","releases_url":"https://api.github.com/repos/timxzl/finagle/releases{/id}","created_at":"2015-05-13T16:06:06Z","updated_at":"2015-05-13T16:06:09Z","pushed_at":"2015-05-14T05:13:58Z","git_url":"git://github.com/timxzl/finagle.git","ssh_url":"git@github.com:timxzl/finagle.git","clone_url":"https://github.com/timxzl/finagle.git","svn_url":"https://github.com/timxzl/finagle","homepage":"http://twitter.github.io/finagle","size":28297,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"twitter:master","ref":"master","sha":"78909170b7cc97044481274e297805d770465110","user":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=3","gravatar_id":"","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"repo":{"id":1007362,"name":"finagle","full_name":"twitter/finagle","owner":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=3","gravatar_id":"","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twitter/finagle","description":"A fault tolerant, protocol-agnostic RPC system","fork":false,"url":"https://api.github.com/repos/twitter/finagle","forks_url":"https://api.github.com/repos/twitter/finagle/forks","keys_url":"https://api.github.com/repos/twitter/finagle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twitter/finagle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twitter/finagle/teams","hooks_url":"https://api.github.com/repos/twitter/finagle/hooks","issue_events_url":"https://api.github.com/repos/twitter/finagle/issues/events{/number}","events_url":"https://api.github.com/repos/twitter/finagle/events","assignees_url":"https://api.github.com/repos/twitter/finagle/assignees{/user}","branches_url":"https://api.github.com/repos/twitter/finagle/branches{/branch}","tags_url":"https://api.github.com/repos/twitter/finagle/tags","blobs_url":"https://api.github.com/repos/twitter/finagle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twitter/finagle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twitter/finagle/git/refs{/sha}","trees_url":"https://api.github.com/repos/twitter/finagle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twitter/finagle/statuses/{sha}","languages_url":"https://api.github.com/repos/twitter/finagle/languages","stargazers_url":"https://api.github.com/repos/twitter/finagle/stargazers","contributors_url":"https://api.github.com/repos/twitter/finagle/contributors","subscribers_url":"https://api.github.com/repos/twitter/finagle/subscribers","subscription_url":"https://api.github.com/repos/twitter/finagle/subscription","commits_url":"https://api.github.com/repos/twitter/finagle/commits{/sha}","git_commits_url":"https://api.github.com/repos/twitter/finagle/git/commits{/sha}","comments_url":"https://api.github.com/repos/twitter/finagle/comments{/number}","issue_comment_url":"https://api.github.com/repos/twitter/finagle/issues/comments{/number}","contents_url":"https://api.github.com/repos/twitter/finagle/contents/{+path}","compare_url":"https://api.github.com/repos/twitter/finagle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twitter/finagle/merges","archive_url":"https://api.github.com/repos/twitter/finagle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twitter/finagle/downloads","issues_url":"https://api.github.com/repos/twitter/finagle/issues{/number}","pulls_url":"https://api.github.com/repos/twitter/finagle/pulls{/number}","milestones_url":"https://api.github.com/repos/twitter/finagle/milestones{/number}","notifications_url":"https://api.github.com/repos/twitter/finagle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twitter/finagle/labels{/name}","releases_url":"https://api.github.com/repos/twitter/finagle/releases{/id}","created_at":"2010-10-19T22:10:09Z","updated_at":"2015-05-16T05:58:28Z","pushed_at":"2015-05-14T05:14:00Z","git_url":"git://github.com/twitter/finagle.git","ssh_url":"git@github.com:twitter/finagle.git","clone_url":"https://github.com/twitter/finagle.git","svn_url":"https://github.com/twitter/finagle","homepage":"http://twitter.github.io/finagle","size":36345,"stargazers_count":3438,"watchers_count":3438,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":652,"mirror_url":null,"open_issues_count":47,"forks":652,"open_issues":47,"watchers":3438,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/twitter/finagle/pulls/381"},"html":{"href":"https://github.com/twitter/finagle/pull/381"},"issue":{"href":"https://api.github.com/repos/twitter/finagle/issues/381"},"comments":{"href":"https://api.github.com/repos/twitter/finagle/issues/381/comments"},"review_comments":{"href":"https://api.github.com/repos/twitter/finagle/pulls/381/comments"},"review_comment":{"href":"https://api.github.com/repos/twitter/finagle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/twitter/finagle/pulls/381/commits"},"statuses":{"href":"https://api.github.com/repos/twitter/finagle/statuses/1d36bd1b797351b98cca20ec34e808963195d120"}}}}