save方法,序列化是自己实现的:
public void save(final K redisKey,final V data){
if(redisKey != null && data != null){
redisTemplate.execute(new RedisCallback<V>() {  
            public V doInRedis(RedisConnection connection) throws DataAccessException {
             byte[] bkey = ObjectTranscoder.serialize(redisKey);
             connection.set(bkey,ObjectTranscoder.serialize(data));
             connection.close();
             return null; 
            }  
        }); 
}
}
incrBy方法:
  public void incr(final K redisKey,final long increValue){
if(redisKey != null){
redisTemplate.execute(new RedisCallback<V>() {  
public V doInRedis(RedisConnection connection) throws DataAccessException {
byte[] bkey = ObjectTranscoder.serialize(redisKey);
connection.incrBy(bkey, increValue);
connection.close();
return null; 
}  
}); 
}
}

解决方案 »

  1.   

    修改了一下,虽然功能是实现了,但是原子性没有了,并发时候会有问题,希望大神解决呀~
    public void incr(final K redisKey,final long increValue){
    if(redisKey != null){
    redisTemplate.execute(new RedisCallback<V>() {  
    public V doInRedis(RedisConnection connection) throws DataAccessException {
    byte[] bkey = ObjectTranscoder.serialize(redisKey);
    Object obj = ObjectTranscoder.deserialize(connection.get(bkey));
    if(obj == null){
    connection.close();
    return null; 
    }
    long value = Long.valueOf(obj.toString()) + increValue;
    long expitedTime = connection.ttl(bkey);
    connection.setEx(bkey,expitedTime,ObjectTranscoder.serialize(value));
    connection.close();
    return null; 
    }  
    }); 
    }
    }谢谢。
      

  2.   

    JedisConnection con = this.jedisConnectionFactory.getConnection();
    con.incr("a:a".getBytes());
    这样试试看