标签:redis maven spring spring-data spring-data-redis
因为别人都在用Redis,所以我不得不用Redis。redis-server.exe:服务端
原来是5个exe文件,差点不会数数了。
package cn.fansunion.redis; import hprose.io.HproseFormatter; import java.io.IOException; import java.util.Locale; import java.util.ResourceBundle; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; //简单的Redis例子,用到了Hprose序列化 public class MyDemo { private static String HOST = "127.0.0.1"; private static int PORT = 6379; private static int MAX_ACTIVE = 20; private static int MAX_IDLE = 5; private static int MAX_WAIT = 1000; private static int TIME_OUT = 2000;// 毫秒 private static boolean TEST_ON_BORROW = true;// 当调用borrow // object方法时,是否进行有效性检查 private static boolean TEST_ON_RETURN = true;// 当调用return object时,是否进行有效性检查 private static JedisPool pool; static { initPool(); } private static void setValueFromBundle() { ResourceBundle bundle = ResourceBundle.getBundle("redis", Locale.getDefault(), MyDemo.class.getClassLoader()); if (bundle == null) { throw new IllegalArgumentException( "[redis.properties] is not found!"); } HOST = bundle.getString("redis.host"); PORT = Integer.parseInt(bundle.getString("redis.port")); MAX_ACTIVE = Integer.valueOf(bundle.getString("redis.maxActive")); MAX_IDLE = Integer.valueOf(bundle.getString("redis.maxIdle")); MAX_WAIT = Integer.valueOf(bundle.getString("redis.maxWait")); TIME_OUT = Integer.valueOf(bundle.getString("redis.timeOut")); TEST_ON_BORROW = Boolean.valueOf(bundle .getString("redis.testOnBorrow")); TEST_ON_RETURN = Boolean.valueOf(bundle .getString("redis.testOnReturn")); } private static void initPool() { JedisPoolConfig config = new JedisPoolConfig(); try { setValueFromBundle(); } catch (Exception e) { System.out.println("redis bundle resource get error"); } config.setMaxActive(MAX_ACTIVE); config.setMaxIdle(MAX_IDLE); config.setMaxIdle(MAX_WAIT); config.setTestOnBorrow(TEST_ON_BORROW); config.setTestOnReturn(TEST_ON_RETURN); pool = new JedisPool(config, HOST, PORT, TIME_OUT); } public static void put(String key, Object value) { Jedis jedis = null; try { jedis = pool.getResource(); jedis.set(key.getBytes(), HproseFormatter.serialize(value) .toByteArray()); } catch (IOException e) { e.printStackTrace(); pool.returnBrokenResource(jedis); } finally { pool.returnResource(jedis); } } public static void delete(String key) { Jedis jedis = null; try { jedis = pool.getResource(); jedis.del(key.getBytes()); } catch (Exception e) { e.printStackTrace(); pool.returnBrokenResource(jedis); } finally { pool.returnResource(jedis); } } public static Object get(String key) { Object result = null; Jedis jedis = null; try { jedis = pool.getResource(); if (key != null) { byte[] bt = jedis.get(key.getBytes()); if (bt != null) { result = HproseFormatter.unserialize(jedis.get(key .getBytes())); } } } catch (IOException e) { e.printStackTrace(); pool.returnBrokenResource(jedis); } finally { pool.returnResource(jedis); } return result; } public static void main(String[] args) { String name = "小雷FansUnion"; String key = "name"; MyDemo.put(key, name); Object nameObject = MyDemo.get(key); if (nameObject != null) { String n = (String) nameObject; System.out.println(n); } MyDemo.delete(key); Object nullObject = MyDemo.get(name); if (nullObject == null) { System.out.println("The name object has been deleted."); } } }
package cn.fansunion.redis; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisShardInfo; import redis.clients.jedis.ShardedJedis; import redis.clients.jedis.ShardedJedisPool; import redis.clients.jedis.SortingParams; //根据网上代码,略微改造的例子 public class RedisClient { private static final int PORT = 6379; private static final String HOST = "127.0.0.1"; private Jedis jedis;// 非切片客户端连接 private JedisPool jedisPool;// 非切片连接池 private ShardedJedis shardedJedis;// 切片额客户端连接 private ShardedJedisPool shardedJedisPool;// 切片连接池 public RedisClient() { initialPool(); initialShardedPool(); shardedJedis = shardedJedisPool.getResource(); jedis = jedisPool.getResource(); } /** * 初始化非切片池 */ private void initialPool() { // 池基本配置 JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(20); config.setMaxIdle(5); config.setMaxWait(1000l); config.setTestOnBorrow(false); jedisPool = new JedisPool(config, HOST, PORT); } /** * 初始化切片池 */ private void initialShardedPool() { // 池基本配置 JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(20); config.setMaxIdle(5); config.setMaxWait(1000l); config.setTestOnBorrow(false); // slave链接 List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); shards.add(new JedisShardInfo(HOST, 6379, "master")); // 构造池 shardedJedisPool = new ShardedJedisPool(config, shards); } public static void main(String[] args) { RedisClient redisClient = new RedisClient(); redisClient.show(); } public void show() { keyOperate(); stringOperate(); listOperate(); setOperate(); sortedSetOperate(); hashOperate(); jedisPool.returnResource(jedis); shardedJedisPool.returnResource(shardedJedis); } private static void pn(Object o){ System.out.println(o); } private static void pn(){ System.out.println(); } private void keyOperate() { pn("======================key=========================="); // 清空数据 pn("清空库中所有数据:" + jedis.flushDB()); // 判断key否存在 pn("判断key999键是否存在:" + shardedJedis.exists("key999")); pn("新增key001,value001键值对:" + shardedJedis.set("key001", "value001")); pn("判断key001是否存在:" + shardedJedis.exists("key001")); // 输出系统中所有的key pn("新增key002,value002键值对:" + shardedJedis.set("key002", "value002")); pn("系统中所有键如下:"); Set<String> keys = jedis.keys("*"); Iterator<String> it = keys.iterator(); while (it.hasNext()) { String key = it.next(); pn(key); } // 删除某个key,若key不存在,则忽略该命令。 pn("系统中删除key002: " + jedis.del("key002")); pn("判断key002是否存在:" + shardedJedis.exists("key002")); // 设置 key001的过期时间 pn("设置 key001的过期时间为5秒:" + jedis.expire("key001", 5)); try { Thread.sleep(2000); } catch (InterruptedException e) { } // 查看某个key的剩余生存时间,单位【秒】.永久生存或者不存在的都返回-1 pn("查看key001的剩余生存时间:" + jedis.ttl("key001")); // 移除某个key的生存时间 pn("移除key001的生存时间:" + jedis.persist("key001")); pn("查看key001的剩余生存时间:" + jedis.ttl("key001")); // 查看key所储存的值的类型 pn("查看key所储存的值的类型:" + jedis.type("key001")); /* * 一些其他方法:1、修改键名:jedis.rename("key6", "key0"); * 2、将当前db的key移动到给定的db当中:jedis.move("foo", 1) */ } private void stringOperate() { System.out .println("======================String_1=========================="); // 清空数据 pn("清空库中所有数据:" + jedis.flushDB()); pn("=============增============="); jedis.set("key001", "value001"); jedis.set("key002", "value002"); jedis.set("key003", "value003"); pn("已新增的3个键值对如下:"); pn(jedis.get("key001")); pn(jedis.get("key002")); pn(jedis.get("key003")); pn("=============删============="); pn("删除key003键值对:" + jedis.del("key003")); pn("获取key003键对应的值:" + jedis.get("key003")); pn("=============改============="); // 1、直接覆盖原来的数据 pn("直接覆盖key001原来的数据:" + jedis.set("key001", "value001-update")); pn("获取key001对应的新值:" + jedis.get("key001")); // 2、直接覆盖原来的数据 pn("在key002原来值后面追加:" + jedis.append("key002", "+appendString")); pn("获取key002对应的新值" + jedis.get("key002")); pn("=============增,删,查(多个)============="); /** * mset,mget同时新增,修改,查询多个键值对 等价于: jedis.set("name","ssss"); * jedis.set("jarorwar","xxxx"); */ pn("一次性新增key201,key202,key203,key204及其对应值:" + jedis.mset("key201", "value201", "key202", "value202", "key203", "value203", "key204", "value204")); pn("一次性获取key201,key202,key203,key204各自对应的值:" + jedis.mget("key201", "key202", "key203", "key204")); pn("一次性删除key201,key202:" + jedis.del(new String[] { "key201", "key202" })); pn("一次性获取key201,key202,key203,key204各自对应的值:" + jedis.mget("key201", "key202", "key203", "key204")); pn(); // jedis具备的功能shardedJedis中也可直接使用,下面测试一些前面没用过的方法 System.out .println("======================String_2=========================="); // 清空数据 pn("清空库中所有数据:" + jedis.flushDB()); pn("=============新增键值对时防止覆盖原先值============="); pn("原先key301不存在时,新增key301:" + shardedJedis.setnx("key301", "value301")); pn("原先key302不存在时,新增key302:" + shardedJedis.setnx("key302", "value302")); pn("当key302存在时,尝试新增key302:" + shardedJedis.setnx("key302", "value302_new")); pn("获取key301对应的值:" + shardedJedis.get("key301")); pn("获取key302对应的值:" + shardedJedis.get("key302")); pn("=============超过有效期键值对被删除============="); // 设置key的有效期,并存储数据 pn("新增key303,并指定过期时间为2秒" + shardedJedis.setex("key303", 2, "key303-2second")); pn("获取key303对应的值:" + shardedJedis.get("key303")); try { Thread.sleep(3000); } catch (InterruptedException e) { } pn("3秒之后,获取key303对应的值:" + shardedJedis.get("key303")); pn("=============获取原值,更新为新值一步完成============="); pn("key302原值:" + shardedJedis.getSet("key302", "value302-after-getset")); pn("key302新值:" + shardedJedis.get("key302")); pn("=============获取子串============="); pn("获取key302对应值中的子串:" + shardedJedis.getrange("key302", 5, 7)); } private void listOperate() { pn("======================list=========================="); // 清空数据 pn("清空库中所有数据:" + jedis.flushDB()); pn("=============增============="); shardedJedis.lpush("stringlists", "vector"); shardedJedis.lpush("stringlists", "ArrayList"); shardedJedis.lpush("stringlists", "vector"); shardedJedis.lpush("stringlists", "vector"); shardedJedis.lpush("stringlists", "LinkedList"); shardedJedis.lpush("stringlists", "MapList"); shardedJedis.lpush("stringlists", "SerialList"); shardedJedis.lpush("stringlists", "HashList"); shardedJedis.lpush("numberlists", "3"); shardedJedis.lpush("numberlists", "1"); shardedJedis.lpush("numberlists", "5"); shardedJedis.lpush("numberlists", "2"); pn("所有元素-stringlists:" + shardedJedis.lrange("stringlists", 0, -1)); pn("所有元素-numberlists:" + shardedJedis.lrange("numberlists", 0, -1)); pn("=============删============="); // 删除列表指定的值 ,第二个参数为删除的个数(有重复时),后add进去的值先被删,类似于出栈 pn("成功删除指定元素个数-stringlists:" + shardedJedis.lrem("stringlists", 2, "vector")); pn("删除指定元素之后-stringlists:" + shardedJedis.lrange("stringlists", 0, -1)); // 删除区间以外的数据 pn("删除下标0-3区间之外的元素:" + shardedJedis.ltrim("stringlists", 0, 3)); pn("删除指定区间之外元素后-stringlists:" + shardedJedis.lrange("stringlists", 0, -1)); // 列表元素出栈 pn("出栈元素:" + shardedJedis.lpop("stringlists")); pn("元素出栈后-stringlists:" + shardedJedis.lrange("stringlists", 0, -1)); pn("=============改============="); // 修改列表中指定下标的值 shardedJedis.lset("stringlists", 0, "hello list!"); pn("下标为0的值修改后-stringlists:" + shardedJedis.lrange("stringlists", 0, -1)); pn("=============查============="); // 数组长度 pn("长度-stringlists:" + shardedJedis.llen("stringlists")); pn("长度-numberlists:" + shardedJedis.llen("numberlists")); // 排序 /* * list中存字符串时必须指定参数为alpha,如果不使用SortingParams,而是直接使用sort("list"), * 会出现"ERR One or more scores can‘t be converted into double" */ SortingParams sortingParameters = new SortingParams(); sortingParameters.alpha(); sortingParameters.limit(0, 3); pn("返回排序后的结果-stringlists:" + shardedJedis.sort("stringlists", sortingParameters)); pn("返回排序后的结果-numberlists:" + shardedJedis.sort("numberlists")); // 子串: start为元素下标,end也为元素下标;-1代表倒数一个元素,-2代表倒数第二个元素 pn("子串-第二个开始到结束:" + shardedJedis.lrange("stringlists", 1, -1)); // 获取列表指定下标的值 pn("获取下标为2的元素:" + shardedJedis.lindex("stringlists", 2) + "\n"); } private void setOperate() { pn("======================set=========================="); // 清空数据 pn("清空库中所有数据:" + jedis.flushDB()); pn("=============增============="); pn("向sets集合中加入元素element001:" + jedis.sadd("sets", "element001")); pn("向sets集合中加入元素element002:" + jedis.sadd("sets", "element002")); pn("向sets集合中加入元素element003:" + jedis.sadd("sets", "element003")); pn("向sets集合中加入元素element004:" + jedis.sadd("sets", "element004")); pn("查看sets集合中的所有元素:" + jedis.smembers("sets")); pn(); pn("=============删============="); pn("集合sets中删除元素element003:" + jedis.srem("sets", "element003")); pn("查看sets集合中的所有元素:" + jedis.smembers("sets")); /* * pn("sets集合中任意位置的元素出栈:"+jedis.spop("sets"));//注: * 出栈元素位置居然不定?--无实际意义 * pn("查看sets集合中的所有元素:"+jedis.smembers("sets")); */ pn(); pn("=============改============="); pn(); pn("=============查============="); pn("判断element001是否在集合sets中:" + jedis.sismember("sets", "element001")); pn("循环查询获取sets中的每个元素:"); Set<String> set = jedis.smembers("sets"); Iterator<String> it = set.iterator(); while (it.hasNext()) { Object obj = it.next(); pn(obj); } pn(); pn("=============集合运算============="); pn("sets1中添加元素element001:" + jedis.sadd("sets1", "element001")); pn("sets1中添加元素element002:" + jedis.sadd("sets1", "element002")); pn("sets1中添加元素element003:" + jedis.sadd("sets1", "element003")); pn("sets1中添加元素element002:" + jedis.sadd("sets2", "element002")); pn("sets1中添加元素element003:" + jedis.sadd("sets2", "element003")); pn("sets1中添加元素element004:" + jedis.sadd("sets2", "element004")); pn("查看sets1集合中的所有元素:" + jedis.smembers("sets1")); pn("查看sets2集合中的所有元素:" + jedis.smembers("sets2")); pn("sets1和sets2交集:" + jedis.sinter("sets1", "sets2")); pn("sets1和sets2并集:" + jedis.sunion("sets1", "sets2")); pn("sets1和sets2差集:" + jedis.sdiff("sets1", "sets2"));// 差集:set1中有,set2中没有的元素 } private void sortedSetOperate() { pn("======================zset=========================="); // 清空数据 pn(jedis.flushDB()); pn("=============增============="); pn("zset中添加元素element001:" + shardedJedis.zadd("zset", 7.0, "element001")); pn("zset中添加元素element002:" + shardedJedis.zadd("zset", 8.0, "element002")); pn("zset中添加元素element003:" + shardedJedis.zadd("zset", 2.0, "element003")); pn("zset中添加元素element004:" + shardedJedis.zadd("zset", 3.0, "element004")); pn("zset集合中的所有元素:" + shardedJedis.zrange("zset", 0, -1));// 按照权重值排序 pn(); pn("=============删============="); pn("zset中删除元素element002:" + shardedJedis.zrem("zset", "element002")); pn("zset集合中的所有元素:" + shardedJedis.zrange("zset", 0, -1)); pn(); pn("=============改============="); pn(); pn("=============查============="); pn("统计zset集合中的元素中个数:" + shardedJedis.zcard("zset")); pn("统计zset集合中权重某个范围内(1.0——5.0),元素的个数:" + shardedJedis.zcount("zset", 1.0, 5.0)); pn("查看zset集合中element004的权重:" + shardedJedis.zscore("zset", "element004")); pn("查看下标1到2范围内的元素值:" + shardedJedis.zrange("zset", 1, 2)); } private void hashOperate() { pn("======================hash=========================="); // 清空数据 pn(jedis.flushDB()); pn("=============增============="); pn("hashs中添加key001和value001键值对:" + shardedJedis.hset("hashs", "key001", "value001")); pn("hashs中添加key002和value002键值对:" + shardedJedis.hset("hashs", "key002", "value002")); pn("hashs中添加key003和value003键值对:" + shardedJedis.hset("hashs", "key003", "value003")); pn("新增key004和4的整型键值对:" + shardedJedis.hincrBy("hashs", "key004", 4l)); pn("hashs中的所有值:" + shardedJedis.hvals("hashs")); pn(); pn("=============删============="); pn("hashs中删除key002键值对:" + shardedJedis.hdel("hashs", "key002")); pn("hashs中的所有值:" + shardedJedis.hvals("hashs")); pn(); pn("=============改============="); pn("key004整型键值的值增加100:" + shardedJedis.hincrBy("hashs", "key004", 100l)); pn("hashs中的所有值:" + shardedJedis.hvals("hashs")); pn(); pn("=============查============="); pn("判断key003是否存在:" + shardedJedis.hexists("hashs", "key003")); pn("获取key004对应的值:" + shardedJedis.hget("hashs", "key004")); pn("批量获取key001和key003对应的值:" + shardedJedis.hmget("hashs", "key001", "key003")); pn("获取hashs中所有的key:" + shardedJedis.hkeys("hashs")); pn("获取hashs中所有的value:" + shardedJedis.hvals("hashs")); pn(); } }
第3个例子,Spring-Data和Redis结合的
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <!-- scanner redis properties --> <context:property-placeholder location="classpath:redis.properties" ignore-unresolvable="true" /> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}" /> <property name="maxActive" value="${redis.maxActive}" /> <property name="maxWait" value="${redis.maxWait}" /> <property name="testOnBorrow" value="${redis.testOnBorrow}" /> </bean> <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:pool-config-ref="poolConfig" /> <bean id="businessConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:pool-config-ref="poolConfig" /> <bean id="loginRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="connectionFactory" /> <!--如果不配置Serializer,那么存储的时候智能使用String,如果用User类型存储,那么会提示错误User can‘t cast to String!!! --> <property name="keySerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" /> </property> <property name="valueSerializer"> <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" /> </property> </bean> <bean id="businessRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="businessConnectionFactory" /> <!--如果不配置Serializer,那么存储的时候智能使用String,如果用User类型存储,那么会提示错误User can‘t cast to String!!! --> <property name="keySerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" /> </property> <property name="valueSerializer"> <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" /> </property> </bean> <bean id="defaultCache" class="cn.fansunion.redis.springdata.RedisClientImpl"> </bean> <bean id="loginCache" class="cn.fansunion.redis.springdata.LoginRedisImpl"> <property name="loginRedisTemplate" ref="loginRedisTemplate" /> </bean> <context:component-scan base-package="cn.fansunion.redis.springdata" /> </beans>
public interface Cache { Map<String, Object> getMulti(List<String> keys); Object[] getMulti(String[] keys); void add(String key, Object value, long timeout); Object getValue(String key); void delete(String key); void delete(Collection<String> keys); Boolean exists(String key); boolean setIfAbsent(String key, Object value, long timeout); void add(String key, Object value); }
package cn.fansunion.redis.springdata; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.StringUtils; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ValueOperations; /** * Redis接口封装 */ public class LoginRedisImpl implements Cache { private RedisTemplate<String, Object> loginRedisTemplate; public RedisTemplate<String, Object> getLoginRedisTemplate() { return loginRedisTemplate; } public void setLoginRedisTemplate( RedisTemplate<String, Object> loginRedisTemplate) { this.loginRedisTemplate = loginRedisTemplate; } public void add(String key, Object value, long timeout) { ValueOperations<String, Object> valueops = loginRedisTemplate .opsForValue(); valueops.set(key, value, timeout, TimeUnit.SECONDS); } public Object getValue(String key) { if(StringUtils.isBlank(key)){ return null; } ValueOperations<String, Object> valueops = loginRedisTemplate .opsForValue(); Object value = valueops.get(key); return value; } public void delete(String key) { if(StringUtils.isBlank(key)){ return; } loginRedisTemplate.delete(key); } /** * 批量删除 */ public void delete(Collection<String> keys) { if(keys==null || keys.size()==0){ return; } loginRedisTemplate.delete(keys); } public Boolean exists(String key) { if(StringUtils.isBlank(key)){ return false; } return loginRedisTemplate.hasKey(key); } @Override public boolean setIfAbsent(String key, Object value, long timeout) { return false; } @Override public Map<String, Object> getMulti(List<String> keys) { return null; } @Override public Object[] getMulti(String[] keys) { ValueOperations<String, Object> valueops = loginRedisTemplate .opsForValue(); List<String> keys_list = Arrays.asList(keys); List<Object> value = valueops.multiGet(keys_list); return value.toArray(); } @Override public void add(String key, Object value) { ValueOperations<String, Object> valueops = loginRedisTemplate .opsForValue(); valueops.set(key, value); } }
package cn.fansunion.redis.springdata; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; //根据自己参与的项目,简化的例子 public class SpringDataRedisDemo { public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext( "classpath:/spring-data-redis.xml"); Cache loginCache = (Cache) ac.getBean("loginCache"); loginCache.add("name", "FansUnion"); Object v = loginCache.getValue("name"); System.out.println(v); } }
redis.properties
redis.pool.maxActive=1024
redis.pool.maxIdle=200
redis.pool.maxWait=1000
redis.pool.testOnBorrow=true
redis.pool.testOnReturn=true
#IP
redis.ip=127.0.0.1
#Port
redis.port=6379
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.fansunion</groupId> <artifactId>redis</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Redis</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.0.2.RELEASE</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.3.2</version> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.1.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.1</version> </dependency> <!-- 将现有的jakarta commons logging的调用转换成lsf4j的调用。 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.6.1</version> </dependency> <!-- Hack:确保commons-logging的jar包不被引入,否则将和jcl-over-slf4j冲突 --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> <scope>provided</scope> </dependency> <!-- slf4j的实现:logback,用来取代log4j。更快、更强! --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>0.9.24</version> <scope>runtime</scope> </dependency> </dependencies> </project>
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:redis maven spring spring-data spring-data-redis
原文地址:http://blog.csdn.net/fansunion/article/details/49278209