debasishg / scala-redis

A scala library for connecting to a redis server, or a cluster of redis nodes using consistent hashing on the client side.
1.02k stars 219 forks source link

Exception in thread "main" java.lang.Exception: Protocol error: Got (:,[B@1189dd52) as initial reply byte #213

Closed shivam-880 closed 5 years ago

shivam-880 commented 6 years ago

Redis Data

I have a redis key content with following data:

127.0.0.1:6379> lrange content 0 -1
1) "{\"source\": \"output1.txt\", \"col1\": \"water_pressure\", \"col2\": \"sunday\", \"col3\": \"december\"}"
2) "{\"source\": \"output1.txt\", \"col1\": \"air_pressure\", \"col2\": \"saturday\", \"col3\": \"november\"}"
3) "{\"source\": \"output2.txt\", \"col1\": \"voltage\", \"col2\": \"saturday\", \"col3\": \"october\"}"

Executing script

When I execute the lua script testsc.lua I get appropriate response as below: redis-cli --eval testsc.lua "content" returns (integer) 1

Utilising scala-redis

But executing StudioRedis.scala returns following exception:

Exception in thread "main" java.lang.Exception: Protocol error: Got (:,[B@1189dd52) as initial reply byte
    at com.redis.Reply$$anonfun$8.applyOrElse(RedisProtocol.scala:120)

Can anyone please explain where am I getting wrong here? Also could someone please point me to the API documentation or WIKI for this project?

Versions

scala-redis: latest

redis-server --version
Redis server v=3.2.6 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=af85f436129f4de0

redis-cli --version
redis-cli 3.2.6

StudioRedis.scala

import com.redis.RedisClient

object StudioRedis extends App {
  val luaCode = """
            if redis.call("EXISTS", KEYS[1]) == 1 then
              local res = {}

              local payload = redis.call("lrange", KEYS[1], 0, -1)
              local row = cjson.decode(payload[1])
              res[1] = row["source"]

              return #res
            else
              return -1
            end
            """

  val r = new RedisClient("localhost", 6379)

  val res = r.evalBulk(luaCode, List("content"), List())
  print(res)

  r.disconnect
}

testsc.lua

if redis.call("EXISTS", KEYS[1]) == 1 then
    local res = {}

    local payload = redis.call("lrange", KEYS[1], 0, -1)
    local row = cjson.decode(payload[1])
    res[1] = row["source"]

    return #res
else
    return -1
end
debasishg commented 6 years ago

Thanks for reporting. I will take a look soon .. In the lua code that u posted, could u identify the offending statement that causes this exception ?

shivam-880 commented 6 years ago

Lua code isn't throwing any exception. It is this statement from scala code that is causing exception: val res = r.evalBulk(luaCode, List("content"), List())

debasishg commented 6 years ago

Have been awfully busy since the last couple of weeks, which is likely to continue for a couple of weeks more. Has there been any further development on this ? Anyone want to take a shot ?

debasishg commented 6 years ago

Can u please check https://github.com/debasishg/scala-redis/pull/215 ? Looks like I have a fix for it ..

debasishg commented 6 years ago

@codingkapoor - ping ..

bogdanteutsky commented 6 years ago

Hi there. When is the fix for this getting released? It really bites us...

debasishg commented 6 years ago

I was waiting for @codingkapoor on verification of the fix .. I will merge it to master and release soon ..

bogdanteutsky commented 6 years ago

Thanks @debasishg. I noticed there are some merge conflicts, maybe you want to take a look on those. @codingkapoor, do these changes look ok to you?