项目修炼之路(4)aop+注解的自动缓存

来源:互联网 发布:组织胚胎学试题软件 编辑:程序博客网 时间:2024/05/12 08:19

        在项目中,使用缓存的方式有很多种,一般我们会封装出一个工具类以供使用,但是这样对代码的侵入性还是太强,在这里给大家介绍一种,使用自定义注解自动缓存内容,降低缓存与逻辑代码的耦合性,也省去了大家封装的时间,注意:key生成策略为(标识字符+首个参数值)

一,代码实现:

1,自定义注解:

@Target({ElementType.METHOD, ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Inherited@Documentedpublic @interface Cacheable {    String value();    String key() default "";    int expireSeconds() default 0;}

2,aop代码:

public class CacheInterceptor implements MethodInterceptor {    private final ExpressionEvaluator evaluator = new ExpressionEvaluator();    public CacheInterceptor() {    }    private Object generateKey(String key, MethodInvocation invocation) {        return "".equals(key)?(null != invocation.getArguments() && invocation.getArguments().length != 0?invocation.getArguments()[0]:""):this.evaluator.key(key, invocation.getMethod(), this.createEvaluationContext(invocation, ExpressionEvaluator.NO_RESULT));    }    private EvaluationContext createEvaluationContext(MethodInvocation invocation, Object result) {        Class targetClass = AopProxyUtils.ultimateTargetClass(invocation.getThis());        if(targetClass == null && invocation.getThis() != null) {            targetClass = invocation.getThis().getClass();        }        return this.evaluator.createEvaluationContext(invocation.getMethod(), invocation.getArguments(), invocation.getThis(), targetClass, result);    }    public Object invoke(MethodInvocation invocation) throws Throwable {        Annotation[] annotations = invocation.getMethod().getAnnotations();        if(null != annotations && annotations.length > 0) {            Cacheable cacheable = (Cacheable)invocation.getMethod().getAnnotation(Cacheable.class);            CacheEvict evict = (CacheEvict)invocation.getMethod().getAnnotation(CacheEvict.class);            if(null == cacheable && null == evict) {                return invocation.proceed();            } else {                Object obj;                Object key;                if(null != cacheable) {                    key = this.generateKey(cacheable.key(), invocation);                    obj = RedisUtils.get(cacheable.value() + key.toString(), invocation.getMethod().getReturnType());                    if(null == obj) {                        obj = invocation.proceed();                        if(null != obj) {                            RedisUtils.set(cacheable.value() + key, obj, cacheable.expireSeconds());                        }                    }                    return obj;                } else if(null != evict) {                    key = this.generateKey(evict.key(), invocation);                    if(evict.beforeInvocation()) {                        RedisUtils.del(evict.value() + key);                    }                    obj = invocation.proceed();                    if(!evict.beforeInvocation()) {                        RedisUtils.del(evict.value() + key);                    }                    if(null != obj && evict.cacheAgain()) {                        RedisUtils.set(evict.value() + key, obj, evict.expireSeconds());                    }                    return obj;                } else {                    return invocation.proceed();                }            }        } else {            return invocation.proceed();        }    }}

3,spring配置:

        具体类实现参看文尾:《附录:redis相关类》

<bean id="redisPoolConfig" class="com.~~.cache.redis.RedisPoolConfig">        <property name="maxActive" value="3024"/>        <property name="maxIdle" value="120"/>        <property name="minIdle" value="10"/>        <property name="maxWait" value="3000"/>        <property name="timeOut" value="30000"/>    </bean>    <bean id="redisDataSource" class="com.el.cache.redis.RedisDataSource">        <constructor-arg index="0" value="192.168.~~.~~"/>        <constructor-arg index="1" value="~~~9"/>        <constructor-arg index="2" value=""/>        <constructor-arg index="3" value=""/>        <constructor-arg index="4" value="12"/>        <constructor-arg index="5" ref="redisPoolConfig"/>    </bean>    <bean id="redisClient" class="com.~~.cache.redis.RedisClient">        <property name="dataSource" ref="redisDataSource"/>    </bean>    <bean class="com.~~.cache.redis.utils.RedisUtils">        <property name="redisClient" ref="redisClient"/>    </bean>    <bean id="cacheInterceptor" class="com.~~.cache.redis.interceptor.CacheInterceptor"/>    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">        <property name="beanNames">            <list>                <value>*Service</value>            </list>        </property>        <property name="interceptorNames">            <list>                <value>cacheInterceptor</value>            </list>        </property>    </bean>

二,具体应用:

public interface IUserAreaFranchiseeService {  <span style="color:#ff6600;"> <span style="background-color: rgb(192, 192, 192);"> @Cacheable(value = RedisKeyUtils.USER_AREA_ID, expireSeconds = RedisKeyUtils.USER_AREA_ID_TIME)</span></span>    public Integer getUserAreaIdByUid(Integer uid);}


总结:

        在程序的道路上,我们发现,我们有很多重复发明轮子的过程,这是个不可或缺的过程,纵观现代工业的发展史,在最初的蒸汽机时代,没有统一的标准,大家各自为政,在巨大利益的诱惑面前,一系列资本涌入,开始打天下,制定标准,最后,一定是“最合适”的企业生存了,映射到现在,不也是一样吗?

       java在制定标准,各种民间资本在各自领域抢占高地,我们重复发明轮子,不是因为轮子不好用,而是因为轮子还没有被简化,当我们制作的轮子足够简单时,就是标准时,这个世界从来不是现有标准,再有产品!而是现有产品,再有标准!或者叫,现有认知,才有标准。所以,要成为制作标准的公司,前几个阶段,是不可或缺的!人的成长,也是一样!


附录:redis相关类:

RedisPoolConfig:

public class RedisPoolConfig extends GenericObjectPoolConfig {    private String user;    private String password;    private int timeOut;    private int maxActive = 8;    private long maxWait = -1L;    public RedisPoolConfig() {        this.setTestWhileIdle(true);        this.setMinEvictableIdleTimeMillis(60000L);        this.setTimeBetweenEvictionRunsMillis(30000L);        this.setNumTestsPerEvictionRun(-1);    }    public int getMaxActive() {        return this.maxActive;    }    public void setMaxActive(int maxActive) {        this.maxActive = maxActive;    }    public long getMaxWait() {        return this.maxWait;    }    public void setMaxWait(long maxWait) {        this.maxWait = maxWait;    }    public String getUser() {        return this.user;    }    public void setUser(String user) {        this.user = user;    }    public String getPassword() {        return this.password;    }    public void setPassword(String password) {        this.password = password;    }    public int getTimeOut() {        return this.timeOut;    }    public void setTimeOut(int timeOut) {        this.timeOut = timeOut;    }}</span>

RedisDataSource:

<span style="font-size:18px;">public class RedisDataSource {    private RedisPoolConfig poolConfig;    private GenericObjectPool pool;    private String host;    private int port;    private String user;    private String password;    private int db;    public RedisDataSource(String host, int port, String user, String password, RedisPoolConfig poolConfig) {        this(host, port, user, password, 0, poolConfig);    }    public RedisDataSource(String host, int port, String user, String password, int db, RedisPoolConfig poolConfig) {        this.host = host;        this.port = port;        this.user = user;        this.password = password;        this.db = db;        this.poolConfig = poolConfig;        this.poolConfig.setPassword(this.password);        this.poolConfig.setUser(this.user);        RedisDataSource.PooledRedisFactory redisFactory = null;        try {            redisFactory = this.createRedisFactory();        } catch (Exception var9) {            throw new JedisConnectionException(var9.getMessage(), var9);        }        this.pool = new GenericObjectPool(redisFactory, this.poolConfig);    }    protected RedisDataSource.PooledRedisFactory createRedisFactory() throws Exception {        RedisDataSource.PooledRedisFactory redisFactory = new RedisDataSource.PooledRedisFactory();        PooledObject redis = null;        try {            redis = redisFactory.makeObject();        } finally {            if(redis != null) {                redisFactory.destroyObject(redis);            }        }        return redisFactory;    }    public void close() {        try {            if(this.pool != null) {                this.pool.close();            }        } catch (RuntimeException var2) {            throw var2;        } catch (Exception var3) {            throw new JedisConnectionException("Cannot close connection pool", var3);        }    }    public PooledRedis getRedis() {        try {            return (PooledRedis)this.pool.borrowObject();        } catch (Exception var2) {            throw new JedisConnectionException("Cannot get a connection", var2);        }    }    public String getHost() {        return this.host;    }    public int getPort() {        return this.port;    }    public class PooledRedisFactory extends BasePooledObjectFactory<PooledRedis> {        public PooledRedisFactory() {        }        public PooledRedis create() throws Exception {            PooledRedis redis = new PooledRedis(RedisDataSource.this.host, RedisDataSource.this.port, RedisDataSource.this.db, RedisDataSource.this.poolConfig.getTimeOut() > 0?RedisDataSource.this.poolConfig.getTimeOut():2000, RedisDataSource.this.user == null?RedisDataSource.this.poolConfig.getUser():RedisDataSource.this.user, RedisDataSource.this.password == null?RedisDataSource.this.poolConfig.getPassword():RedisDataSource.this.password, RedisDataSource.this.pool);            redis.connect();            return redis;        }        public PooledObject wrap(PooledRedis obj) {            return new DefaultPooledObject(obj);        }        public void destroyObject(PooledObject<PooledRedis> p) throws Exception {            PooledRedis jedis = (PooledRedis)p.getObject();            if(jedis.isConnected()) {                try {                    try {                        jedis.quit();                    } catch (Exception var4) {                        ;                    }                    jedis.disconnect();                } catch (Exception var5) {                    ;                }            }        }        public boolean validateObject(PooledObject p) {            try {                PooledRedis e = (PooledRedis)p.getObject();                if(!e.isConnected()) {                    e.connect();                }                return e.isConnected()?e.ping().equals("PONG"):false;            } catch (Exception var3) {                var3.printStackTrace();                return false;            }        }        public void activateObject(PooledObject<PooledRedis> pooledJedis) throws Exception {            BinaryJedis jedis = (BinaryJedis)pooledJedis.getObject();            if(jedis.getDB().longValue() != (long)RedisDataSource.this.db) {                jedis.select(RedisDataSource.this.db);            }        }    }}</span>

RedisClient:

<span style="font-size:18px;">public class RedisClient implements InvocationHandler, IRedisClient {    protected final Log log = LogFactory.getLog(this.getClass());    private RedisDataSource dataSource;    private String namespace = "";    private int retryTimes = 3;    private List<String> excludeMethods = new ArrayList() {        {            this.add("keys");            this.add("flushDB");            this.add("flushAll");        }    };    public RedisClient() {    }    public RedisCommands getRedis() {        return (RedisCommands)Proxy.newProxyInstance(RedisCommands.class.getClassLoader(), new Class[]{RedisCommands.class}, this);    }    public boolean set(Object key, Object value) {        return this.set(key, value, 0);    }    public boolean setIfNot(Object key, Object value) {        return this.setIfNot(key, value, 0);    }    public boolean set(Object key, Object value, int expireSeconds) {        try {            RedisCommands e = this.getRedis();            e.set(ByteSerializer.serializer.serialize(this.namespace + key), ByteSerializer.serializer.serialize(value));            if(expireSeconds > 0) {                e.expire(ByteSerializer.serializer.serialize(this.namespace + key), expireSeconds);            }            return true;        } catch (Exception var5) {            this.log.error("=set=>", var5);            return false;        }    }    public boolean mset(Object[] keys, Object[] values) {        return this.mset(keys, values, 0);    }    public boolean msetIfNot(Object[] keys, Object[] values) {        return this.msetIfNot(keys, values, 0);    }    public boolean mset(Object[] keys, Object[] values, int expireSeconds) {        if(null != keys && values != null) {            try {                final ArrayList e = new ArrayList(keys.length + values.length);                for(int redisCommands = 0; redisCommands < keys.length; ++redisCommands) {                    e.add(ByteSerializer.serializer.serialize(this.namespace + keys[redisCommands]));                    e.add(ByteSerializer.serializer.serialize(this.namespace + values[redisCommands]));                }                RedisCommands var8 = this.getRedis();                var8.nativeExecute(new RetryJedisOperation("mset", this.retryTimes) {                    public void exeJedis(Jedis jedis) {                        jedis.mset((byte[][])e.toArray(new byte[0][0]));                    }                });                if(expireSeconds > 0) {                    for(int i = 0; i < e.size(); i += 2) {                        var8.expire((byte[])e.get(i), expireSeconds);                    }                }                return true;            } catch (Exception var7) {                this.log.error("=mset=>", var7);                return false;            }        } else {            return false;        }    }    public boolean msetIfNot(Object[] keys, Object[] values, int expireSeconds) {        if(null != keys && values != null) {            try {                final ArrayList e = new ArrayList(keys.length + values.length);                for(int redisCommands = 0; redisCommands < keys.length; ++redisCommands) {                    e.add(ByteSerializer.serializer.serialize(this.namespace + keys[redisCommands]));                    e.add(ByteSerializer.serializer.serialize(this.namespace + values[redisCommands]));                }                RedisCommands var8 = this.getRedis();                var8.nativeExecute(new RetryJedisOperation("msetIfNot", this.retryTimes) {                    public void exeJedis(Jedis jedis) {                        jedis.msetnx((byte[][])e.toArray(new byte[0][0]));                    }                });                if(expireSeconds > 0) {                    for(int i = 0; i < e.size(); i += 2) {                        var8.expire((byte[])e.get(i), expireSeconds);                    }                }                return true;            } catch (Exception var7) {                this.log.error("=msetIfNot=>", var7);                return false;            }        } else {            return false;        }    }    public <T> List<T> mget(Object[] keys, final Class<T> clazz) {        try {            if(null == keys) {                return null;            } else {                RedisCommands e = this.getRedis();                final ArrayList list = new ArrayList(keys.length);                Object[] result = keys;                int len$ = keys.length;                for(int i$ = 0; i$ < len$; ++i$) {                    Object key = result[i$];                    list.add(ByteSerializer.serializer.serialize(this.namespace + key));                }                final ArrayList var10 = new ArrayList(list.size());                e.nativeExecute(new RetryJedisOperation("mget", this.retryTimes) {                    public void reset() {                        super.reset();                        var10.clear();                    }                    public void exeJedis(Jedis paramJedis) {                        try {                            List e = paramJedis.mget((byte[][])list.toArray(new byte[0][0]));                            if(!CollectionUtils.isEmpty(e)) {                                Iterator i$ = e.iterator();                                while(i$.hasNext()) {                                    byte[] by = (byte[])i$.next();                                    var10.add(ByteSerializer.serializer.deserialize(by, clazz));                                }                            }                        } catch (JedisDataException var5) {                            this.log.error("=mget=>JedisDataException error:", var5);                            throw var5;                        } catch (Exception var6) {                            this.log.error("=mget=>nativeExecute error:", var6);                        }                    }                });                return var10;            }        } catch (Exception var9) {            this.log.error("=mget=>error;", var9);            return null;        }    }    public boolean hset(Object key, Object field, Object value) {        return this.hset(key, field, value, 0);    }    public boolean hset(Object key, Object field, Object value, int expireSeconds) {        try {            RedisCommands e = this.getRedis();            e.hset(ByteSerializer.serializer.serialize(this.namespace + key), ByteSerializer.serializer.serialize(field), ByteSerializer.serializer.serialize(value));            if(expireSeconds > 0) {                e.expire(ByteSerializer.serializer.serialize(this.namespace + key), expireSeconds);            }            return true;        } catch (Exception var6) {            this.log.error("=set=>", var6);            return false;        }    }    public <T> T hget(Object key, Object field, Class<T> clazz) {        try {            RedisCommands e = this.getRedis();            return ByteSerializer.serializer.deserialize(e.hget(ByteSerializer.serializer.serialize(this.namespace + key), ByteSerializer.serializer.serialize(field)), clazz);        } catch (Exception var5) {            this.log.error("=hget=>", var5);            return null;        }    }    public <T> List<T> hmget(Object key, Object field, Class<T> clazz) {        try {            RedisCommands e = this.getRedis();            List list = e.hmget(ByteSerializer.serializer.serialize(this.namespace + key), new byte[][]{ByteSerializer.serializer.serialize(field)});            if(null != list && !list.isEmpty()) {                ArrayList result = new ArrayList(list.size());                Iterator i$ = list.iterator();                while(i$.hasNext()) {                    byte[] bytes = (byte[])i$.next();                    result.add(ByteSerializer.serializer.deserialize(bytes, clazz));                }                return result;            }        } catch (Exception var9) {            this.log.error("=hmget=>", var9);        }        return new ArrayList(0);    }    public boolean setIfNot(Object key, Object value, int expireSeconds) {        try {            RedisCommands e = this.getRedis();            e.setnx(ByteSerializer.serializer.serialize(this.namespace + key), ByteSerializer.serializer.serialize(value));            if(expireSeconds > 0) {                e.expire(ByteSerializer.serializer.serialize(this.namespace + key), expireSeconds);            }            return true;        } catch (Exception var5) {            this.log.error("=setIfNot=>", var5);            return false;        }    }    public boolean setIfExists(Object key, Object value, int expireSeconds) {        try {            RedisCommands e = this.getRedis();            e.setex(ByteSerializer.serializer.serialize(this.namespace + key), expireSeconds, ByteSerializer.serializer.serialize(value));            return true;        } catch (Exception var5) {            this.log.error("=setIfExists=>", var5);            return false;        }    }    public Long ttl(Object key) {        return this.getExpireTime(key);    }    public Long incr(Object key) {        return this.incr(key, 0);    }    public Long incrBy(Object key, long step) {        return this.incrBy(key, step, 0);    }    public Long incrByIfNot(Object key, long step, long defaultValue) {        return this.incrByIfNot(key, step, defaultValue, 0);    }    public Long incrByIfNot(final Object key, final long step, final long defaultValue, final int expireSeconds) {        final HashSet set = new HashSet(1);        this.getRedis().nativeExecute(new JedisOperation() {            public void call(Jedis paramJedis) {                try {                    Long e = paramJedis.incrBy(ByteSerializer.serializer.serialize(RedisClient.this.namespace + key), step);                    if(null != e && step == e.longValue()) {                        paramJedis.setnx(ByteSerializer.serializer.serialize(RedisClient.this.namespace + key), ByteSerializer.serializer.serialize(Long.valueOf(defaultValue)));                        set.add(Long.valueOf(defaultValue));                    } else {                        set.add(e);                    }                    if(expireSeconds > 0) {                        paramJedis.expire(ByteSerializer.serializer.serialize(RedisClient.this.namespace + key), expireSeconds);                    }                } catch (Exception var3) {                    RedisClient.this.log.error("=incrByIfNot=>", var3);                    set.add(Long.valueOf(defaultValue));                }            }        });        return (Long)set.iterator().next();    }    public Long decr(Object key) {        return this.decr(key, 0);    }    public Long decrBy(Object key, long step) {        return this.decrBy(key, step, 0);    }    public Long getExpireTime(Object key) {        try {            RedisCommands e = this.getRedis();            return e.ttl(ByteSerializer.serializer.serialize(this.namespace + key));        } catch (Exception var3) {            this.log.error("=ttl=>", var3);            return null;        }    }    public Long incr(Object key, int expireSeconds) {        try {            RedisCommands e = this.getRedis();            Long result = e.incr(ByteSerializer.serializer.serialize(this.namespace + key));            if(expireSeconds > 0) {                e.expire(ByteSerializer.serializer.serialize(this.namespace + key), expireSeconds);            }            return result;        } catch (Exception var5) {            this.log.error("=incr=>", var5);            return null;        }    }    public Long incrBy(Object key, long step, int expireSeconds) {        try {            RedisCommands e = this.getRedis();            Long result = e.incrBy(ByteSerializer.serializer.serialize(this.namespace + key), step);            if(expireSeconds > 0) {                e.expire(ByteSerializer.serializer.serialize(this.namespace + key), expireSeconds);            }            return result;        } catch (Exception var7) {            this.log.error("=incr=>", var7);            return null;        }    }    public Long decrBy(Object key, long step, int expireSeconds) {        try {            RedisCommands e = this.getRedis();            Long result = e.decrBy(ByteSerializer.serializer.serialize(this.namespace + key), step);            if(expireSeconds > 0) {                e.expire(ByteSerializer.serializer.serialize(this.namespace + key), expireSeconds);            }            return result;        } catch (Exception var7) {            this.log.error("=incr=>", var7);            return null;        }    }    public Long decr(Object key, int expireSeconds) {        try {            RedisCommands e = this.getRedis();            Long result = e.decr(ByteSerializer.serializer.serialize(this.namespace + key));            if(expireSeconds > 0) {                e.expire(ByteSerializer.serializer.serialize(this.namespace + key), expireSeconds);            }            return result;        } catch (Exception var5) {            this.log.error("=incr=>", var5);            return null;        }    }    public boolean del(Object key) {        try {            RedisCommands e = this.getRedis();            return e.del(ByteSerializer.serializer.serialize(this.namespace + key)).longValue() > 0L;        } catch (Exception var3) {            this.log.error("=del=>", var3);            return false;        }    }    public boolean exists(Object key) {        try {            RedisCommands e = this.getRedis();            return e.exists(ByteSerializer.serializer.serialize(this.namespace + key)).booleanValue();        } catch (Exception var3) {            this.log.error("=exists=>", var3);            return false;        }    }    public <T> T get(Object key, Class<T> clazz) {        try {            RedisCommands e = this.getRedis();            return ByteSerializer.serializer.deserialize(e.get(ByteSerializer.serializer.serialize(this.namespace + key)), clazz);        } catch (Exception var4) {            this.log.error("=get=>", var4);            return null;        }    }    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {        if("close".equals(method.getName())) {            return null;        } else if(args != null && args.length > 0) {            return this.execute(method, args);        } else if("toString()".equals(method.getName())) {            return "no method toString.";        } else {            throw new UnsupportedOperationException(method.getName() + "is not supported.");        }    }    private Object execute(Method method, Object[] args) throws Throwable {        PooledRedis redis = this.dataSource.getRedis();        if("nativeExecute".equals(method.getName())) {            try {                redis.nativeExecute((JedisOperation)args[0]);            } finally {                redis.close();            }            return null;        } else if(this.excludeMethods.contains(method.getName())) {            throw new IllegalAccessException("not supported method=" + method.getName());        } else {            Object e;            try {                e = method.invoke(redis, args);            } catch (InvocationTargetException var13) {                this.log.error("=" + method.getName() + "=>error: key=" + args[0], var13);                throw var13.getCause();            } finally {                redis.close();            }            return e;        }    }    public String getNamespace() {        return this.namespace;    }    public void setNamespace(String namespace) {        this.namespace = namespace;    }    public RedisDataSource getDataSource() {        return this.dataSource;    }    public void setDataSource(RedisDataSource dataSource) {        this.dataSource = dataSource;    }    public List<String> getExcludeMethods() {        return this.excludeMethods;    }    public int getRetryTimes() {        return this.retryTimes;    }    public void setRetryTimes(int retryTimes) {        this.retryTimes = retryTimes;    }    public void setExcludeMethods(List<String> excludeMethods) {        this.excludeMethods = excludeMethods;    }}</span>

RedisUtils:

<span style="font-size:18px;">public class RedisUtils implements ApplicationContextAware {    private static IRedisClient redisClient;    protected static ApplicationContext applicationContext;    public RedisUtils() {    }    public void setRedisClient(IRedisClient redisClient) {        redisClient = redisClient;    }    public static IRedisClient getRedisClient() {        if(null == redisClient) {            Class var0 = RedisUtils.class;            synchronized(RedisUtils.class) {                if(null == redisClient) {                    redisClient = (IRedisClient)applicationContext.getBean("redisClient", IRedisClient.class);                }            }        }        if(null == redisClient) {            throw new RuntimeException("redisClient is null.");        } else {            return redisClient;        }    }    public static RedisCommands getRedis() {        return redisClient.getRedis();    }    public static void nativeExecute(JedisOperation jedis) {        getRedis().nativeExecute(jedis);    }    public static boolean set(Object key, Object value) {        return redisClient.set(key, value);    }    public static boolean mset(Object[] keys, Object[] values) {        return redisClient.mset(keys, values);    }    public static boolean mset(Object[] keys, Object[] values, int expireSeconds) {        return redisClient.mset(keys, values, expireSeconds);    }    public static boolean msetIfNot(Object[] keys, Object[] values) {        return redisClient.msetIfNot(keys, values);    }    public static boolean msetIfNot(Object[] keys, Object[] values, int expireSeconds) {        return redisClient.msetIfNot(keys, values, expireSeconds);    }    public static boolean set(Object key, Object value, int expireSeconds) {        return getRedisClient().set(key, value, expireSeconds);    }    public static boolean setIfNot(Object key, Object value) {        return redisClient.setIfNot(key, value);    }    public static boolean setIfNot(Object key, Object value, int expireSeconds) {        return getRedisClient().setIfNot(key, value, expireSeconds);    }    public static boolean setIfExists(Object key, Object value, int expireSeconds) {        return getRedisClient().setIfExists(key, value, expireSeconds);    }    public static <T> T get(Object key, Class<T> clazz) {        return getRedisClient().get(key, clazz);    }    public static <T> List<T> mget(Object[] key, Class<T> clazz) {        return getRedisClient().mget(key, clazz);    }    public static boolean del(Object key) {        return getRedisClient().del(key);    }    public static boolean exists(Object key) {        return getRedisClient().exists(key);    }    public static Long incr(Object key) {        return getRedisClient().incr(key);    }    public static Long incrBy(Object key, long step) {        return getRedisClient().incrBy(key, step);    }    public static Long incrByIfNot(Object key, long step, long defaultValue) {        return getRedisClient().incrByIfNot(key, step, defaultValue);    }    public static Long incrByIfNot(Object key, long step, long defaultValue, int expireSeconds) {        return getRedisClient().incrByIfNot(key, step, defaultValue, expireSeconds);    }    public static Long decr(Object key) {        return getRedisClient().decr(key);    }    public static Long decrBy(Object key, long step) {        return getRedisClient().decrBy(key, step);    }    public static Long incr(Object key, int expireSeconds) {        return getRedisClient().incr(key, expireSeconds);    }    public static Long incrBy(Object key, long step, int expireSeconds) {        return getRedisClient().incrBy(key, step, expireSeconds);    }    public static Long decrBy(Object key, long step, int expireSeconds) {        return getRedisClient().decrBy(key, step, expireSeconds);    }    public static Long decr(Object key, int expireSeconds) {        return getRedisClient().decr(key, expireSeconds);    }    public static boolean hset(Object key, Object field, Object value) {        return getRedisClient().hset(key, field, value);    }    public static boolean hset(Object key, Object field, Object value, int expireSeconds) {        return getRedisClient().hset(key, field, value, expireSeconds);    }    public static <T> T hget(Object key, Object field, Class<T> clazz) {        return getRedisClient().hget(key, field, clazz);    }    public static <T> List<T> hmget(Object key, Object field, Class<T> clazz) {        return getRedisClient().hmget(key, field, clazz);    }    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {        applicationContext = applicationContext;    }}</span>




0 0