Question

How would I properly use the StringRedisTemplate method in this following program?

public void put(StringRedisTemplate template, final Object key, final Object value ) {
    template.execute(new RedisCallback<Object>() {
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
             connection.zCard((byte[]) key);

             connection.exec();
             return null;
        }

     }
    );
}
Was it helpful?

Solution

You can call zCard(key) on RedisConnection somehow like this:

Long zCard = template.execute(new RedisCallback<Long>() {

  @Override
  public Long doInRedis(RedisConnection connection) throws DataAccessException {
    return connection.zCard(potentiallyExtractBytes(key));
  }

  private byte[] potentiallyExtractBytes(Object key) {
    return (key instanceof byte[]) ? (byte[]) key : key.toString().getBytes();
  }

}); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top