Search code examples
scalaredis-streams

How can I go around an ambigous reference to overloaded definition error in Scala


I am getting the error ambiguous reference to overloaded definition. My code looks like this

    override def process(record: Row) = {
    var asset = record.getString(0);
    var count = record.getLong(1);
    if(jedis == null){
        connect()
    }

    jedis.hset("click:"+asset, "asset", asset)
    jedis.hset("click:"+asset, "count", count.toString)
    jedis.expire("click:"+asset, 300)
}

and the error is from the line jedis.expire("click:"+asset, 300). anyone knows how I can go around this error


Solution

  • I'm guessing jedis is from https://www.javadoc.io/doc/redis.clients/jedis/latest/redis/clients/jedis/Jedis.html

    That class has four expire method overloads:

    long expire(byte[] key, long seconds)
    long expire(byte[] key, long seconds, ExpiryOption expiryOption) 
    long expire(java.lang.String key, long seconds)
    long expire(java.lang.String key, long seconds, ExpiryOption expiryOption)
    

    It looks like you're trying to pass a String and an Int; the closest method signature expects a long as the second argument, so try this:

    jedis.expire("click:"+asset, 300L)
    

    Note the L on the number literal tells the compiler you want a Long instead of an Int.