001package gu.dtalk.redis; 002 003import java.net.URI; 004 005/** 006 * redis服务器参数SPI(Service Provider Interface)读写接口 007 * {@link #getHost()}和{@link #getURI()}不可同时为{@code null},否则视为无效实例被忽略 008 * @author guyadong 009 * 010 */ 011public interface RedisConfigProvider { 012 /** 013 * @return 返回redis主机名,当{@link #getURI()}返回{@code null}时,不可为{@code null}, 014 * 否则视为无效,实例被忽略 015 */ 016 String getHost(); 017 /** 018 * 保存redis主机名 019 * @param host 主机名 020 */ 021 void setHost(String host); 022 /** 023 * 024 * @return 返回redis端口号,{@code <=0}使用默认redis端口6379 025 */ 026 int getPort(); 027 /** 028 * 保存redis端口号 029 * @param port 端口号 030 */ 031 void setPort(int port); 032 /** 033 * 034 * @return 返回redis连接密码,为{@code null}使用默认密码 035 */ 036 String getPassword(); 037 /** 038 * 保存redis连接密码 039 * @param password 密码 040 */ 041 void setPassword(String password); 042 /** 043 * 044 * @return 返回redis数据库id,{@code <=0}使用默认id(0) 045 */ 046 int getDatabase(); 047 /** 048 * 保存redis数据库id 049 * @param database 数据库索引号 050 */ 051 void setDatabase(int database); 052 /** 053 * 054 * @return 返回redis超时连接参数(毫秒),{@code <=0}使用默认值 055 */ 056 int getTimeout(); 057 /** 058 * 保存redis超时连接参数 059 * @param timeout 超时时间(毫秒) 060 */ 061 void setTimeout(int timeout); 062 /** 063 * 以{@link URI}对象返回连接redis数据库所需要的host/port/password/database参数, 064 * 此方法不为{@code null}时,忽略{@link #getHost()},{@link #getPort()},{@link #getPassword()},{@link #getDatabase()}方法返回的参数 065 * @return {@link URI}对象 066 */ 067 URI getURI(); 068 /** 069 * 以{@link URI}对象保存接redis数据库所需要的host/port/password/database参数, 070 * @param uri {@link URI}对象 071 */ 072 void setURI(URI uri); 073 /** 074 * 返回当前配置的连接类型,不可为{@code null} 075 * @return 连接类型 076 */ 077 RedisConfigType type(); 078}