团队对封装组件的代码范例

IRedisCache.java 3.3KB

    package com.ai.ipu.cache.redis; import java.util.List; import java.util.Map; import java.util.Set; import com.ai.ipu.cache.ICache; import com.ai.ipu.cache.redis.listener.AbstractPubSubListener; /** * redis缓存接口 */ public interface IRedisCache extends ICache{ /** * 自增 * @param key * @return 自增之后的值 */ public Long incr(String key); /** * 自定义步长自增 * @param key * @param step * @return 增长之后的值 */ public Long incrBy(String key, long step); /** * 设置失效时间 * @param key * @param timeoutSeconds * @return 过期失效时间 */ public Long expire(String key, int timeoutSeconds); /** * 设置失效时间点 * @param key * @param millisSeconds * @return 过期失效时间 */ public Long expireAt(String key, long millisSeconds); /** * 设置数据 * @param key 键 * @param value 值 * @param timeoutSeconds 过期时间 * @return 是否存储成功 * @throws Exception */ public boolean put(Object key, Object value, int timeoutSeconds) throws Exception; /** * 设置map * @param key 键 * @param map 映射 * @return 是否存储成功 */ public boolean putMap(String key, Map<String,String> map); /** * 设置单个key value * @param key 键 * @param element 映射的key * @param value 值 * @return 是否存储成功 */ public boolean putMapElement(String key, String element, String value); /** * 获取map的长度 * @param key 键 * @return 映射的长度 */ public long getMapLens(String key); /** * 获取map中所有的key * @param key 键 * @return 对应映射的键集 */ public Set<String> getMapKeys(String key); /** * 获取map中所有的value * @param key 键 * @return 对应映射的值集 */ public List<String> getMapVals(String key); /** * 获取map中的value * @param key 键 * @param fields 映射的keys * @return 值集 */ public List<String> takeMapVals(String key, String... fields); /** * 删除map中的value * @param key 键 * @param elements 映射的keys * @return 是否删除成功 */ public boolean delMapElement(String key, String... elements); /** * 判断map中的element是否存在 * @param key 键 * @param element 映射的key * @return 是否存在 */ public boolean mapElementExist(String key, String element); /** * 进行资源回收 * @throws Exception */ public void close() throws Exception; /** * publish消息,仅支持发布字符串或字节型数组 * * @param channel * @param message * @return -1:非字符串或字节型数组,发布失败;-2:channel为空,发布失败;-3:message为空,发布失败 * >=0 接收消息的订阅者数量 * @throws Exception */ public Long publish(Object channel, Object message) throws Exception; /** * @param listener * @param channels * @throws Exception */ public void subscribe(AbstractPubSubListener listener, String... channels) throws Exception; }