redis-server.exe:服務端 html
原來是5個exe文件,差點不會數數了。java
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")); /* * 一些其餘方法:一、修改鍵名:jedis.rename("key6", "key0"); * 二、將當前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("=============改============="); // 一、直接覆蓋原來的數據 pn("直接覆蓋key001原來的數據:" + jedis.set("key001", "value001-update")); pn("獲取key001對應的新值:" + jedis.get("key001")); // 二、直接覆蓋原來的數據 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結合的mysql
<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.propertiesweb
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
redis
pom.xmlspring
<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>補充說明:我在秒針工做的時候,有2個項目都用了Hprose,來作序列化。 所以,我本身的代碼中,也用了Hprose,須要的網上下載哦。 各類參考資料: 百度知道:java web開發緩存方案,ehcache和redis哪一個更好 http://zhidao.baidu.com/link?url=v9i98VamdEEv-qvhXZ875qpAeLlk6Y1jLeeUjUa8RqH2OK8LLxKCfsdPMuVzLZHaJSacvOGnxJF6P3Ve9e0uYCCfniI7XzSdHyfuK7uEUKq 百度百科Redis:http://baike.baidu.com/link?url=t3DT1YANTECL0iYZ0y40otALPMqaPjgTkZV7CXyKhm9eMNZS5p3E2u4N7sbnbuHKixrmxFY9ZXS2QAlALsYcCq java對redis的基本操做 http://www.cnblogs.com/edisonfeng/p/3571870.html#undefined java之redis篇(spring-data-redis整合) http://www.cnblogs.com/tankaixiong/p/3660075.html 官方網站:http://redis.io/