如何在以下程序中正确使用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;
}
}
);
}
答案 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}}