001/* 002 * (C) Copyright 2006-2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.nuxeo.ecm.core.redis; 017 018import java.util.List; 019 020import redis.clients.jedis.Jedis; 021import redis.clients.jedis.exceptions.JedisException; 022import redis.clients.util.Pool; 023 024/** 025 * Execute the jedis statement 026 * 027 * @since 6.0 028 */ 029public interface RedisExecutor { 030 031 public static final RedisExecutor NOOP = new RedisAbstractExecutor() { 032 033 @Override 034 public <T> T execute(RedisCallable<T> call) throws JedisException { 035 throw new UnsupportedOperationException("No redis executor available"); 036 } 037 038 @Override 039 public Pool<Jedis> getPool() { 040 throw new UnsupportedOperationException("No pool available"); 041 } 042 043 }; 044 045 /** 046 * Loads the script into Redis. 047 * 048 * @return the script SHA1 049 * @since 8.10 050 */ 051 String scriptLoad(String script) throws JedisException; 052 053 /** 054 * Evaluates the script of the given SHA1 with the given keys and arguments. 055 * <p> 056 * Can reload the script if the Redis instance restarted and the script isn't available anymore. 057 * 058 * @param sha1 the script SHA1 059 * @param keys the keys 060 * @param args the arguments 061 * @return the SHA1 062 * @since 8.10 063 */ 064 Object evalsha(String sha1, List<String> keys, List<String> args) throws JedisException; 065 066 /** 067 * Evaluates the script of the given SHA1 with the given keys and arguments. 068 * <p> 069 * Can reload the script if the Redis instance restarted and the script isn't available anymore. 070 * 071 * @param sha1 the script SHA1 072 * @param keys the keys 073 * @param args the arguments 074 * @return the SHA1 075 * @since 8.10 076 */ 077 Object evalsha(byte[] sha1, List<byte[]> keys, List<byte[]> args) throws JedisException; 078 079 <T> T execute(RedisCallable<T> call) throws JedisException; 080 081 Pool<Jedis> getPool(); 082 083 /** 084 * Start to trace Redis activity only for debug purpose. 085 * @since 8.1 086 */ 087 default void startMonitor() { 088 } 089 090 /** 091 * Stop tracing Redis activity. 092 * @since 8.1 093 */ 094 default void stopMonitor() { 095 } 096 097}