StringRedisTemplate如何使用redis zcard方法?

时间:2014-03-18 01:16:50

标签: java redis spring-data

如何在以下程序中正确使用StringRedisTemplate方法?

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;
        }

     }
    );
}

1 个答案:

答案 0 :(得分:1)

您可以zCard(key) RedisConnection以这样的方式致电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(); } });

{{1}}