e-mzungu / rjc

Redis Java Client
Other
26 stars 5 forks source link

java.lang.String cannot be cast to java.lang.Long #14

Open saintamandc opened 13 years ago

saintamandc commented 13 years ago

After recently updating RJC, we get the following issue:

Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long at org.idevlab.rjc.ds.RedisConnectionImpl.getIntegerReply(RedisConnectionImpl.java:162) at org.idevlab.rjc.ds.PoolableRedisConnection.getIntegerReply(PoolableRedisConnection.java:127) at org.idevlab.rjc.RedisClientImpl.getIntegerReply(RedisClientImpl.java:68) at org.idevlab.rjc.RedisSessionImpl.hincrBy(RedisSessionImpl.java:194) at ie.ndrc.sentinel.service.dao.inmemorydb.Dummy.doIncr(Dummy.java:22) at ie.ndrc.sentinel.service.dao.inmemorydb.Dummy.main(Dummy.java:29)

This happens when we are executing hincrBy on redis 2.2.3.

Please find the source below:

import org.idevlab.rjc.Session; import org.idevlab.rjc.SessionFactory; import org.idevlab.rjc.SessionFactoryImpl; import org.idevlab.rjc.ds.PoolableDataSource;

public class Dummy { private SessionFactory sessionFactory; private PoolableDataSource dataSource;

public Dummy(String hostname) {
    dataSource = new PoolableDataSource();
    dataSource.setHost(hostname);
    dataSource.setMaxActive(10);
    sessionFactory = new SessionFactoryImpl(dataSource);
}

public void doIncr() {
    Session session = sessionFactory.create();
    session.multi();
    session.hincrBy("dummy", "count-1", 1);
    session.expire("dummy", 10);
    session.close();
}

public static void main(String args[]) {
    Dummy dummy = new Dummy("localhost");
    dummy.doIncr();
}

}

e-mzungu commented 13 years ago

In version 0.7 interface for working with transactions has been changed. See examples on the wiki page

RedisClient redis = session.multi(); redis.getStatusReply(RedisCommand.INCR, "boo"); session.exec();

System.out.println(session.get("boo")); session.close();

saintamandc commented 13 years ago

Ah, great! Thanks!