scala-redis icon indicating copy to clipboard operation
scala-redis copied to clipboard

Unable to assign file as a value to a key and check size/length of any value

Open jubins opened this issue 5 years ago • 1 comments

I am trying to do two things:

  1. Simple set operations, where I want to set key and value as a text file. For example my key:A100 and its value:A100.obj or A100.txt.
  2. Get that value from redis server and check size of the value. Below is my code (basically I am trying to use redis as a simple database where my files are associated with unique keys and I could access them using the get method).
CODE:

    val host = "localhost"
    val port = 6379
    val file = "A100.obj"

    var key1 = "A100"
    val value1 = file //seems this is taking the filename as string (not the file itself)

    try {
      var r = new RedisClient(host, port)
      r.set(key1, value1)
      println(r.get(key1))
      println(r.strlen(key1))
    }catch{
      case err: Exception => println("Exception: ", err)
    }
OUTPUT:
   Some(A100.obj)
   Some(8)

Any help on this is appreciated and let me know if I could provide any additional information for this. Thank you.

jubins avatar Sep 13 '18 21:09 jubins

I am not sure I understand what you are trying to do here. When u do val value1 = file do you expect to assign the contents of the file to value1. This is not going to happen.

debasishg avatar Sep 15 '18 12:09 debasishg