2018\7\7 星期六 18:08:52 ZSW 2018\7\7 星期六 18:08:52 package com.cityWifi.util; import java.util.Iterator; import java.util.Set; import java.util.UUID; import org.apache.commons.dbcp.AbandonedObjectPool; import org.mybatis.generator.codegen.ibatis2.sqlmap.elements.SelectByPrimaryKeyElementGenerator; import com.cityWifi.model.AdvertisingMac; import com.jspsmart.upload.File; import com.sun.org .apache.bcel.internal.generic.Select; import redis.clients.jedis.Jedis; public class RedisUtil { private static RedisUtil r = new RedisUtil(); private static final Jedis jedis = new Jedis("127.0.0.1",6379); private RedisUtil() { // TODO Auto-generated constructor stub } public static RedisUtil getRedisUtilInstance() { return r; } //查询所有数据 public String selectAll() { StringBuilder sBuilder = new StringBuilder(); Set<String> set = jedis.keys("*"); Iterator it = set.iterator(); while(it.hasNext()) { String s = (String) it.next(); sBuilder.append("||").append(jedis.get(s)); } return sBuilder.toString(); } //查询特定数据 public String SelectByPrimaryKey(String key) { return jedis.get(key); } //删除特定数据 1=success 0=fail public Long deleteByPrimaryKey(String key) { return jedis.del(key); } //删除所有数据 public Long deleteAll() { Set<String> set = jedis.keys("*"); Iterator it = set.iterator(); while(it.hasNext()) { String string = (String) it.next(); deleteByPrimaryKey(string); } return null; } //增加数据 public void AddObject(String key,String value) { jedis.set(key, value); } public static String getKey() { return UUID.randomUUID().toString(); } }