Commit 9fd4759e7d329594bbadc12319f2597ce2ba05f0
1 parent
51694876
1111
Showing
9 changed files
with
2775 additions
and
10 deletions
src/main/java/com/xly/config/JedisUtil.java
0 → 100644
| 1 | +//package com.xly.utils.redis; | |
| 2 | +// | |
| 3 | +//import java.io.ByteArrayInputStream; | |
| 4 | +//import java.io.ByteArrayOutputStream; | |
| 5 | +//import java.io.ObjectInputStream; | |
| 6 | +//import java.io.ObjectOutputStream; | |
| 7 | +//import java.util.*; | |
| 8 | +//import java.util.concurrent.TimeUnit; | |
| 9 | +// | |
| 10 | +//import cn.hutool.core.util.StrUtil; | |
| 11 | +//import cn.hutool.json.JSONUtil; | |
| 12 | +//import com.alibaba.fastjson.JSONObject; | |
| 13 | +//import com.google.common.collect.Sets; | |
| 14 | +//import groovy.util.logging.Slf4j; | |
| 15 | +//import org.slf4j.Logger; | |
| 16 | +//import org.slf4j.LoggerFactory; | |
| 17 | +//import org.springframework.beans.factory.annotation.Autowired; | |
| 18 | +//import org.springframework.beans.factory.annotation.Value; | |
| 19 | +//import org.springframework.cache.annotation.Cacheable; | |
| 20 | +//import org.springframework.stereotype.Component; | |
| 21 | +// | |
| 22 | +//import org.springframework.util.ObjectUtils; | |
| 23 | +//import redis.clients.jedis.*; | |
| 24 | +//import redis.clients.jedis.BinaryClient.LIST_POSITION; | |
| 25 | +// | |
| 26 | +//@Component | |
| 27 | +//@Slf4j | |
| 28 | +//public class JedisUtil { | |
| 29 | +// | |
| 30 | +// private static final Logger logger = LoggerFactory.getLogger(JedisUtil.class); | |
| 31 | +// | |
| 32 | +// private static final String LOCK_SUCCESS = "OK"; | |
| 33 | +// private static final String SET_IF_NOT_EXIST = "NX"; | |
| 34 | +// private static final String SET_WITH_EXPIRE_TIME = "PX"; | |
| 35 | +// private static final String SET_WITH_EXPIRE_TIME_EX = "EX"; | |
| 36 | +// private static final Long RELEASE_SUCCESS = 1L; | |
| 37 | +// public static final int lockWaitTime = 4000; | |
| 38 | +// public static final int scanlimit = 10000; | |
| 39 | +// | |
| 40 | +// @Value("${spring.redis.database}") | |
| 41 | +// private int indexdb; | |
| 42 | +// | |
| 43 | +// @Autowired | |
| 44 | +// private JedisPool jedisPool; | |
| 45 | +// | |
| 46 | +// /** | |
| 47 | +// * <p> | |
| 48 | +// * 通过key获取储存在redis中的value | |
| 49 | +// * </p> | |
| 50 | +// * <p> | |
| 51 | +// * 并释放连接 | |
| 52 | +// * </p> | |
| 53 | +// * | |
| 54 | +// * @param key | |
| 55 | +// * @return 成功返回value 失败返回null | |
| 56 | +// */ | |
| 57 | +// public String get(String key) { | |
| 58 | +// Jedis jedis = null; | |
| 59 | +// String value = null; | |
| 60 | +// try { | |
| 61 | +// jedis = jedisPool.getResource(); | |
| 62 | +// jedis.select(indexdb); | |
| 63 | +// value = jedis.get(key); | |
| 64 | +// } catch (Exception e) { | |
| 65 | +// logger.error(e.getMessage()); | |
| 66 | +// } finally { | |
| 67 | +// returnResource(jedis); | |
| 68 | +// } | |
| 69 | +// return value; | |
| 70 | +// } | |
| 71 | +// /** | |
| 72 | +// * <p> | |
| 73 | +// * 通过key获取储存在redis中的value | |
| 74 | +// * </p> | |
| 75 | +// * <p> | |
| 76 | +// * 并释放连接 | |
| 77 | +// * </p> | |
| 78 | +// * | |
| 79 | +// * @param key | |
| 80 | +// * @return 成功返回value 失败返回null | |
| 81 | +// */ | |
| 82 | +// public Object getObject(String key) { | |
| 83 | +// Jedis jedis = null; | |
| 84 | +// Object value = null; | |
| 85 | +// try { | |
| 86 | +// jedis = jedisPool.getResource(); | |
| 87 | +// jedis.select(indexdb); | |
| 88 | +// String jedV = jedis.get(key); | |
| 89 | +// if(StrUtil.isNotEmpty(jedV) && JSONUtil.isJsonObj(jedV)){ | |
| 90 | +// value = JSONUtil.parseObj(jedV); | |
| 91 | +// }else{ | |
| 92 | +// value = jedV; | |
| 93 | +// } | |
| 94 | +// } catch (Exception e) { | |
| 95 | +// logger.error(e.getMessage()); | |
| 96 | +// } finally { | |
| 97 | +// returnResource(jedis); | |
| 98 | +// } | |
| 99 | +// return value; | |
| 100 | +// } | |
| 101 | +// | |
| 102 | +// /** | |
| 103 | +// * 递增 | |
| 104 | +// * @param key 键 | |
| 105 | +// * @return | |
| 106 | +// */ | |
| 107 | +// public long incr(String key, long delta){ | |
| 108 | +// if(delta<0){ | |
| 109 | +// throw new RuntimeException("递增因子必须大于0"); | |
| 110 | +// } | |
| 111 | +// Jedis jedis = null; | |
| 112 | +// try { | |
| 113 | +// jedis = jedisPool.getResource(); | |
| 114 | +// jedis.select(indexdb); | |
| 115 | +// return jedis.incrBy(key,delta); | |
| 116 | +// } catch (Exception e) { | |
| 117 | +// | |
| 118 | +// logger.error(e.getMessage()); | |
| 119 | +// return 0L; | |
| 120 | +// } finally { | |
| 121 | +// returnResource(jedis); | |
| 122 | +// } | |
| 123 | +// } | |
| 124 | +// | |
| 125 | +// /** | |
| 126 | +// * <p> | |
| 127 | +// * 通过key获取储存在redis中的value | |
| 128 | +// * </p> | |
| 129 | +// * <p> | |
| 130 | +// * 并释放连接 | |
| 131 | +// * </p> | |
| 132 | +// * | |
| 133 | +// * @param key | |
| 134 | +// * @param indexdb 选择redis库 0-15 | |
| 135 | +// * @return 成功返回value 失败返回null | |
| 136 | +// */ | |
| 137 | +// public byte[] get(byte[] key, int indexdb) { | |
| 138 | +// Jedis jedis = null; | |
| 139 | +// byte[] value = null; | |
| 140 | +// try { | |
| 141 | +// jedis = jedisPool.getResource(); | |
| 142 | +// jedis.select(indexdb); | |
| 143 | +// value = jedis.get(key); | |
| 144 | +// } catch (Exception e) { | |
| 145 | +// | |
| 146 | +// logger.error(e.getMessage()); | |
| 147 | +// } finally { | |
| 148 | +// returnResource(jedis); | |
| 149 | +// } | |
| 150 | +// return value; | |
| 151 | +// } | |
| 152 | +// | |
| 153 | +// /** | |
| 154 | +// * <p> | |
| 155 | +// * 向redis存入key和value,并释放连接资源 | |
| 156 | +// * </p> | |
| 157 | +// * <p> | |
| 158 | +// * 如果key已经存在 则覆盖 | |
| 159 | +// * </p> | |
| 160 | +// * | |
| 161 | +// * @param key | |
| 162 | +// * @param value | |
| 163 | +// * @param indexdb 选择redis库 0-15 | |
| 164 | +// * @return 成功 返回OK 失败返回 0 | |
| 165 | +// */ | |
| 166 | +// public String set(String key, String value, int indexdb) { | |
| 167 | +// Jedis jedis = null; | |
| 168 | +// try { | |
| 169 | +// jedis = jedisPool.getResource(); | |
| 170 | +// jedis.select(indexdb); | |
| 171 | +// return jedis.set(key, value); | |
| 172 | +// } catch (Exception e) { | |
| 173 | +// | |
| 174 | +// logger.error(e.getMessage()); | |
| 175 | +// return "0"; | |
| 176 | +// } finally { | |
| 177 | +// returnResource(jedis); | |
| 178 | +// } | |
| 179 | +// } | |
| 180 | +// /** | |
| 181 | +// * <p> | |
| 182 | +// * 向redis存入key和value,并释放连接资源 | |
| 183 | +// * </p> | |
| 184 | +// * <p> | |
| 185 | +// * 如果key已经存在 则覆盖 | |
| 186 | +// * </p> | |
| 187 | +// * | |
| 188 | +// * @param key | |
| 189 | +// * @param value | |
| 190 | +// * @return 成功 返回OK 失败返回 0 | |
| 191 | +// */ | |
| 192 | +// public String set(String key, String value) { | |
| 193 | +// return set( key, value, indexdb); | |
| 194 | +// } | |
| 195 | +// /** | |
| 196 | +// * <p> | |
| 197 | +// * 向redis存入key和value,并释放连接资源 | |
| 198 | +// * </p> | |
| 199 | +// * <p> | |
| 200 | +// * 如果key已经存在 则覆盖 | |
| 201 | +// * </p> | |
| 202 | +// * | |
| 203 | +// * @param key | |
| 204 | +// * @param value | |
| 205 | +// * @return 成功 返回OK 失败返回 0 | |
| 206 | +// */ | |
| 207 | +// public String setObject(String key, Object value) { | |
| 208 | +// Jedis jedis = null; | |
| 209 | +// try { | |
| 210 | +// jedis = jedisPool.getResource(); | |
| 211 | +// jedis.select(indexdb); | |
| 212 | +// String objJson = JSONUtil.toJsonStr(value); | |
| 213 | +// return jedis.set( key,objJson); | |
| 214 | +// } catch (Exception e) { | |
| 215 | +// | |
| 216 | +// logger.error(e.getMessage()); | |
| 217 | +// return "0"; | |
| 218 | +// } finally { | |
| 219 | +// returnResource(jedis); | |
| 220 | +// } | |
| 221 | +// } | |
| 222 | +// | |
| 223 | +// /** | |
| 224 | +// * <p> | |
| 225 | +// * 向redis存入key和value,并释放连接资源 | |
| 226 | +// * </p> | |
| 227 | +// * <p> | |
| 228 | +// * 如果key已经存在 则覆盖 | |
| 229 | +// * </p> | |
| 230 | +// * | |
| 231 | +// * @param key | |
| 232 | +// * @param value | |
| 233 | +// * @param indexdb 选择redis库 0-15 | |
| 234 | +// * @return 成功 返回OK 失败返回 0 | |
| 235 | +// */ | |
| 236 | +// public String set(byte[] key, byte[] value, int indexdb) { | |
| 237 | +// Jedis jedis = null; | |
| 238 | +// try { | |
| 239 | +// jedis = jedisPool.getResource(); | |
| 240 | +// jedis.select(indexdb); | |
| 241 | +// return jedis.set(key, value); | |
| 242 | +// } catch (Exception e) { | |
| 243 | +// | |
| 244 | +// logger.error(e.getMessage()); | |
| 245 | +// return "0"; | |
| 246 | +// } finally { | |
| 247 | +// returnResource(jedis); | |
| 248 | +// } | |
| 249 | +// } | |
| 250 | +// | |
| 251 | +// /** | |
| 252 | +// * <p> | |
| 253 | +// * 删除指定的key,也可以传入一个包含key的数组 | |
| 254 | +// * </p> | |
| 255 | +// * | |
| 256 | +// * @param keys 一个key 也可以使 string 数组 | |
| 257 | +// * @return 返回删除成功的个数 | |
| 258 | +// */ | |
| 259 | +// public Long del(String... keys) { | |
| 260 | +// Jedis jedis = null; | |
| 261 | +// try { | |
| 262 | +// jedis = jedisPool.getResource(); | |
| 263 | +// jedis.select(indexdb); | |
| 264 | +// return jedis.del(keys); | |
| 265 | +// } catch (Exception e) { | |
| 266 | +// | |
| 267 | +// logger.error(e.getMessage()); | |
| 268 | +// return 0L; | |
| 269 | +// } finally { | |
| 270 | +// returnResource(jedis); | |
| 271 | +// } | |
| 272 | +// } | |
| 273 | +// /** | |
| 274 | +// * <p> | |
| 275 | +// * 删除指定的key,也可以传入一个包含key的数组 | |
| 276 | +// * </p> | |
| 277 | +// * | |
| 278 | +// * @param keysSet 一个key 也可以使 string 数组 | |
| 279 | +// * @return 返回删除成功的个数 | |
| 280 | +// */ | |
| 281 | +// public Long delSet(Set<String> keysSet) { | |
| 282 | +// return del(keysSet.toArray(new String[keysSet.size()])); | |
| 283 | +// } | |
| 284 | +// | |
| 285 | +// /** | |
| 286 | +// * <p> | |
| 287 | +// * 删除指定的key,也可以传入一个包含key的数组 | |
| 288 | +// * </p> | |
| 289 | +// * | |
| 290 | +// * @param indexdb 选择redis库 0-15 | |
| 291 | +// * @param keys 一个key 也可以使 string 数组 | |
| 292 | +// * @return 返回删除成功的个数 | |
| 293 | +// */ | |
| 294 | +// public Long del(int indexdb, String... keys) { | |
| 295 | +// Jedis jedis = null; | |
| 296 | +// try { | |
| 297 | +// jedis = jedisPool.getResource(); | |
| 298 | +// jedis.select(indexdb); | |
| 299 | +// return jedis.del(keys); | |
| 300 | +// } catch (Exception e) { | |
| 301 | +// | |
| 302 | +// logger.error(e.getMessage()); | |
| 303 | +// return 0L; | |
| 304 | +// } finally { | |
| 305 | +// returnResource(jedis); | |
| 306 | +// } | |
| 307 | +// } | |
| 308 | +// | |
| 309 | +// /** | |
| 310 | +// * <p> | |
| 311 | +// * 删除指定的key,也可以传入一个包含key的数组 | |
| 312 | +// * </p> | |
| 313 | +// * | |
| 314 | +// * @param indexdb 选择redis库 0-15 | |
| 315 | +// * @param keys 一个key 也可以使 string 数组 | |
| 316 | +// * @return 返回删除成功的个数 | |
| 317 | +// */ | |
| 318 | +// public Long del(int indexdb, byte[]... keys) { | |
| 319 | +// Jedis jedis = null; | |
| 320 | +// try { | |
| 321 | +// jedis = jedisPool.getResource(); | |
| 322 | +// jedis.select(indexdb); | |
| 323 | +// return jedis.del(keys); | |
| 324 | +// } catch (Exception e) { | |
| 325 | +// | |
| 326 | +// logger.error(e.getMessage()); | |
| 327 | +// return 0L; | |
| 328 | +// } finally { | |
| 329 | +// returnResource(jedis); | |
| 330 | +// } | |
| 331 | +// } | |
| 332 | +// | |
| 333 | +// /** | |
| 334 | +// * <p> | |
| 335 | +// * 通过key向指定的value值追加值 | |
| 336 | +// * </p> | |
| 337 | +// * | |
| 338 | +// * @param key | |
| 339 | +// * @param str | |
| 340 | +// * @return 成功返回 添加后value的长度 失败 返回 添加的 value 的长度 异常返回0L | |
| 341 | +// */ | |
| 342 | +// public Long append(String key, String str) { | |
| 343 | +// Jedis jedis = null; | |
| 344 | +// Long res = null; | |
| 345 | +// try { | |
| 346 | +// jedis = jedisPool.getResource(); | |
| 347 | +// jedis.select(indexdb); | |
| 348 | +// res = jedis.append(key, str); | |
| 349 | +// } catch (Exception e) { | |
| 350 | +// logger.error(e.getMessage()); | |
| 351 | +// return 0L; | |
| 352 | +// } finally { | |
| 353 | +// returnResource(jedis); | |
| 354 | +// } | |
| 355 | +// return res; | |
| 356 | +// } | |
| 357 | +// | |
| 358 | +// /** | |
| 359 | +// * <p> | |
| 360 | +// * 判断key是否存在 | |
| 361 | +// * </p> | |
| 362 | +// * | |
| 363 | +// * @param key | |
| 364 | +// * @return true OR false | |
| 365 | +// */ | |
| 366 | +// public Boolean exists(String key) { | |
| 367 | +// Jedis jedis = null; | |
| 368 | +// try { | |
| 369 | +// jedis = jedisPool.getResource(); | |
| 370 | +// jedis.select(indexdb); | |
| 371 | +// return jedis.exists(key); | |
| 372 | +// } catch (Exception e) { | |
| 373 | +// | |
| 374 | +// logger.error(e.getMessage()); | |
| 375 | +// return false; | |
| 376 | +// } finally { | |
| 377 | +// returnResource(jedis); | |
| 378 | +// } | |
| 379 | +// } | |
| 380 | +// | |
| 381 | +// /** | |
| 382 | +// * <p> | |
| 383 | +// * 清空当前数据库中的所有 key,此命令从不失败。 | |
| 384 | +// * </p> | |
| 385 | +// * | |
| 386 | +// * @return 总是返回 OK | |
| 387 | +// */ | |
| 388 | +// public String flushDB() { | |
| 389 | +// Jedis jedis = null; | |
| 390 | +// try { | |
| 391 | +// jedis = jedisPool.getResource(); | |
| 392 | +// jedis.select(indexdb); | |
| 393 | +// return jedis.flushDB(); | |
| 394 | +// } catch (Exception e) { | |
| 395 | +// logger.error(e.getMessage()); | |
| 396 | +// } finally { | |
| 397 | +// returnResource(jedis); | |
| 398 | +// } | |
| 399 | +// return null; | |
| 400 | +// } | |
| 401 | +// | |
| 402 | +// /** | |
| 403 | +// * <p> | |
| 404 | +// * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。 | |
| 405 | +// * </p> | |
| 406 | +// * | |
| 407 | +// * @param key | |
| 408 | +// * @param value 过期时间,单位:秒 | |
| 409 | +// * @return 成功返回1 如果存在 和 发生异常 返回 0 | |
| 410 | +// */ | |
| 411 | +// public Long expire(String key, int value, int indexdb) { | |
| 412 | +// Jedis jedis = null; | |
| 413 | +// try { | |
| 414 | +// jedis = jedisPool.getResource(); | |
| 415 | +// jedis.select(indexdb); | |
| 416 | +// return jedis.expire(key, value); | |
| 417 | +// } catch (Exception e) { | |
| 418 | +// logger.error(e.getMessage()); | |
| 419 | +// return 0L; | |
| 420 | +// } finally { | |
| 421 | +// returnResource(jedis); | |
| 422 | +// } | |
| 423 | +// } | |
| 424 | +// | |
| 425 | +// /** | |
| 426 | +// * 普通缓存放入并设置时间 | |
| 427 | +// * @param key 键 | |
| 428 | +// * @param value 值 | |
| 429 | +// * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 | |
| 430 | +// * @return true成功 false 失败 | |
| 431 | +// */ | |
| 432 | +// public boolean setObjectExpire(String key,Object value,long time){ | |
| 433 | +// String valueJson = JSONUtil.toJsonStr(value); | |
| 434 | +// this.setex( key, new Long(time).intValue(), valueJson); | |
| 435 | +// return true; | |
| 436 | +// } | |
| 437 | +// | |
| 438 | +// /** | |
| 439 | +// * <p> | |
| 440 | +// * 以秒为单位,返回给定 key 的剩余生存时间 | |
| 441 | +// * </p> | |
| 442 | +// * | |
| 443 | +// * @param key | |
| 444 | +// * @return 当 key 不存在时,返回 -2 。当 key 存在但没有设置剩余生存时间时,返回 -1 。否则,以秒为单位,返回 key | |
| 445 | +// * 的剩余生存时间。 发生异常 返回 0 | |
| 446 | +// */ | |
| 447 | +// public Long ttl(String key, int indexdb) { | |
| 448 | +// Jedis jedis = null; | |
| 449 | +// try { | |
| 450 | +// jedis = jedisPool.getResource(); | |
| 451 | +// jedis.select(indexdb); | |
| 452 | +// return jedis.ttl(key); | |
| 453 | +// } catch (Exception e) { | |
| 454 | +// | |
| 455 | +// logger.error(e.getMessage()); | |
| 456 | +// return 0L; | |
| 457 | +// } finally { | |
| 458 | +// returnResource(jedis); | |
| 459 | +// } | |
| 460 | +// } | |
| 461 | +// /** | |
| 462 | +// * 普通缓存放入并设置时间 | |
| 463 | +// * @param key 键 | |
| 464 | +// * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 | |
| 465 | +// * @return true成功 false 失败 | |
| 466 | +// */ | |
| 467 | +// public Long expireSeconds(String key,long time){ | |
| 468 | +// return expire( key, new Long(time).intValue(), indexdb); | |
| 469 | +// } | |
| 470 | +// /** | |
| 471 | +// * 普通缓存放入并设置时间 | |
| 472 | +// * @param key 键 | |
| 473 | +// * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 | |
| 474 | +// * @return true成功 false 失败 | |
| 475 | +// */ | |
| 476 | +// public Long expireMinutes(String key,long time){ | |
| 477 | +// time = time * 60; | |
| 478 | +// return expire( key, new Long(time).intValue(), indexdb); | |
| 479 | +// } | |
| 480 | +// /** | |
| 481 | +// * 普通缓存放入并设置时间 | |
| 482 | +// * @param key 键 | |
| 483 | +// * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 | |
| 484 | +// * @return true成功 false 失败 | |
| 485 | +// */ | |
| 486 | +// public String createAndExpireMinutes(String key,String value,long time){ | |
| 487 | +// return setexMinutes(key,new Long(time).intValue(), value); | |
| 488 | +// } | |
| 489 | +// | |
| 490 | +// /** | |
| 491 | +// * <p> | |
| 492 | +// * 移除给定 key 的生存时间,将这个 key 从『易失的』(带生存时间 key )转换成『持久的』(一个不带生存时间、永不过期的 key ) | |
| 493 | +// * </p> | |
| 494 | +// * | |
| 495 | +// * @param key | |
| 496 | +// * @return 当生存时间移除成功时,返回 1 .如果 key 不存在或 key 没有设置生存时间,返回 0 , 发生异常 返回 -1 | |
| 497 | +// */ | |
| 498 | +// public Long persist(String key) { | |
| 499 | +// Jedis jedis = null; | |
| 500 | +// try { | |
| 501 | +// jedis = jedisPool.getResource(); | |
| 502 | +// jedis.select(indexdb); | |
| 503 | +// return jedis.persist(key); | |
| 504 | +// } catch (Exception e) { | |
| 505 | +// | |
| 506 | +// logger.error(e.getMessage()); | |
| 507 | +// return -1L; | |
| 508 | +// } finally { | |
| 509 | +// returnResource(jedis); | |
| 510 | +// } | |
| 511 | +// } | |
| 512 | +// | |
| 513 | +// /** | |
| 514 | +// * <p> | |
| 515 | +// * 新增key,并将 key 的生存时间 (以秒为单位) | |
| 516 | +// * </p> | |
| 517 | +// * | |
| 518 | +// * @param key | |
| 519 | +// * @param seconds 生存时间 单位:秒 | |
| 520 | +// * @param value | |
| 521 | +// * @return 设置成功时返回 OK 。当 seconds 参数不合法时,返回一个错误。 | |
| 522 | +// */ | |
| 523 | +// public String setex(String key, int seconds, String value) { | |
| 524 | +// Jedis jedis = null; | |
| 525 | +// try { | |
| 526 | +// jedis = jedisPool.getResource(); | |
| 527 | +// jedis.select(indexdb); | |
| 528 | +// return jedis.setex(key, seconds, value); | |
| 529 | +// } catch (Exception e) { | |
| 530 | +// | |
| 531 | +// logger.error(e.getMessage()); | |
| 532 | +// } finally { | |
| 533 | +// returnResource(jedis); | |
| 534 | +// } | |
| 535 | +// return null; | |
| 536 | +// } | |
| 537 | +// /** | |
| 538 | +// * <p> | |
| 539 | +// * 新增key,并将 key 的生存时间 (以秒为单位) | |
| 540 | +// * </p> | |
| 541 | +// * | |
| 542 | +// * @param key | |
| 543 | +// * @param seconds 生存时间 单位:秒 | |
| 544 | +// * @param value | |
| 545 | +// * @return 设置成功时返回 OK 。当 seconds 参数不合法时,返回一个错误。 | |
| 546 | +// */ | |
| 547 | +// public String setexMinutes(String key, int seconds, String value) { | |
| 548 | +// Jedis jedis = null; | |
| 549 | +// try { | |
| 550 | +// jedis = jedisPool.getResource(); | |
| 551 | +// jedis.select(indexdb); | |
| 552 | +// seconds = seconds*60; | |
| 553 | +// return jedis.setex(key, seconds, value); | |
| 554 | +// } catch (Exception e) { | |
| 555 | +// logger.error(e.getMessage()); | |
| 556 | +// } finally { | |
| 557 | +// returnResource(jedis); | |
| 558 | +// } | |
| 559 | +// return null; | |
| 560 | +// } | |
| 561 | +// | |
| 562 | +// /** | |
| 563 | +// * <p> | |
| 564 | +// * 设置key value,如果key已经存在则返回0,nx==> not exist | |
| 565 | +// * </p> | |
| 566 | +// * | |
| 567 | +// * @param key | |
| 568 | +// * @param value | |
| 569 | +// * @return 成功返回1 如果存在 和 发生异常 返回 0 | |
| 570 | +// */ | |
| 571 | +// public Long setnx(String key, String value) { | |
| 572 | +// Jedis jedis = null; | |
| 573 | +// try { | |
| 574 | +// jedis = jedisPool.getResource(); | |
| 575 | +// jedis.select(indexdb); | |
| 576 | +// return jedis.setnx(key, value); | |
| 577 | +// } catch (Exception e) { | |
| 578 | +// | |
| 579 | +// logger.error(e.getMessage()); | |
| 580 | +// return 0L; | |
| 581 | +// } finally { | |
| 582 | +// returnResource(jedis); | |
| 583 | +// } | |
| 584 | +// } | |
| 585 | +// | |
| 586 | +// /** | |
| 587 | +// * <p> | |
| 588 | +// * 将给定 key 的值设为 value ,并返回 key 的旧值(old value)。 | |
| 589 | +// * </p> | |
| 590 | +// * <p> | |
| 591 | +// * 当 key 存在但不是字符串类型时,返回一个错误。 | |
| 592 | +// * </p> | |
| 593 | +// * | |
| 594 | +// * @param key | |
| 595 | +// * @param value | |
| 596 | +// * @return 返回给定 key 的旧值。当 key 没有旧值时,也即是, key 不存在时,返回 nil | |
| 597 | +// */ | |
| 598 | +// public String getSet(String key, String value) { | |
| 599 | +// Jedis jedis = null; | |
| 600 | +// try { | |
| 601 | +// jedis = jedisPool.getResource(); | |
| 602 | +// jedis.select(indexdb); | |
| 603 | +// return jedis.getSet(key, value); | |
| 604 | +// } catch (Exception e) { | |
| 605 | +// | |
| 606 | +// logger.error(e.getMessage()); | |
| 607 | +// } finally { | |
| 608 | +// returnResource(jedis); | |
| 609 | +// } | |
| 610 | +// return null; | |
| 611 | +// } | |
| 612 | +// | |
| 613 | +// /** | |
| 614 | +// * <p> | |
| 615 | +// * 设置key value并制定这个键值的有效期 | |
| 616 | +// * </p> | |
| 617 | +// * | |
| 618 | +// * @param key | |
| 619 | +// * @param value | |
| 620 | +// * @param seconds 单位:秒 | |
| 621 | +// * @return 成功返回OK 失败和异常返回null | |
| 622 | +// */ | |
| 623 | +// public String setex(String key, String value, int seconds) { | |
| 624 | +// Jedis jedis = null; | |
| 625 | +// String res = null; | |
| 626 | +// try { | |
| 627 | +// jedis = jedisPool.getResource(); | |
| 628 | +// jedis.select(indexdb); | |
| 629 | +// res = jedis.setex(key, seconds, value); | |
| 630 | +// } catch (Exception e) { | |
| 631 | +// | |
| 632 | +// logger.error(e.getMessage()); | |
| 633 | +// } finally { | |
| 634 | +// returnResource(jedis); | |
| 635 | +// } | |
| 636 | +// return res; | |
| 637 | +// } | |
| 638 | +// | |
| 639 | +// /** | |
| 640 | +// * <p> | |
| 641 | +// * 通过key 和offset 从指定的位置开始将原先value替换 | |
| 642 | +// * </p> | |
| 643 | +// * <p> | |
| 644 | +// * 下标从0开始,offset表示从offset下标开始替换 | |
| 645 | +// * </p> | |
| 646 | +// * <p> | |
| 647 | +// * 如果替换的字符串长度过小则会这样 | |
| 648 | +// * </p> | |
| 649 | +// * <p> | |
| 650 | +// * example: | |
| 651 | +// * </p> | |
| 652 | +// * <p> | |
| 653 | +// * value : bigsea@zto.cn | |
| 654 | +// * </p> | |
| 655 | +// * <p> | |
| 656 | +// * str : abc | |
| 657 | +// * </p> | |
| 658 | +// * <P> | |
| 659 | +// * 从下标7开始替换 则结果为 | |
| 660 | +// * </p> | |
| 661 | +// * <p> | |
| 662 | +// * RES : bigsea.abc.cn | |
| 663 | +// * </p> | |
| 664 | +// * | |
| 665 | +// * @param key | |
| 666 | +// * @param str | |
| 667 | +// * @param offset 下标位置 | |
| 668 | +// * @return 返回替换后 value 的长度 | |
| 669 | +// */ | |
| 670 | +// public Long setrange(String key, String str, int offset) { | |
| 671 | +// Jedis jedis = null; | |
| 672 | +// try { | |
| 673 | +// jedis = jedisPool.getResource(); | |
| 674 | +// jedis.select(indexdb); | |
| 675 | +// return jedis.setrange(key, offset, str); | |
| 676 | +// } catch (Exception e) { | |
| 677 | +// | |
| 678 | +// logger.error(e.getMessage()); | |
| 679 | +// return 0L; | |
| 680 | +// } finally { | |
| 681 | +// returnResource(jedis); | |
| 682 | +// } | |
| 683 | +// } | |
| 684 | +// | |
| 685 | +// /** | |
| 686 | +// * <p> | |
| 687 | +// * 通过批量的key获取批量的value | |
| 688 | +// * </p> | |
| 689 | +// * | |
| 690 | +// * @param keys string数组 也可以是一个key | |
| 691 | +// * @return 成功返回value的集合, 失败返回null的集合 ,异常返回空 | |
| 692 | +// */ | |
| 693 | +// public List<String> mget(String... keys) { | |
| 694 | +// Jedis jedis = null; | |
| 695 | +// List<String> values = null; | |
| 696 | +// try { | |
| 697 | +// jedis = jedisPool.getResource(); | |
| 698 | +// jedis.select(indexdb); | |
| 699 | +// values = jedis.mget(keys); | |
| 700 | +// } catch (Exception e) { | |
| 701 | +// | |
| 702 | +// logger.error(e.getMessage()); | |
| 703 | +// } finally { | |
| 704 | +// returnResource(jedis); | |
| 705 | +// } | |
| 706 | +// return values; | |
| 707 | +// } | |
| 708 | +// | |
| 709 | +// /** | |
| 710 | +// * <p> | |
| 711 | +// * 批量的设置key:value,可以一个 | |
| 712 | +// * </p> | |
| 713 | +// * <p> | |
| 714 | +// * example: | |
| 715 | +// * </p> | |
| 716 | +// * <p> | |
| 717 | +// * obj.mset(new String[]{"key2","value1","key2","value2"}) | |
| 718 | +// * </p> | |
| 719 | +// * | |
| 720 | +// * @param keysvalues | |
| 721 | +// * @return 成功返回OK 失败 异常 返回 null | |
| 722 | +// */ | |
| 723 | +// public String mset(String... keysvalues) { | |
| 724 | +// Jedis jedis = null; | |
| 725 | +// String res = null; | |
| 726 | +// try { | |
| 727 | +// jedis = jedisPool.getResource(); | |
| 728 | +// jedis.select(indexdb); | |
| 729 | +// res = jedis.mset(keysvalues); | |
| 730 | +// } catch (Exception e) { | |
| 731 | +// | |
| 732 | +// logger.error(e.getMessage()); | |
| 733 | +// } finally { | |
| 734 | +// returnResource(jedis); | |
| 735 | +// } | |
| 736 | +// return res; | |
| 737 | +// } | |
| 738 | +// | |
| 739 | +// /** | |
| 740 | +// * <p> | |
| 741 | +// * 批量的设置key:value,可以一个,如果key已经存在则会失败,操作会回滚 | |
| 742 | +// * </p> | |
| 743 | +// * <p> | |
| 744 | +// * example: | |
| 745 | +// * </p> | |
| 746 | +// * <p> | |
| 747 | +// * obj.msetnx(new String[]{"key2","value1","key2","value2"}) | |
| 748 | +// * </p> | |
| 749 | +// * | |
| 750 | +// * @param keysvalues | |
| 751 | +// * @return 成功返回1 失败返回0 | |
| 752 | +// */ | |
| 753 | +// public Long msetnx(String... keysvalues) { | |
| 754 | +// Jedis jedis = null; | |
| 755 | +// Long res = 0L; | |
| 756 | +// try { | |
| 757 | +// jedis = jedisPool.getResource(); | |
| 758 | +// jedis.select(indexdb); | |
| 759 | +// res = jedis.msetnx(keysvalues); | |
| 760 | +// } catch (Exception e) { | |
| 761 | +// | |
| 762 | +// logger.error(e.getMessage()); | |
| 763 | +// } finally { | |
| 764 | +// returnResource(jedis); | |
| 765 | +// } | |
| 766 | +// return res; | |
| 767 | +// } | |
| 768 | +// | |
| 769 | +// /** | |
| 770 | +// * <p> | |
| 771 | +// * 设置key的值,并返回一个旧值 | |
| 772 | +// * </p> | |
| 773 | +// * | |
| 774 | +// * @param key | |
| 775 | +// * @param value | |
| 776 | +// * @return 旧值 如果key不存在 则返回null | |
| 777 | +// */ | |
| 778 | +// public String getset(String key, String value) { | |
| 779 | +// Jedis jedis = null; | |
| 780 | +// String res = null; | |
| 781 | +// try { | |
| 782 | +// jedis = jedisPool.getResource(); | |
| 783 | +// jedis.select(indexdb); | |
| 784 | +// res = jedis.getSet(key, value); | |
| 785 | +// } catch (Exception e) { | |
| 786 | +// | |
| 787 | +// logger.error(e.getMessage()); | |
| 788 | +// } finally { | |
| 789 | +// returnResource(jedis); | |
| 790 | +// } | |
| 791 | +// return res; | |
| 792 | +// } | |
| 793 | +// | |
| 794 | +// /** | |
| 795 | +// * <p> | |
| 796 | +// * 通过下标 和key 获取指定下标位置的 value | |
| 797 | +// * </p> | |
| 798 | +// * | |
| 799 | +// * @param key | |
| 800 | +// * @param startOffset 开始位置 从0 开始 负数表示从右边开始截取 | |
| 801 | +// * @param endOffset | |
| 802 | +// * @return 如果没有返回null | |
| 803 | +// */ | |
| 804 | +// public String getrange(String key, int startOffset, int endOffset) { | |
| 805 | +// Jedis jedis = null; | |
| 806 | +// String res = null; | |
| 807 | +// try { | |
| 808 | +// jedis = jedisPool.getResource(); | |
| 809 | +// jedis.select(indexdb); | |
| 810 | +// res = jedis.getrange(key, startOffset, endOffset); | |
| 811 | +// } catch (Exception e) { | |
| 812 | +// | |
| 813 | +// logger.error(e.getMessage()); | |
| 814 | +// } finally { | |
| 815 | +// returnResource(jedis); | |
| 816 | +// } | |
| 817 | +// return res; | |
| 818 | +// } | |
| 819 | +// | |
| 820 | +// /** | |
| 821 | +// * <p> | |
| 822 | +// * 通过key 对value进行加值+1操作,当value不是int类型时会返回错误,当key不存在是则value为1 | |
| 823 | +// * </p> | |
| 824 | +// * | |
| 825 | +// * @param key | |
| 826 | +// * @return 加值后的结果 | |
| 827 | +// */ | |
| 828 | +// public Long incr(String key) { | |
| 829 | +// Jedis jedis = null; | |
| 830 | +// Long res = null; | |
| 831 | +// try { | |
| 832 | +// jedis = jedisPool.getResource(); | |
| 833 | +// jedis.select(indexdb); | |
| 834 | +// res = jedis.incr(key); | |
| 835 | +// } catch (Exception e) { | |
| 836 | +// | |
| 837 | +// logger.error(e.getMessage()); | |
| 838 | +// } finally { | |
| 839 | +// returnResource(jedis); | |
| 840 | +// } | |
| 841 | +// return res; | |
| 842 | +// } | |
| 843 | +// | |
| 844 | +// /** | |
| 845 | +// * <p> | |
| 846 | +// * 通过key给指定的value加值,如果key不存在,则这是value为该值 | |
| 847 | +// * </p> | |
| 848 | +// * | |
| 849 | +// * @param key | |
| 850 | +// * @param integer | |
| 851 | +// * @return | |
| 852 | +// */ | |
| 853 | +// public Long incrBy(String key, Long integer) { | |
| 854 | +// Jedis jedis = null; | |
| 855 | +// Long res = null; | |
| 856 | +// try { | |
| 857 | +// jedis = jedisPool.getResource(); | |
| 858 | +// jedis.select(indexdb); | |
| 859 | +// res = jedis.incrBy(key, integer); | |
| 860 | +// } catch (Exception e) { | |
| 861 | +// | |
| 862 | +// logger.error(e.getMessage()); | |
| 863 | +// } finally { | |
| 864 | +// returnResource(jedis); | |
| 865 | +// } | |
| 866 | +// return res; | |
| 867 | +// } | |
| 868 | +// | |
| 869 | +// /** | |
| 870 | +// * <p> | |
| 871 | +// * 对key的值做减减操作,如果key不存在,则设置key为-1 | |
| 872 | +// * </p> | |
| 873 | +// * | |
| 874 | +// * @param key | |
| 875 | +// * @return | |
| 876 | +// */ | |
| 877 | +// public Long decr(String key) { | |
| 878 | +// Jedis jedis = null; | |
| 879 | +// Long res = null; | |
| 880 | +// try { | |
| 881 | +// jedis = jedisPool.getResource(); | |
| 882 | +// jedis.select(indexdb); | |
| 883 | +// res = jedis.decr(key); | |
| 884 | +// } catch (Exception e) { | |
| 885 | +// | |
| 886 | +// logger.error(e.getMessage()); | |
| 887 | +// } finally { | |
| 888 | +// returnResource(jedis); | |
| 889 | +// } | |
| 890 | +// return res; | |
| 891 | +// } | |
| 892 | +// | |
| 893 | +// /** | |
| 894 | +// * <p> | |
| 895 | +// * 减去指定的值 | |
| 896 | +// * </p> | |
| 897 | +// * | |
| 898 | +// * @param key | |
| 899 | +// * @param integer | |
| 900 | +// * @return | |
| 901 | +// */ | |
| 902 | +// public Long decrBy(String key, Long integer) { | |
| 903 | +// Jedis jedis = null; | |
| 904 | +// Long res = null; | |
| 905 | +// try { | |
| 906 | +// jedis = jedisPool.getResource(); | |
| 907 | +// jedis.select(indexdb); | |
| 908 | +// res = jedis.decrBy(key, integer); | |
| 909 | +// } catch (Exception e) { | |
| 910 | +// | |
| 911 | +// logger.error(e.getMessage()); | |
| 912 | +// } finally { | |
| 913 | +// returnResource(jedis); | |
| 914 | +// } | |
| 915 | +// return res; | |
| 916 | +// } | |
| 917 | +// | |
| 918 | +// /** | |
| 919 | +// * <p> | |
| 920 | +// * 通过key获取value值的长度 | |
| 921 | +// * </p> | |
| 922 | +// * | |
| 923 | +// * @param key | |
| 924 | +// * @return 失败返回null | |
| 925 | +// */ | |
| 926 | +// public Long serlen(String key) { | |
| 927 | +// Jedis jedis = null; | |
| 928 | +// Long res = null; | |
| 929 | +// try { | |
| 930 | +// jedis = jedisPool.getResource(); | |
| 931 | +// jedis.select(indexdb); | |
| 932 | +// res = jedis.strlen(key); | |
| 933 | +// } catch (Exception e) { | |
| 934 | +// | |
| 935 | +// logger.error(e.getMessage()); | |
| 936 | +// } finally { | |
| 937 | +// returnResource(jedis); | |
| 938 | +// } | |
| 939 | +// return res; | |
| 940 | +// } | |
| 941 | +// | |
| 942 | +// /** | |
| 943 | +// * <p> | |
| 944 | +// * 通过key给field设置指定的值,如果key不存在,则先创建 | |
| 945 | +// * </p> | |
| 946 | +// * | |
| 947 | +// * @param key | |
| 948 | +// * @param field 字段 | |
| 949 | +// * @param value | |
| 950 | +// * @return 如果存在返回0 异常返回null | |
| 951 | +// */ | |
| 952 | +// public Long hset(String key, String field, String value) { | |
| 953 | +// Jedis jedis = null; | |
| 954 | +// Long res = null; | |
| 955 | +// try { | |
| 956 | +// jedis = jedisPool.getResource(); | |
| 957 | +// jedis.select(indexdb); | |
| 958 | +// res = jedis.hset(key, field, value); | |
| 959 | +// } catch (Exception e) { | |
| 960 | +// | |
| 961 | +// logger.error(e.getMessage()); | |
| 962 | +// } finally { | |
| 963 | +// returnResource(jedis); | |
| 964 | +// } | |
| 965 | +// return res; | |
| 966 | +// } | |
| 967 | +// | |
| 968 | +// /** | |
| 969 | +// * <p> | |
| 970 | +// * 通过key给field设置指定的值,如果key不存在则先创建,如果field已经存在,返回0 | |
| 971 | +// * </p> | |
| 972 | +// * | |
| 973 | +// * @param key | |
| 974 | +// * @param field | |
| 975 | +// * @param value | |
| 976 | +// * @return | |
| 977 | +// */ | |
| 978 | +// public Long hsetnx(String key, String field, String value) { | |
| 979 | +// Jedis jedis = null; | |
| 980 | +// Long res = null; | |
| 981 | +// try { | |
| 982 | +// jedis = jedisPool.getResource(); | |
| 983 | +// jedis.select(indexdb); | |
| 984 | +// res = jedis.hsetnx(key, field, value); | |
| 985 | +// } catch (Exception e) { | |
| 986 | +// | |
| 987 | +// logger.error(e.getMessage()); | |
| 988 | +// } finally { | |
| 989 | +// returnResource(jedis); | |
| 990 | +// } | |
| 991 | +// return res; | |
| 992 | +// } | |
| 993 | +// | |
| 994 | +// /** | |
| 995 | +// * <p> | |
| 996 | +// * 通过key同时设置 hash的多个field | |
| 997 | +// * </p> | |
| 998 | +// * | |
| 999 | +// * @param key | |
| 1000 | +// * @param hash | |
| 1001 | +// * @return 返回OK 异常返回null | |
| 1002 | +// */ | |
| 1003 | +// public String hmset(String key, Map<String, String> hash, int indexdb) { | |
| 1004 | +// Jedis jedis = null; | |
| 1005 | +// String res = null; | |
| 1006 | +// try { | |
| 1007 | +// jedis = jedisPool.getResource(); | |
| 1008 | +// jedis.select(indexdb); | |
| 1009 | +// res = jedis.hmset(key, hash); | |
| 1010 | +// } catch (Exception e) { | |
| 1011 | +// | |
| 1012 | +// logger.error(e.getMessage()); | |
| 1013 | +// } finally { | |
| 1014 | +// returnResource(jedis); | |
| 1015 | +// } | |
| 1016 | +// return res; | |
| 1017 | +// } | |
| 1018 | +// | |
| 1019 | +// /** | |
| 1020 | +// * <p> | |
| 1021 | +// * 通过key 和 field 获取指定的 value | |
| 1022 | +// * </p> | |
| 1023 | +// * | |
| 1024 | +// * @param key | |
| 1025 | +// * @param field | |
| 1026 | +// * @return 没有返回null | |
| 1027 | +// */ | |
| 1028 | +// public String hget(String key, String field) { | |
| 1029 | +// Jedis jedis = null; | |
| 1030 | +// String res = null; | |
| 1031 | +// try { | |
| 1032 | +// jedis = jedisPool.getResource(); | |
| 1033 | +// jedis.select(indexdb); | |
| 1034 | +// res = jedis.hget(key, field); | |
| 1035 | +// } catch (Exception e) { | |
| 1036 | +// | |
| 1037 | +// logger.error(e.getMessage()); | |
| 1038 | +// } finally { | |
| 1039 | +// returnResource(jedis); | |
| 1040 | +// } | |
| 1041 | +// return res; | |
| 1042 | +// } | |
| 1043 | +// | |
| 1044 | +// /** | |
| 1045 | +// * <p> | |
| 1046 | +// * 通过key 和 fields 获取指定的value 如果没有对应的value则返回null | |
| 1047 | +// * </p> | |
| 1048 | +// * | |
| 1049 | +// * @param key | |
| 1050 | +// * @param fields 可以使 一个String 也可以是 String数组 | |
| 1051 | +// * @return | |
| 1052 | +// */ | |
| 1053 | +// public List<String> hmget(String key, int indexdb, String... fields) { | |
| 1054 | +// Jedis jedis = null; | |
| 1055 | +// List<String> res = null; | |
| 1056 | +// try { | |
| 1057 | +// jedis = jedisPool.getResource(); | |
| 1058 | +// jedis.select(indexdb); | |
| 1059 | +// res = jedis.hmget(key, fields); | |
| 1060 | +// } catch (Exception e) { | |
| 1061 | +// | |
| 1062 | +// logger.error(e.getMessage()); | |
| 1063 | +// } finally { | |
| 1064 | +// returnResource(jedis); | |
| 1065 | +// } | |
| 1066 | +// return res; | |
| 1067 | +// } | |
| 1068 | +// | |
| 1069 | +// /** | |
| 1070 | +// * <p> | |
| 1071 | +// * 通过key给指定的field的value加上给定的值 | |
| 1072 | +// * </p> | |
| 1073 | +// * | |
| 1074 | +// * @param key | |
| 1075 | +// * @param field | |
| 1076 | +// * @param value | |
| 1077 | +// * @return | |
| 1078 | +// */ | |
| 1079 | +// public Long hincrby(String key, String field, Long value) { | |
| 1080 | +// Jedis jedis = null; | |
| 1081 | +// Long res = null; | |
| 1082 | +// try { | |
| 1083 | +// jedis = jedisPool.getResource(); | |
| 1084 | +// jedis.select(indexdb); | |
| 1085 | +// res = jedis.hincrBy(key, field, value); | |
| 1086 | +// } catch (Exception e) { | |
| 1087 | +// | |
| 1088 | +// logger.error(e.getMessage()); | |
| 1089 | +// } finally { | |
| 1090 | +// returnResource(jedis); | |
| 1091 | +// } | |
| 1092 | +// return res; | |
| 1093 | +// } | |
| 1094 | +// | |
| 1095 | +// /** | |
| 1096 | +// * <p> | |
| 1097 | +// * 通过key和field判断是否有指定的value存在 | |
| 1098 | +// * </p> | |
| 1099 | +// * | |
| 1100 | +// * @param key | |
| 1101 | +// * @param field | |
| 1102 | +// * @return | |
| 1103 | +// */ | |
| 1104 | +// public Boolean hexists(String key, String field) { | |
| 1105 | +// Jedis jedis = null; | |
| 1106 | +// Boolean res = false; | |
| 1107 | +// try { | |
| 1108 | +// jedis = jedisPool.getResource(); | |
| 1109 | +// jedis.select(indexdb); | |
| 1110 | +// res = jedis.hexists(key, field); | |
| 1111 | +// } catch (Exception e) { | |
| 1112 | +// | |
| 1113 | +// logger.error(e.getMessage()); | |
| 1114 | +// } finally { | |
| 1115 | +// returnResource(jedis); | |
| 1116 | +// } | |
| 1117 | +// return res; | |
| 1118 | +// } | |
| 1119 | +// | |
| 1120 | +// /** | |
| 1121 | +// * <p> | |
| 1122 | +// * 通过key返回field的数量 | |
| 1123 | +// * </p> | |
| 1124 | +// * | |
| 1125 | +// * @param key | |
| 1126 | +// * @return | |
| 1127 | +// */ | |
| 1128 | +// public Long hlen(String key) { | |
| 1129 | +// Jedis jedis = null; | |
| 1130 | +// Long res = null; | |
| 1131 | +// try { | |
| 1132 | +// jedis = jedisPool.getResource(); | |
| 1133 | +// jedis.select(indexdb); | |
| 1134 | +// res = jedis.hlen(key); | |
| 1135 | +// } catch (Exception e) { | |
| 1136 | +// | |
| 1137 | +// logger.error(e.getMessage()); | |
| 1138 | +// } finally { | |
| 1139 | +// returnResource(jedis); | |
| 1140 | +// } | |
| 1141 | +// return res; | |
| 1142 | +// | |
| 1143 | +// } | |
| 1144 | +// | |
| 1145 | +// /** | |
| 1146 | +// * <p> | |
| 1147 | +// * 通过key 删除指定的 field | |
| 1148 | +// * </p> | |
| 1149 | +// * | |
| 1150 | +// * @param key | |
| 1151 | +// * @param fields 可以是 一个 field 也可以是 一个数组 | |
| 1152 | +// * @return | |
| 1153 | +// */ | |
| 1154 | +// public Long hdel(String key, String... fields) { | |
| 1155 | +// Jedis jedis = null; | |
| 1156 | +// Long res = null; | |
| 1157 | +// try { | |
| 1158 | +// jedis = jedisPool.getResource(); | |
| 1159 | +// jedis.select(indexdb); | |
| 1160 | +// res = jedis.hdel(key, fields); | |
| 1161 | +// } catch (Exception e) { | |
| 1162 | +// | |
| 1163 | +// logger.error(e.getMessage()); | |
| 1164 | +// } finally { | |
| 1165 | +// returnResource(jedis); | |
| 1166 | +// } | |
| 1167 | +// return res; | |
| 1168 | +// } | |
| 1169 | +// | |
| 1170 | +// /** | |
| 1171 | +// * <p> | |
| 1172 | +// * 通过key返回所有的field | |
| 1173 | +// * </p> | |
| 1174 | +// * | |
| 1175 | +// * @param key | |
| 1176 | +// * @return | |
| 1177 | +// */ | |
| 1178 | +// public Set<String> hkeys(String key) { | |
| 1179 | +// Jedis jedis = null; | |
| 1180 | +// Set<String> res = null; | |
| 1181 | +// try { | |
| 1182 | +// jedis = jedisPool.getResource(); | |
| 1183 | +// jedis.select(indexdb); | |
| 1184 | +// res = jedis.hkeys(key); | |
| 1185 | +// } catch (Exception e) { | |
| 1186 | +// | |
| 1187 | +// logger.error(e.getMessage()); | |
| 1188 | +// } finally { | |
| 1189 | +// returnResource(jedis); | |
| 1190 | +// } | |
| 1191 | +// return res; | |
| 1192 | +// } | |
| 1193 | +// | |
| 1194 | +// /** | |
| 1195 | +// * <p> | |
| 1196 | +// * 通过key返回所有和key有关的value | |
| 1197 | +// * </p> | |
| 1198 | +// * | |
| 1199 | +// * @param key | |
| 1200 | +// * @return | |
| 1201 | +// */ | |
| 1202 | +// public List<String> hvals(String key) { | |
| 1203 | +// Jedis jedis = null; | |
| 1204 | +// List<String> res = null; | |
| 1205 | +// try { | |
| 1206 | +// jedis = jedisPool.getResource(); | |
| 1207 | +// jedis.select(indexdb); | |
| 1208 | +// res = jedis.hvals(key); | |
| 1209 | +// } catch (Exception e) { | |
| 1210 | +// | |
| 1211 | +// logger.error(e.getMessage()); | |
| 1212 | +// } finally { | |
| 1213 | +// returnResource(jedis); | |
| 1214 | +// } | |
| 1215 | +// return res; | |
| 1216 | +// } | |
| 1217 | +// | |
| 1218 | +// /** | |
| 1219 | +// * <p> | |
| 1220 | +// * 通过key获取所有的field和value | |
| 1221 | +// * </p> | |
| 1222 | +// * | |
| 1223 | +// * @param key | |
| 1224 | +// * @return | |
| 1225 | +// */ | |
| 1226 | +// public Map<String, String> hgetall(String key, int indexdb) { | |
| 1227 | +// Jedis jedis = null; | |
| 1228 | +// Map<String, String> res = null; | |
| 1229 | +// try { | |
| 1230 | +// jedis = jedisPool.getResource(); | |
| 1231 | +// jedis.select(indexdb); | |
| 1232 | +// res = jedis.hgetAll(key); | |
| 1233 | +// } catch (Exception e) { | |
| 1234 | +// logger.error(e.getMessage()); | |
| 1235 | +// } finally { | |
| 1236 | +// returnResource(jedis); | |
| 1237 | +// } | |
| 1238 | +// return res; | |
| 1239 | +// } | |
| 1240 | +// | |
| 1241 | +// /** | |
| 1242 | +// * <p> | |
| 1243 | +// * 通过key向list头部添加字符串 | |
| 1244 | +// * </p> | |
| 1245 | +// * | |
| 1246 | +// * @param key | |
| 1247 | +// * @param strs 可以使一个string 也可以使string数组 | |
| 1248 | +// * @return 返回list的value个数 | |
| 1249 | +// */ | |
| 1250 | +// public Long lpush(int indexdb, String key, String... strs) { | |
| 1251 | +// Jedis jedis = null; | |
| 1252 | +// Long res = null; | |
| 1253 | +// try { | |
| 1254 | +// jedis = jedisPool.getResource(); | |
| 1255 | +// jedis.select(indexdb); | |
| 1256 | +// res = jedis.lpush(key, strs); | |
| 1257 | +// } catch (Exception e) { | |
| 1258 | +// | |
| 1259 | +// logger.error(e.getMessage()); | |
| 1260 | +// } finally { | |
| 1261 | +// returnResource(jedis); | |
| 1262 | +// } | |
| 1263 | +// return res; | |
| 1264 | +// } | |
| 1265 | +// | |
| 1266 | +// /** | |
| 1267 | +// * <p> | |
| 1268 | +// * 通过key向list尾部添加字符串 | |
| 1269 | +// * </p> | |
| 1270 | +// * | |
| 1271 | +// * @param key | |
| 1272 | +// * @param strs 可以使一个string 也可以使string数组 | |
| 1273 | +// * @return 返回list的value个数 | |
| 1274 | +// */ | |
| 1275 | +// public Long rpush(String key, String... strs) { | |
| 1276 | +// Jedis jedis = null; | |
| 1277 | +// Long res = null; | |
| 1278 | +// try { | |
| 1279 | +// jedis = jedisPool.getResource(); | |
| 1280 | +// jedis.select(indexdb); | |
| 1281 | +// res = jedis.rpush(key, strs); | |
| 1282 | +// } catch (Exception e) { | |
| 1283 | +// | |
| 1284 | +// logger.error(e.getMessage()); | |
| 1285 | +// } finally { | |
| 1286 | +// returnResource(jedis); | |
| 1287 | +// } | |
| 1288 | +// return res; | |
| 1289 | +// } | |
| 1290 | +// | |
| 1291 | +// /** | |
| 1292 | +// * <p> | |
| 1293 | +// * 通过key在list指定的位置之前或者之后 添加字符串元素 | |
| 1294 | +// * </p> | |
| 1295 | +// * | |
| 1296 | +// * @param key | |
| 1297 | +// * @param where LIST_POSITION枚举类型 | |
| 1298 | +// * @param pivot list里面的value | |
| 1299 | +// * @param value 添加的value | |
| 1300 | +// * @return | |
| 1301 | +// */ | |
| 1302 | +// public Long linsert(String key, LIST_POSITION where, String pivot, | |
| 1303 | +// String value) { | |
| 1304 | +// Jedis jedis = null; | |
| 1305 | +// Long res = null; | |
| 1306 | +// try { | |
| 1307 | +// jedis = jedisPool.getResource(); | |
| 1308 | +// jedis.select(indexdb); | |
| 1309 | +// res = jedis.linsert(key, where, pivot, value); | |
| 1310 | +// } catch (Exception e) { | |
| 1311 | +// | |
| 1312 | +// logger.error(e.getMessage()); | |
| 1313 | +// } finally { | |
| 1314 | +// returnResource(jedis); | |
| 1315 | +// } | |
| 1316 | +// return res; | |
| 1317 | +// } | |
| 1318 | +// | |
| 1319 | +// /** | |
| 1320 | +// * <p> | |
| 1321 | +// * 通过key设置list指定下标位置的value | |
| 1322 | +// * </p> | |
| 1323 | +// * <p> | |
| 1324 | +// * 如果下标超过list里面value的个数则报错 | |
| 1325 | +// * </p> | |
| 1326 | +// * | |
| 1327 | +// * @param key | |
| 1328 | +// * @param index 从0开始 | |
| 1329 | +// * @param value | |
| 1330 | +// * @return 成功返回OK | |
| 1331 | +// */ | |
| 1332 | +// public String lset(String key, Long index, String value) { | |
| 1333 | +// Jedis jedis = null; | |
| 1334 | +// String res = null; | |
| 1335 | +// try { | |
| 1336 | +// jedis = jedisPool.getResource(); | |
| 1337 | +// jedis.select(indexdb); | |
| 1338 | +// res = jedis.lset(key, index, value); | |
| 1339 | +// } catch (Exception e) { | |
| 1340 | +// | |
| 1341 | +// logger.error(e.getMessage()); | |
| 1342 | +// } finally { | |
| 1343 | +// returnResource(jedis); | |
| 1344 | +// } | |
| 1345 | +// return res; | |
| 1346 | +// } | |
| 1347 | +// | |
| 1348 | +// /** | |
| 1349 | +// * <p> | |
| 1350 | +// * 通过key从对应的list中删除指定的count个 和 value相同的元素 | |
| 1351 | +// * </p> | |
| 1352 | +// * | |
| 1353 | +// * @param key | |
| 1354 | +// * @param count 当count为0时删除全部 | |
| 1355 | +// * @param value | |
| 1356 | +// * @return 返回被删除的个数 | |
| 1357 | +// */ | |
| 1358 | +// public Long lrem(String key, long count, String value) { | |
| 1359 | +// Jedis jedis = null; | |
| 1360 | +// Long res = null; | |
| 1361 | +// try { | |
| 1362 | +// jedis = jedisPool.getResource(); | |
| 1363 | +// jedis.select(indexdb); | |
| 1364 | +// res = jedis.lrem(key, count, value); | |
| 1365 | +// } catch (Exception e) { | |
| 1366 | +// | |
| 1367 | +// logger.error(e.getMessage()); | |
| 1368 | +// } finally { | |
| 1369 | +// returnResource(jedis); | |
| 1370 | +// } | |
| 1371 | +// return res; | |
| 1372 | +// } | |
| 1373 | +// | |
| 1374 | +// /** | |
| 1375 | +// * <p> | |
| 1376 | +// * 通过key保留list中从strat下标开始到end下标结束的value值 | |
| 1377 | +// * </p> | |
| 1378 | +// * | |
| 1379 | +// * @param key | |
| 1380 | +// * @param start | |
| 1381 | +// * @param end | |
| 1382 | +// * @return 成功返回OK | |
| 1383 | +// */ | |
| 1384 | +// public String ltrim(String key, long start, long end) { | |
| 1385 | +// Jedis jedis = null; | |
| 1386 | +// String res = null; | |
| 1387 | +// try { | |
| 1388 | +// jedis = jedisPool.getResource(); | |
| 1389 | +// jedis.select(indexdb); | |
| 1390 | +// res = jedis.ltrim(key, start, end); | |
| 1391 | +// } catch (Exception e) { | |
| 1392 | +// | |
| 1393 | +// logger.error(e.getMessage()); | |
| 1394 | +// } finally { | |
| 1395 | +// returnResource(jedis); | |
| 1396 | +// } | |
| 1397 | +// return res; | |
| 1398 | +// } | |
| 1399 | +// | |
| 1400 | +// /** | |
| 1401 | +// * <p> | |
| 1402 | +// * 通过key从list的头部删除一个value,并返回该value | |
| 1403 | +// * </p> | |
| 1404 | +// * | |
| 1405 | +// * @param key | |
| 1406 | +// * @return | |
| 1407 | +// */ | |
| 1408 | +// synchronized public String lpop(String key) { | |
| 1409 | +// Jedis jedis = null; | |
| 1410 | +// String res = null; | |
| 1411 | +// try { | |
| 1412 | +// jedis = jedisPool.getResource(); | |
| 1413 | +// jedis.select(indexdb); | |
| 1414 | +// res = jedis.lpop(key); | |
| 1415 | +// } catch (Exception e) { | |
| 1416 | +// | |
| 1417 | +// logger.error(e.getMessage()); | |
| 1418 | +// } finally { | |
| 1419 | +// returnResource(jedis); | |
| 1420 | +// } | |
| 1421 | +// return res; | |
| 1422 | +// } | |
| 1423 | +// | |
| 1424 | +// /** | |
| 1425 | +// * <p> | |
| 1426 | +// * 通过key从list尾部删除一个value,并返回该元素 | |
| 1427 | +// * </p> | |
| 1428 | +// * | |
| 1429 | +// * @param key | |
| 1430 | +// * @return | |
| 1431 | +// */ | |
| 1432 | +// synchronized public String rpop(String key, int indexdb) { | |
| 1433 | +// Jedis jedis = null; | |
| 1434 | +// String res = null; | |
| 1435 | +// try { | |
| 1436 | +// jedis = jedisPool.getResource(); | |
| 1437 | +// jedis.select(indexdb); | |
| 1438 | +// res = jedis.rpop(key); | |
| 1439 | +// } catch (Exception e) { | |
| 1440 | +// | |
| 1441 | +// logger.error(e.getMessage()); | |
| 1442 | +// } finally { | |
| 1443 | +// returnResource(jedis); | |
| 1444 | +// } | |
| 1445 | +// return res; | |
| 1446 | +// } | |
| 1447 | +// | |
| 1448 | +// /** | |
| 1449 | +// * <p> | |
| 1450 | +// * 通过key从一个list的尾部删除一个value并添加到另一个list的头部,并返回该value | |
| 1451 | +// * </p> | |
| 1452 | +// * <p> | |
| 1453 | +// * 如果第一个list为空或者不存在则返回null | |
| 1454 | +// * </p> | |
| 1455 | +// * | |
| 1456 | +// * @param srckey | |
| 1457 | +// * @param dstkey | |
| 1458 | +// * @return | |
| 1459 | +// */ | |
| 1460 | +// public String rpoplpush(String srckey, String dstkey, int indexdb) { | |
| 1461 | +// Jedis jedis = null; | |
| 1462 | +// String res = null; | |
| 1463 | +// try { | |
| 1464 | +// jedis = jedisPool.getResource(); | |
| 1465 | +// jedis.select(indexdb); | |
| 1466 | +// res = jedis.rpoplpush(srckey, dstkey); | |
| 1467 | +// } catch (Exception e) { | |
| 1468 | +// | |
| 1469 | +// logger.error(e.getMessage()); | |
| 1470 | +// } finally { | |
| 1471 | +// returnResource(jedis); | |
| 1472 | +// } | |
| 1473 | +// return res; | |
| 1474 | +// } | |
| 1475 | +// | |
| 1476 | +// /** | |
| 1477 | +// * <p> | |
| 1478 | +// * 通过key获取list中指定下标位置的value | |
| 1479 | +// * </p> | |
| 1480 | +// * | |
| 1481 | +// * @param key | |
| 1482 | +// * @param index | |
| 1483 | +// * @return 如果没有返回null | |
| 1484 | +// */ | |
| 1485 | +// public String lindex(String key, long index) { | |
| 1486 | +// Jedis jedis = null; | |
| 1487 | +// String res = null; | |
| 1488 | +// try { | |
| 1489 | +// jedis = jedisPool.getResource(); | |
| 1490 | +// jedis.select(indexdb); | |
| 1491 | +// res = jedis.lindex(key, index); | |
| 1492 | +// } catch (Exception e) { | |
| 1493 | +// | |
| 1494 | +// logger.error(e.getMessage()); | |
| 1495 | +// } finally { | |
| 1496 | +// returnResource(jedis); | |
| 1497 | +// } | |
| 1498 | +// return res; | |
| 1499 | +// } | |
| 1500 | +// | |
| 1501 | +// /** | |
| 1502 | +// * <p> | |
| 1503 | +// * 通过key返回list的长度 | |
| 1504 | +// * </p> | |
| 1505 | +// * | |
| 1506 | +// * @param key | |
| 1507 | +// * @return | |
| 1508 | +// */ | |
| 1509 | +// public Long llen(String key) { | |
| 1510 | +// Jedis jedis = null; | |
| 1511 | +// Long res = null; | |
| 1512 | +// try { | |
| 1513 | +// jedis = jedisPool.getResource(); | |
| 1514 | +// jedis.select(indexdb); | |
| 1515 | +// res = jedis.llen(key); | |
| 1516 | +// } catch (Exception e) { | |
| 1517 | +// | |
| 1518 | +// logger.error(e.getMessage()); | |
| 1519 | +// } finally { | |
| 1520 | +// returnResource(jedis); | |
| 1521 | +// } | |
| 1522 | +// return res; | |
| 1523 | +// } | |
| 1524 | +// | |
| 1525 | +// /** | |
| 1526 | +// * <p> | |
| 1527 | +// * 通过key获取list指定下标位置的value | |
| 1528 | +// * </p> | |
| 1529 | +// * <p> | |
| 1530 | +// * 如果start 为 0 end 为 -1 则返回全部的list中的value | |
| 1531 | +// * </p> | |
| 1532 | +// * | |
| 1533 | +// * @param key | |
| 1534 | +// * @param start | |
| 1535 | +// * @param end | |
| 1536 | +// * @return | |
| 1537 | +// */ | |
| 1538 | +// public List<String> lrange(String key, long start, long end, int indexdb) { | |
| 1539 | +// Jedis jedis = null; | |
| 1540 | +// List<String> res = null; | |
| 1541 | +// try { | |
| 1542 | +// jedis = jedisPool.getResource(); | |
| 1543 | +// jedis.select(indexdb); | |
| 1544 | +// res = jedis.lrange(key, start, end); | |
| 1545 | +// } catch (Exception e) { | |
| 1546 | +// | |
| 1547 | +// logger.error(e.getMessage()); | |
| 1548 | +// } finally { | |
| 1549 | +// returnResource(jedis); | |
| 1550 | +// } | |
| 1551 | +// return res; | |
| 1552 | +// } | |
| 1553 | +// | |
| 1554 | +// /** | |
| 1555 | +// * <p> | |
| 1556 | +// * 将列表 key 下标为 index 的元素的值设置为 value | |
| 1557 | +// * </p> | |
| 1558 | +// * | |
| 1559 | +// * @param key | |
| 1560 | +// * @param index | |
| 1561 | +// * @param value | |
| 1562 | +// * @return 操作成功返回 ok ,否则返回错误信息 | |
| 1563 | +// */ | |
| 1564 | +// public String lset(String key, long index, String value) { | |
| 1565 | +// Jedis jedis = null; | |
| 1566 | +// try { | |
| 1567 | +// jedis = jedisPool.getResource(); | |
| 1568 | +// jedis.select(indexdb); | |
| 1569 | +// return jedis.lset(key, index, value); | |
| 1570 | +// } catch (Exception e) { | |
| 1571 | +// | |
| 1572 | +// logger.error(e.getMessage()); | |
| 1573 | +// } finally { | |
| 1574 | +// returnResource(jedis); | |
| 1575 | +// } | |
| 1576 | +// return null; | |
| 1577 | +// } | |
| 1578 | +// | |
| 1579 | +// /** | |
| 1580 | +// * <p> | |
| 1581 | +// * 返回给定排序后的结果 | |
| 1582 | +// * </p> | |
| 1583 | +// * | |
| 1584 | +// * @param key | |
| 1585 | +// * @param sortingParameters | |
| 1586 | +// * @return 返回列表形式的排序结果 | |
| 1587 | +// */ | |
| 1588 | +// public List<String> sort(String key, SortingParams sortingParameters) { | |
| 1589 | +// Jedis jedis = null; | |
| 1590 | +// try { | |
| 1591 | +// jedis = jedisPool.getResource(); | |
| 1592 | +// jedis.select(indexdb); | |
| 1593 | +// return jedis.sort(key, sortingParameters); | |
| 1594 | +// } catch (Exception e) { | |
| 1595 | +// | |
| 1596 | +// logger.error(e.getMessage()); | |
| 1597 | +// } finally { | |
| 1598 | +// returnResource(jedis); | |
| 1599 | +// } | |
| 1600 | +// return null; | |
| 1601 | +// } | |
| 1602 | +// | |
| 1603 | +// /** | |
| 1604 | +// * <p> | |
| 1605 | +// * 返回排序后的结果,排序默认以数字作为对象,值被解释为双精度浮点数,然后进行比较。 | |
| 1606 | +// * </p> | |
| 1607 | +// * | |
| 1608 | +// * @param key | |
| 1609 | +// * @return 返回列表形式的排序结果 | |
| 1610 | +// */ | |
| 1611 | +// public List<String> sort(String key) { | |
| 1612 | +// Jedis jedis = null; | |
| 1613 | +// try { | |
| 1614 | +// jedis = jedisPool.getResource(); | |
| 1615 | +// jedis.select(indexdb); | |
| 1616 | +// return jedis.sort(key); | |
| 1617 | +// } catch (Exception e) { | |
| 1618 | +// | |
| 1619 | +// logger.error(e.getMessage()); | |
| 1620 | +// } finally { | |
| 1621 | +// returnResource(jedis); | |
| 1622 | +// } | |
| 1623 | +// return null; | |
| 1624 | +// } | |
| 1625 | +// | |
| 1626 | +// /** | |
| 1627 | +// * <p> | |
| 1628 | +// * 通过key向指定的set中添加value | |
| 1629 | +// * </p> | |
| 1630 | +// * | |
| 1631 | +// * @param key | |
| 1632 | +// * @param members 可以是一个String 也可以是一个String数组 | |
| 1633 | +// * @return 添加成功的个数 | |
| 1634 | +// */ | |
| 1635 | +// public Long sadd(String key, String... members) { | |
| 1636 | +// Jedis jedis = null; | |
| 1637 | +// Long res = null; | |
| 1638 | +// try { | |
| 1639 | +// jedis = jedisPool.getResource(); | |
| 1640 | +// jedis.select(indexdb); | |
| 1641 | +// res = jedis.sadd(key, members); | |
| 1642 | +// } catch (Exception e) { | |
| 1643 | +// | |
| 1644 | +// logger.error(e.getMessage()); | |
| 1645 | +// } finally { | |
| 1646 | +// returnResource(jedis); | |
| 1647 | +// } | |
| 1648 | +// return res; | |
| 1649 | +// } | |
| 1650 | +// | |
| 1651 | +// /** | |
| 1652 | +// * <p> | |
| 1653 | +// * 通过key删除set中对应的value值 | |
| 1654 | +// * </p> | |
| 1655 | +// * | |
| 1656 | +// * @param key | |
| 1657 | +// * @param members 可以是一个String 也可以是一个String数组 | |
| 1658 | +// * @return 删除的个数 | |
| 1659 | +// */ | |
| 1660 | +// public Long srem(String key, String... members) { | |
| 1661 | +// Jedis jedis = null; | |
| 1662 | +// Long res = null; | |
| 1663 | +// try { | |
| 1664 | +// jedis = jedisPool.getResource(); | |
| 1665 | +// jedis.select(indexdb); | |
| 1666 | +// res = jedis.srem(key, members); | |
| 1667 | +// } catch (Exception e) { | |
| 1668 | +// | |
| 1669 | +// logger.error(e.getMessage()); | |
| 1670 | +// } finally { | |
| 1671 | +// returnResource(jedis); | |
| 1672 | +// } | |
| 1673 | +// return res; | |
| 1674 | +// } | |
| 1675 | +// | |
| 1676 | +// /** | |
| 1677 | +// * <p> | |
| 1678 | +// * 通过key随机删除一个set中的value并返回该值 | |
| 1679 | +// * </p> | |
| 1680 | +// * | |
| 1681 | +// * @param key | |
| 1682 | +// * @return | |
| 1683 | +// */ | |
| 1684 | +// public String spop(String key) { | |
| 1685 | +// Jedis jedis = null; | |
| 1686 | +// String res = null; | |
| 1687 | +// try { | |
| 1688 | +// jedis = jedisPool.getResource(); | |
| 1689 | +// jedis.select(indexdb); | |
| 1690 | +// res = jedis.spop(key); | |
| 1691 | +// } catch (Exception e) { | |
| 1692 | +// | |
| 1693 | +// logger.error(e.getMessage()); | |
| 1694 | +// } finally { | |
| 1695 | +// returnResource(jedis); | |
| 1696 | +// } | |
| 1697 | +// return res; | |
| 1698 | +// } | |
| 1699 | +// | |
| 1700 | +// /** | |
| 1701 | +// * <p> | |
| 1702 | +// * 通过key获取set中的差集 | |
| 1703 | +// * </p> | |
| 1704 | +// * <p> | |
| 1705 | +// * 以第一个set为标准 | |
| 1706 | +// * </p> | |
| 1707 | +// * | |
| 1708 | +// * @param keys 可以使一个string 则返回set中所有的value 也可以是string数组 | |
| 1709 | +// * @return | |
| 1710 | +// */ | |
| 1711 | +// public Set<String> sdiff(String... keys) { | |
| 1712 | +// Jedis jedis = null; | |
| 1713 | +// Set<String> res = null; | |
| 1714 | +// try { | |
| 1715 | +// jedis = jedisPool.getResource(); | |
| 1716 | +// jedis.select(indexdb); | |
| 1717 | +// res = jedis.sdiff(keys); | |
| 1718 | +// } catch (Exception e) { | |
| 1719 | +// | |
| 1720 | +// logger.error(e.getMessage()); | |
| 1721 | +// } finally { | |
| 1722 | +// returnResource(jedis); | |
| 1723 | +// } | |
| 1724 | +// return res; | |
| 1725 | +// } | |
| 1726 | +// | |
| 1727 | +// /** | |
| 1728 | +// * <p> | |
| 1729 | +// * 通过key获取set中的差集并存入到另一个key中 | |
| 1730 | +// * </p> | |
| 1731 | +// * <p> | |
| 1732 | +// * 以第一个set为标准 | |
| 1733 | +// * </p> | |
| 1734 | +// * | |
| 1735 | +// * @param dstkey 差集存入的key | |
| 1736 | +// * @param keys 可以使一个string 则返回set中所有的value 也可以是string数组 | |
| 1737 | +// * @return | |
| 1738 | +// */ | |
| 1739 | +// public Long sdiffstore(String dstkey, String... keys) { | |
| 1740 | +// Jedis jedis = null; | |
| 1741 | +// Long res = null; | |
| 1742 | +// try { | |
| 1743 | +// jedis = jedisPool.getResource(); | |
| 1744 | +// jedis.select(indexdb); | |
| 1745 | +// res = jedis.sdiffstore(dstkey, keys); | |
| 1746 | +// } catch (Exception e) { | |
| 1747 | +// | |
| 1748 | +// logger.error(e.getMessage()); | |
| 1749 | +// } finally { | |
| 1750 | +// returnResource(jedis); | |
| 1751 | +// } | |
| 1752 | +// return res; | |
| 1753 | +// } | |
| 1754 | +// | |
| 1755 | +// /** | |
| 1756 | +// * <p> | |
| 1757 | +// * 通过key获取指定set中的交集 | |
| 1758 | +// * </p> | |
| 1759 | +// * | |
| 1760 | +// * @param keys 可以使一个string 也可以是一个string数组 | |
| 1761 | +// * @return | |
| 1762 | +// */ | |
| 1763 | +// public Set<String> sinter(String... keys) { | |
| 1764 | +// Jedis jedis = null; | |
| 1765 | +// Set<String> res = null; | |
| 1766 | +// try { | |
| 1767 | +// jedis = jedisPool.getResource(); | |
| 1768 | +// jedis.select(indexdb); | |
| 1769 | +// res = jedis.sinter(keys); | |
| 1770 | +// } catch (Exception e) { | |
| 1771 | +// | |
| 1772 | +// logger.error(e.getMessage()); | |
| 1773 | +// } finally { | |
| 1774 | +// returnResource(jedis); | |
| 1775 | +// } | |
| 1776 | +// return res; | |
| 1777 | +// } | |
| 1778 | +// | |
| 1779 | +// /** | |
| 1780 | +// * <p> | |
| 1781 | +// * 通过key获取指定set中的交集 并将结果存入新的set中 | |
| 1782 | +// * </p> | |
| 1783 | +// * | |
| 1784 | +// * @param dstkey | |
| 1785 | +// * @param keys 可以使一个string 也可以是一个string数组 | |
| 1786 | +// * @return | |
| 1787 | +// */ | |
| 1788 | +// public Long sinterstore(String dstkey, String... keys) { | |
| 1789 | +// Jedis jedis = null; | |
| 1790 | +// Long res = null; | |
| 1791 | +// try { | |
| 1792 | +// jedis = jedisPool.getResource(); | |
| 1793 | +// jedis.select(indexdb); | |
| 1794 | +// res = jedis.sinterstore(dstkey, keys); | |
| 1795 | +// } catch (Exception e) { | |
| 1796 | +// | |
| 1797 | +// logger.error(e.getMessage()); | |
| 1798 | +// } finally { | |
| 1799 | +// returnResource(jedis); | |
| 1800 | +// } | |
| 1801 | +// return res; | |
| 1802 | +// } | |
| 1803 | +// | |
| 1804 | +// /** | |
| 1805 | +// * <p> | |
| 1806 | +// * 通过key返回所有set的并集 | |
| 1807 | +// * </p> | |
| 1808 | +// * | |
| 1809 | +// * @param keys 可以使一个string 也可以是一个string数组 | |
| 1810 | +// * @return | |
| 1811 | +// */ | |
| 1812 | +// public Set<String> sunion(String... keys) { | |
| 1813 | +// Jedis jedis = null; | |
| 1814 | +// Set<String> res = null; | |
| 1815 | +// try { | |
| 1816 | +// jedis = jedisPool.getResource(); | |
| 1817 | +// jedis.select(indexdb); | |
| 1818 | +// res = jedis.sunion(keys); | |
| 1819 | +// } catch (Exception e) { | |
| 1820 | +// | |
| 1821 | +// logger.error(e.getMessage()); | |
| 1822 | +// } finally { | |
| 1823 | +// returnResource(jedis); | |
| 1824 | +// } | |
| 1825 | +// return res; | |
| 1826 | +// } | |
| 1827 | +// | |
| 1828 | +// /** | |
| 1829 | +// * <p> | |
| 1830 | +// * 通过key返回所有set的并集,并存入到新的set中 | |
| 1831 | +// * </p> | |
| 1832 | +// * | |
| 1833 | +// * @param dstkey | |
| 1834 | +// * @param keys 可以使一个string 也可以是一个string数组 | |
| 1835 | +// * @return | |
| 1836 | +// */ | |
| 1837 | +// public Long sunionstore(String dstkey, String... keys) { | |
| 1838 | +// Jedis jedis = null; | |
| 1839 | +// Long res = null; | |
| 1840 | +// try { | |
| 1841 | +// jedis = jedisPool.getResource(); | |
| 1842 | +// jedis.select(indexdb); | |
| 1843 | +// res = jedis.sunionstore(dstkey, keys); | |
| 1844 | +// } catch (Exception e) { | |
| 1845 | +// | |
| 1846 | +// logger.error(e.getMessage()); | |
| 1847 | +// } finally { | |
| 1848 | +// returnResource(jedis); | |
| 1849 | +// } | |
| 1850 | +// return res; | |
| 1851 | +// } | |
| 1852 | +// | |
| 1853 | +// /** | |
| 1854 | +// * <p> | |
| 1855 | +// * 通过key将set中的value移除并添加到第二个set中 | |
| 1856 | +// * </p> | |
| 1857 | +// * | |
| 1858 | +// * @param srckey 需要移除的 | |
| 1859 | +// * @param dstkey 添加的 | |
| 1860 | +// * @param member set中的value | |
| 1861 | +// * @return | |
| 1862 | +// */ | |
| 1863 | +// public Long smove(String srckey, String dstkey, String member) { | |
| 1864 | +// Jedis jedis = null; | |
| 1865 | +// Long res = null; | |
| 1866 | +// try { | |
| 1867 | +// jedis = jedisPool.getResource(); | |
| 1868 | +// jedis.select(indexdb); | |
| 1869 | +// res = jedis.smove(srckey, dstkey, member); | |
| 1870 | +// } catch (Exception e) { | |
| 1871 | +// | |
| 1872 | +// logger.error(e.getMessage()); | |
| 1873 | +// } finally { | |
| 1874 | +// returnResource(jedis); | |
| 1875 | +// } | |
| 1876 | +// return res; | |
| 1877 | +// } | |
| 1878 | +// | |
| 1879 | +// /** | |
| 1880 | +// * <p> | |
| 1881 | +// * 通过key获取set中value的个数 | |
| 1882 | +// * </p> | |
| 1883 | +// * | |
| 1884 | +// * @param key | |
| 1885 | +// * @return | |
| 1886 | +// */ | |
| 1887 | +// public Long scard(String key) { | |
| 1888 | +// Jedis jedis = null; | |
| 1889 | +// Long res = null; | |
| 1890 | +// try { | |
| 1891 | +// jedis = jedisPool.getResource(); | |
| 1892 | +// jedis.select(indexdb); | |
| 1893 | +// res = jedis.scard(key); | |
| 1894 | +// } catch (Exception e) { | |
| 1895 | +// | |
| 1896 | +// logger.error(e.getMessage()); | |
| 1897 | +// } finally { | |
| 1898 | +// returnResource(jedis); | |
| 1899 | +// } | |
| 1900 | +// return res; | |
| 1901 | +// } | |
| 1902 | +// | |
| 1903 | +// /** | |
| 1904 | +// * <p> | |
| 1905 | +// * 通过key判断value是否是set中的元素 | |
| 1906 | +// * </p> | |
| 1907 | +// * | |
| 1908 | +// * @param key | |
| 1909 | +// * @param member | |
| 1910 | +// * @return | |
| 1911 | +// */ | |
| 1912 | +// public Boolean sismember(String key, String member) { | |
| 1913 | +// Jedis jedis = null; | |
| 1914 | +// Boolean res = null; | |
| 1915 | +// try { | |
| 1916 | +// jedis = jedisPool.getResource(); | |
| 1917 | +// jedis.select(indexdb); | |
| 1918 | +// res = jedis.sismember(key, member); | |
| 1919 | +// } catch (Exception e) { | |
| 1920 | +// | |
| 1921 | +// logger.error(e.getMessage()); | |
| 1922 | +// } finally { | |
| 1923 | +// returnResource(jedis); | |
| 1924 | +// } | |
| 1925 | +// return res; | |
| 1926 | +// } | |
| 1927 | +// | |
| 1928 | +// /** | |
| 1929 | +// * <p> | |
| 1930 | +// * 通过key获取set中随机的value,不删除元素 | |
| 1931 | +// * </p> | |
| 1932 | +// * | |
| 1933 | +// * @param key | |
| 1934 | +// * @return | |
| 1935 | +// */ | |
| 1936 | +// public String srandmember(String key) { | |
| 1937 | +// Jedis jedis = null; | |
| 1938 | +// String res = null; | |
| 1939 | +// try { | |
| 1940 | +// jedis = jedisPool.getResource(); | |
| 1941 | +// jedis.select(indexdb); | |
| 1942 | +// res = jedis.srandmember(key); | |
| 1943 | +// } catch (Exception e) { | |
| 1944 | +// | |
| 1945 | +// logger.error(e.getMessage()); | |
| 1946 | +// } finally { | |
| 1947 | +// returnResource(jedis); | |
| 1948 | +// } | |
| 1949 | +// return res; | |
| 1950 | +// } | |
| 1951 | +// | |
| 1952 | +// /** | |
| 1953 | +// * <p> | |
| 1954 | +// * 通过key获取set中所有的value | |
| 1955 | +// * </p> | |
| 1956 | +// * | |
| 1957 | +// * @param key | |
| 1958 | +// * @return | |
| 1959 | +// */ | |
| 1960 | +// public Set<String> smembers(String key) { | |
| 1961 | +// Jedis jedis = null; | |
| 1962 | +// Set<String> res = null; | |
| 1963 | +// try { | |
| 1964 | +// jedis = jedisPool.getResource(); | |
| 1965 | +// jedis.select(indexdb); | |
| 1966 | +// res = jedis.smembers(key); | |
| 1967 | +// } catch (Exception e) { | |
| 1968 | +// | |
| 1969 | +// logger.error(e.getMessage()); | |
| 1970 | +// } finally { | |
| 1971 | +// returnResource(jedis); | |
| 1972 | +// } | |
| 1973 | +// return res; | |
| 1974 | +// } | |
| 1975 | +// | |
| 1976 | +// /** | |
| 1977 | +// * <p> | |
| 1978 | +// * 通过key向zset中添加value,score,其中score就是用来排序的 | |
| 1979 | +// * </p> | |
| 1980 | +// * <p> | |
| 1981 | +// * 如果该value已经存在则根据score更新元素 | |
| 1982 | +// * </p> | |
| 1983 | +// * | |
| 1984 | +// * @param key | |
| 1985 | +// * @param score | |
| 1986 | +// * @param member | |
| 1987 | +// * @return | |
| 1988 | +// */ | |
| 1989 | +// public Long zadd(String key, double score, String member) { | |
| 1990 | +// Jedis jedis = null; | |
| 1991 | +// Long res = null; | |
| 1992 | +// try { | |
| 1993 | +// jedis = jedisPool.getResource(); | |
| 1994 | +// jedis.select(indexdb); | |
| 1995 | +// res = jedis.zadd(key, score, member); | |
| 1996 | +// } catch (Exception e) { | |
| 1997 | +// | |
| 1998 | +// logger.error(e.getMessage()); | |
| 1999 | +// } finally { | |
| 2000 | +// returnResource(jedis); | |
| 2001 | +// } | |
| 2002 | +// return res; | |
| 2003 | +// } | |
| 2004 | +// | |
| 2005 | +// /** | |
| 2006 | +// * <p> | |
| 2007 | +// * 返回有序集 key 中,指定区间内的成员。min=0,max=-1代表所有元素 | |
| 2008 | +// * </p> | |
| 2009 | +// * | |
| 2010 | +// * @param key | |
| 2011 | +// * @param min | |
| 2012 | +// * @param max | |
| 2013 | +// * @return 指定区间内的有序集成员的列表。 | |
| 2014 | +// */ | |
| 2015 | +// public Set<String> zrange(String key, long min, long max) { | |
| 2016 | +// Jedis jedis = null; | |
| 2017 | +// try { | |
| 2018 | +// jedis = jedisPool.getResource(); | |
| 2019 | +// jedis.select(indexdb); | |
| 2020 | +// return jedis.zrange(key, min, max); | |
| 2021 | +// } catch (Exception e) { | |
| 2022 | +// | |
| 2023 | +// logger.error(e.getMessage()); | |
| 2024 | +// } finally { | |
| 2025 | +// returnResource(jedis); | |
| 2026 | +// } | |
| 2027 | +// return null; | |
| 2028 | +// } | |
| 2029 | +// | |
| 2030 | +// /** | |
| 2031 | +// * <p> | |
| 2032 | +// * 统计有序集 key 中,值在 min 和 max 之间的成员的数量 | |
| 2033 | +// * </p> | |
| 2034 | +// * | |
| 2035 | +// * @param key | |
| 2036 | +// * @param min | |
| 2037 | +// * @param max | |
| 2038 | +// * @return 值在 min 和 max 之间的成员的数量。异常返回0 | |
| 2039 | +// */ | |
| 2040 | +// public Long zcount(String key, double min, double max) { | |
| 2041 | +// Jedis jedis = null; | |
| 2042 | +// try { | |
| 2043 | +// jedis = jedisPool.getResource(); | |
| 2044 | +// jedis.select(indexdb); | |
| 2045 | +// return jedis.zcount(key, min, max); | |
| 2046 | +// } catch (Exception e) { | |
| 2047 | +// | |
| 2048 | +// logger.error(e.getMessage()); | |
| 2049 | +// return 0L; | |
| 2050 | +// } finally { | |
| 2051 | +// returnResource(jedis); | |
| 2052 | +// } | |
| 2053 | +// | |
| 2054 | +// } | |
| 2055 | +// | |
| 2056 | +// /** | |
| 2057 | +// * <p> | |
| 2058 | +// * 为哈希表 key 中的域 field 的值加上增量 increment 。增量也可以为负数,相当于对给定域进行减法操作。 如果 key | |
| 2059 | +// * 不存在,一个新的哈希表被创建并执行 HINCRBY 命令。如果域 field 不存在,那么在执行命令前,域的值被初始化为 0 。 | |
| 2060 | +// * 对一个储存字符串值的域 field 执行 HINCRBY 命令将造成一个错误。本操作的值被限制在 64 位(bit)有符号数字表示之内。 | |
| 2061 | +// * </p> | |
| 2062 | +// * <p> | |
| 2063 | +// * 将名称为key的hash中field的value增加integer | |
| 2064 | +// * </p> | |
| 2065 | +// * | |
| 2066 | +// * @param key | |
| 2067 | +// * @param value | |
| 2068 | +// * @param increment | |
| 2069 | +// * @return 执行 HINCRBY 命令之后,哈希表 key 中域 field的值。异常返回0 | |
| 2070 | +// */ | |
| 2071 | +// public Long hincrBy(String key, String value, long increment) { | |
| 2072 | +// Jedis jedis = null; | |
| 2073 | +// try { | |
| 2074 | +// jedis = jedisPool.getResource(); | |
| 2075 | +// jedis.select(indexdb); | |
| 2076 | +// return jedis.hincrBy(key, value, increment); | |
| 2077 | +// } catch (Exception e) { | |
| 2078 | +// logger.error(e.getMessage()); | |
| 2079 | +// return 0L; | |
| 2080 | +// } finally { | |
| 2081 | +// returnResource(jedis); | |
| 2082 | +// } | |
| 2083 | +// | |
| 2084 | +// } | |
| 2085 | +// | |
| 2086 | +// /** | |
| 2087 | +// * <p> | |
| 2088 | +// * 通过key删除在zset中指定的value | |
| 2089 | +// * </p> | |
| 2090 | +// * | |
| 2091 | +// * @param key | |
| 2092 | +// * @param members 可以使一个string 也可以是一个string数组 | |
| 2093 | +// * @return | |
| 2094 | +// */ | |
| 2095 | +// public Long zrem(String key, String... members) { | |
| 2096 | +// Jedis jedis = null; | |
| 2097 | +// Long res = null; | |
| 2098 | +// try { | |
| 2099 | +// jedis = jedisPool.getResource(); | |
| 2100 | +// jedis.select(indexdb); | |
| 2101 | +// res = jedis.zrem(key, members); | |
| 2102 | +// } catch (Exception e) { | |
| 2103 | +// | |
| 2104 | +// logger.error(e.getMessage()); | |
| 2105 | +// } finally { | |
| 2106 | +// returnResource(jedis); | |
| 2107 | +// } | |
| 2108 | +// return res; | |
| 2109 | +// } | |
| 2110 | +// | |
| 2111 | +// /** | |
| 2112 | +// * <p> | |
| 2113 | +// * 通过key增加该zset中value的score的值 | |
| 2114 | +// * </p> | |
| 2115 | +// * | |
| 2116 | +// * @param key | |
| 2117 | +// * @param score | |
| 2118 | +// * @param member | |
| 2119 | +// * @return | |
| 2120 | +// */ | |
| 2121 | +// public Double zincrby(String key, double score, String member) { | |
| 2122 | +// Jedis jedis = null; | |
| 2123 | +// Double res = null; | |
| 2124 | +// try { | |
| 2125 | +// jedis = jedisPool.getResource(); | |
| 2126 | +// jedis.select(indexdb); | |
| 2127 | +// res = jedis.zincrby(key, score, member); | |
| 2128 | +// } catch (Exception e) { | |
| 2129 | +// | |
| 2130 | +// logger.error(e.getMessage()); | |
| 2131 | +// } finally { | |
| 2132 | +// returnResource(jedis); | |
| 2133 | +// } | |
| 2134 | +// return res; | |
| 2135 | +// } | |
| 2136 | +// | |
| 2137 | +// /** | |
| 2138 | +// * <p> | |
| 2139 | +// * 通过key返回zset中value的排名 | |
| 2140 | +// * </p> | |
| 2141 | +// * <p> | |
| 2142 | +// * 下标从小到大排序 | |
| 2143 | +// * </p> | |
| 2144 | +// * | |
| 2145 | +// * @param key | |
| 2146 | +// * @param member | |
| 2147 | +// * @return | |
| 2148 | +// */ | |
| 2149 | +// public Long zrank(String key, String member) { | |
| 2150 | +// Jedis jedis = null; | |
| 2151 | +// Long res = null; | |
| 2152 | +// try { | |
| 2153 | +// jedis = jedisPool.getResource(); | |
| 2154 | +// jedis.select(indexdb); | |
| 2155 | +// res = jedis.zrank(key, member); | |
| 2156 | +// } catch (Exception e) { | |
| 2157 | +// | |
| 2158 | +// logger.error(e.getMessage()); | |
| 2159 | +// } finally { | |
| 2160 | +// returnResource(jedis); | |
| 2161 | +// } | |
| 2162 | +// return res; | |
| 2163 | +// } | |
| 2164 | +// | |
| 2165 | +// /** | |
| 2166 | +// * <p> | |
| 2167 | +// * 通过key返回zset中value的排名 | |
| 2168 | +// * </p> | |
| 2169 | +// * <p> | |
| 2170 | +// * 下标从大到小排序 | |
| 2171 | +// * </p> | |
| 2172 | +// * | |
| 2173 | +// * @param key | |
| 2174 | +// * @param member | |
| 2175 | +// * @return | |
| 2176 | +// */ | |
| 2177 | +// public Long zrevrank(String key, String member) { | |
| 2178 | +// Jedis jedis = null; | |
| 2179 | +// Long res = null; | |
| 2180 | +// try { | |
| 2181 | +// jedis = jedisPool.getResource(); | |
| 2182 | +// jedis.select(indexdb); | |
| 2183 | +// res = jedis.zrevrank(key, member); | |
| 2184 | +// } catch (Exception e) { | |
| 2185 | +// | |
| 2186 | +// logger.error(e.getMessage()); | |
| 2187 | +// } finally { | |
| 2188 | +// returnResource(jedis); | |
| 2189 | +// } | |
| 2190 | +// return res; | |
| 2191 | +// } | |
| 2192 | +// | |
| 2193 | +// /** | |
| 2194 | +// * <p> | |
| 2195 | +// * 通过key将获取score从start到end中zset的value | |
| 2196 | +// * </p> | |
| 2197 | +// * <p> | |
| 2198 | +// * socre从大到小排序 | |
| 2199 | +// * </p> | |
| 2200 | +// * <p> | |
| 2201 | +// * 当start为0 end为-1时返回全部 | |
| 2202 | +// * </p> | |
| 2203 | +// * | |
| 2204 | +// * @param key | |
| 2205 | +// * @param start | |
| 2206 | +// * @param end | |
| 2207 | +// * @return | |
| 2208 | +// */ | |
| 2209 | +// public Set<String> zrevrange(String key, long start, long end) { | |
| 2210 | +// Jedis jedis = null; | |
| 2211 | +// Set<String> res = null; | |
| 2212 | +// try { | |
| 2213 | +// jedis = jedisPool.getResource(); | |
| 2214 | +// jedis.select(indexdb); | |
| 2215 | +// res = jedis.zrevrange(key, start, end); | |
| 2216 | +// } catch (Exception e) { | |
| 2217 | +// | |
| 2218 | +// logger.error(e.getMessage()); | |
| 2219 | +// } finally { | |
| 2220 | +// returnResource(jedis); | |
| 2221 | +// } | |
| 2222 | +// return res; | |
| 2223 | +// } | |
| 2224 | +// | |
| 2225 | +// /** | |
| 2226 | +// * <p> | |
| 2227 | +// * 通过key返回指定score内zset中的value | |
| 2228 | +// * </p> | |
| 2229 | +// * | |
| 2230 | +// * @param key | |
| 2231 | +// * @param max | |
| 2232 | +// * @param min | |
| 2233 | +// * @return | |
| 2234 | +// */ | |
| 2235 | +// public Set<String> zrangebyscore(String key, String max, String min) { | |
| 2236 | +// Jedis jedis = null; | |
| 2237 | +// Set<String> res = null; | |
| 2238 | +// try { | |
| 2239 | +// jedis = jedisPool.getResource(); | |
| 2240 | +// jedis.select(indexdb); | |
| 2241 | +// res = jedis.zrevrangeByScore(key, max, min); | |
| 2242 | +// } catch (Exception e) { | |
| 2243 | +// | |
| 2244 | +// logger.error(e.getMessage()); | |
| 2245 | +// } finally { | |
| 2246 | +// returnResource(jedis); | |
| 2247 | +// } | |
| 2248 | +// return res; | |
| 2249 | +// } | |
| 2250 | +// | |
| 2251 | +// /** | |
| 2252 | +// * <p> | |
| 2253 | +// * 通过key返回指定score内zset中的value | |
| 2254 | +// * </p> | |
| 2255 | +// * | |
| 2256 | +// * @param key | |
| 2257 | +// * @param max | |
| 2258 | +// * @param min | |
| 2259 | +// * @return | |
| 2260 | +// */ | |
| 2261 | +// public Set<String> zrangeByScore(String key, double max, double min) { | |
| 2262 | +// Jedis jedis = null; | |
| 2263 | +// Set<String> res = null; | |
| 2264 | +// try { | |
| 2265 | +// jedis = jedisPool.getResource(); | |
| 2266 | +// jedis.select(indexdb); | |
| 2267 | +// res = jedis.zrevrangeByScore(key, max, min); | |
| 2268 | +// } catch (Exception e) { | |
| 2269 | +// | |
| 2270 | +// logger.error(e.getMessage()); | |
| 2271 | +// } finally { | |
| 2272 | +// returnResource(jedis); | |
| 2273 | +// } | |
| 2274 | +// return res; | |
| 2275 | +// } | |
| 2276 | +// | |
| 2277 | +// /** | |
| 2278 | +// * <p> | |
| 2279 | +// * 返回指定区间内zset中value的数量 | |
| 2280 | +// * </p> | |
| 2281 | +// * | |
| 2282 | +// * @param key | |
| 2283 | +// * @param min | |
| 2284 | +// * @param max | |
| 2285 | +// * @return | |
| 2286 | +// */ | |
| 2287 | +// public Long zcount(String key, String min, String max) { | |
| 2288 | +// Jedis jedis = null; | |
| 2289 | +// Long res = null; | |
| 2290 | +// try { | |
| 2291 | +// jedis = jedisPool.getResource(); | |
| 2292 | +// jedis.select(indexdb); | |
| 2293 | +// res = jedis.zcount(key, min, max); | |
| 2294 | +// } catch (Exception e) { | |
| 2295 | +// | |
| 2296 | +// logger.error(e.getMessage()); | |
| 2297 | +// } finally { | |
| 2298 | +// returnResource(jedis); | |
| 2299 | +// } | |
| 2300 | +// return res; | |
| 2301 | +// } | |
| 2302 | +// | |
| 2303 | +// /** | |
| 2304 | +// * <p> | |
| 2305 | +// * 通过key返回zset中的value个数 | |
| 2306 | +// * </p> | |
| 2307 | +// * | |
| 2308 | +// * @param key | |
| 2309 | +// * @return | |
| 2310 | +// */ | |
| 2311 | +// public Long zcard(String key) { | |
| 2312 | +// Jedis jedis = null; | |
| 2313 | +// Long res = null; | |
| 2314 | +// try { | |
| 2315 | +// jedis = jedisPool.getResource(); | |
| 2316 | +// jedis.select(indexdb); | |
| 2317 | +// res = jedis.zcard(key); | |
| 2318 | +// } catch (Exception e) { | |
| 2319 | +// | |
| 2320 | +// logger.error(e.getMessage()); | |
| 2321 | +// } finally { | |
| 2322 | +// returnResource(jedis); | |
| 2323 | +// } | |
| 2324 | +// return res; | |
| 2325 | +// } | |
| 2326 | +// | |
| 2327 | +// /** | |
| 2328 | +// * <p> | |
| 2329 | +// * 通过key获取zset中value的score值 | |
| 2330 | +// * </p> | |
| 2331 | +// * | |
| 2332 | +// * @param key | |
| 2333 | +// * @param member | |
| 2334 | +// * @return | |
| 2335 | +// */ | |
| 2336 | +// public Double zscore(String key, String member) { | |
| 2337 | +// Jedis jedis = null; | |
| 2338 | +// Double res = null; | |
| 2339 | +// try { | |
| 2340 | +// jedis = jedisPool.getResource(); | |
| 2341 | +// jedis.select(indexdb); | |
| 2342 | +// res = jedis.zscore(key, member); | |
| 2343 | +// } catch (Exception e) { | |
| 2344 | +// | |
| 2345 | +// logger.error(e.getMessage()); | |
| 2346 | +// } finally { | |
| 2347 | +// returnResource(jedis); | |
| 2348 | +// } | |
| 2349 | +// return res; | |
| 2350 | +// } | |
| 2351 | +// | |
| 2352 | +// /** | |
| 2353 | +// * <p> | |
| 2354 | +// * 通过key删除给定区间内的元素 | |
| 2355 | +// * </p> | |
| 2356 | +// * | |
| 2357 | +// * @param key | |
| 2358 | +// * @param start | |
| 2359 | +// * @param end | |
| 2360 | +// * @return | |
| 2361 | +// */ | |
| 2362 | +// public Long zremrangeByRank(String key, long start, long end) { | |
| 2363 | +// Jedis jedis = null; | |
| 2364 | +// Long res = null; | |
| 2365 | +// try { | |
| 2366 | +// jedis = jedisPool.getResource(); | |
| 2367 | +// jedis.select(indexdb); | |
| 2368 | +// res = jedis.zremrangeByRank(key, start, end); | |
| 2369 | +// } catch (Exception e) { | |
| 2370 | +// | |
| 2371 | +// logger.error(e.getMessage()); | |
| 2372 | +// } finally { | |
| 2373 | +// returnResource(jedis); | |
| 2374 | +// } | |
| 2375 | +// return res; | |
| 2376 | +// } | |
| 2377 | +// | |
| 2378 | +// /** | |
| 2379 | +// * <p> | |
| 2380 | +// * 通过key删除指定score内的元素 | |
| 2381 | +// * </p> | |
| 2382 | +// * | |
| 2383 | +// * @param key | |
| 2384 | +// * @param start | |
| 2385 | +// * @param end | |
| 2386 | +// * @return | |
| 2387 | +// */ | |
| 2388 | +// public Long zremrangeByScore(String key, double start, double end) { | |
| 2389 | +// Jedis jedis = null; | |
| 2390 | +// Long res = null; | |
| 2391 | +// try { | |
| 2392 | +// jedis = jedisPool.getResource(); | |
| 2393 | +// jedis.select(indexdb); | |
| 2394 | +// res = jedis.zremrangeByScore(key, start, end); | |
| 2395 | +// } catch (Exception e) { | |
| 2396 | +// | |
| 2397 | +// logger.error(e.getMessage()); | |
| 2398 | +// } finally { | |
| 2399 | +// returnResource(jedis); | |
| 2400 | +// } | |
| 2401 | +// return res; | |
| 2402 | +// } | |
| 2403 | +// | |
| 2404 | +// /**返回满足pattern表达式的所有 key*/ | |
| 2405 | +// public Set<String> keys(String pattern) { | |
| 2406 | +// Set<String> res = this.scan(pattern); | |
| 2407 | +// return res; | |
| 2408 | +// } | |
| 2409 | +// | |
| 2410 | +// /** | |
| 2411 | +// * key模糊查找 | |
| 2412 | +// * @param keys 要查找的key 例: aaa* ,aaa开头的所有key | |
| 2413 | +// * @return 匹配到的key集合 | |
| 2414 | +// */ | |
| 2415 | +// public Set<String> scan(String keys) { | |
| 2416 | +// return scan(keys,scanlimit); | |
| 2417 | +// } | |
| 2418 | +// | |
| 2419 | +// /** | |
| 2420 | +// * 根据match 查询redis中中的所有key | |
| 2421 | +// * @param match input the argument "ONLINE_*" | |
| 2422 | +// * @param limit 每次查询个数,不要太大 | |
| 2423 | +// */ | |
| 2424 | +// public Set<String> scan(String match,int limit) { | |
| 2425 | +// HashSet<String> keySet = Sets.newHashSet(); | |
| 2426 | +// Jedis jedis = null; | |
| 2427 | +// try { | |
| 2428 | +// jedis = jedisPool.getResource(); | |
| 2429 | +// jedis.select(indexdb); | |
| 2430 | +// //指定规则 | |
| 2431 | +// ScanParams scanParams = new ScanParams().match(match).count(limit); | |
| 2432 | +// boolean hasNext = true; | |
| 2433 | +// //第一次查询的游标 | |
| 2434 | +// String cursor = "0"; | |
| 2435 | +// while (hasNext) { | |
| 2436 | +// ScanResult<String> scanResult = jedis.scan(cursor,scanParams); | |
| 2437 | +// //返回当前查询的key | |
| 2438 | +// List<String> keyList = scanResult.getResult(); | |
| 2439 | +// keySet.addAll(keyList); | |
| 2440 | +// | |
| 2441 | +// cursor = scanResult.getStringCursor(); | |
| 2442 | +// if ("0".equals(cursor)) { | |
| 2443 | +// hasNext = false; | |
| 2444 | +// } | |
| 2445 | +// } | |
| 2446 | +// } catch (Exception e) { | |
| 2447 | +// logger.error(e.getMessage()); | |
| 2448 | +// } finally { | |
| 2449 | +// returnResource(jedis); | |
| 2450 | +// } | |
| 2451 | +// return keySet; | |
| 2452 | +// } | |
| 2453 | +// | |
| 2454 | +// /** | |
| 2455 | +// * <p> | |
| 2456 | +// * 通过key判断值得类型 | |
| 2457 | +// * </p> | |
| 2458 | +// * | |
| 2459 | +// * @param key | |
| 2460 | +// * @return | |
| 2461 | +// */ | |
| 2462 | +// public String type(String key) { | |
| 2463 | +// Jedis jedis = null; | |
| 2464 | +// String res = null; | |
| 2465 | +// try { | |
| 2466 | +// jedis = jedisPool.getResource(); | |
| 2467 | +// jedis.select(indexdb); | |
| 2468 | +// res = jedis.type(key); | |
| 2469 | +// } catch (Exception e) { | |
| 2470 | +// | |
| 2471 | +// logger.error(e.getMessage()); | |
| 2472 | +// } finally { | |
| 2473 | +// returnResource(jedis); | |
| 2474 | +// } | |
| 2475 | +// return res; | |
| 2476 | +// } | |
| 2477 | +// | |
| 2478 | +// /** | |
| 2479 | +// * 序列化对象 | |
| 2480 | +// * | |
| 2481 | +// * @param obj | |
| 2482 | +// * @return 对象需实现Serializable接口 | |
| 2483 | +// */ | |
| 2484 | +// public static byte[] ObjTOSerialize(Object obj) { | |
| 2485 | +// ObjectOutputStream oos = null; | |
| 2486 | +// ByteArrayOutputStream byteOut = null; | |
| 2487 | +// try { | |
| 2488 | +// byteOut = new ByteArrayOutputStream(); | |
| 2489 | +// oos = new ObjectOutputStream(byteOut); | |
| 2490 | +// oos.writeObject(obj); | |
| 2491 | +// byte[] bytes = byteOut.toByteArray(); | |
| 2492 | +// return bytes; | |
| 2493 | +// } catch (Exception e) { | |
| 2494 | +// } | |
| 2495 | +// return null; | |
| 2496 | +// } | |
| 2497 | +// | |
| 2498 | +// /** | |
| 2499 | +// * 反序列化对象 | |
| 2500 | +// * | |
| 2501 | +// * @param bytes | |
| 2502 | +// * @return 对象需实现Serializable接口 | |
| 2503 | +// */ | |
| 2504 | +// public static Object unserialize(byte[] bytes) { | |
| 2505 | +// ByteArrayInputStream bais = null; | |
| 2506 | +// try { | |
| 2507 | +// //反序列化 | |
| 2508 | +// bais = new ByteArrayInputStream(bytes); | |
| 2509 | +// ObjectInputStream ois = new ObjectInputStream(bais); | |
| 2510 | +// return ois.readObject(); | |
| 2511 | +// } catch (Exception e) { | |
| 2512 | +// } | |
| 2513 | +// return null; | |
| 2514 | +// } | |
| 2515 | +// | |
| 2516 | +// /** | |
| 2517 | +// * 返还到连接池 | |
| 2518 | +// * | |
| 2519 | +// * @param jedis | |
| 2520 | +// */ | |
| 2521 | +// public static void returnResource(Jedis jedis) { | |
| 2522 | +// if (jedis != null) { | |
| 2523 | +// jedis.close(); | |
| 2524 | +// } | |
| 2525 | +// } | |
| 2526 | +// | |
| 2527 | +// /** | |
| 2528 | +// * jedis 上锁 | |
| 2529 | +// * @param lockKey | |
| 2530 | +// * @param requestId 锁的值 | |
| 2531 | +// * @param expireTime | |
| 2532 | +// * @return | |
| 2533 | +// */ | |
| 2534 | +// public boolean tryLock(String lockKey, String requestId, int expireTime) { | |
| 2535 | +// Jedis jedis = null; | |
| 2536 | +// try { | |
| 2537 | +// jedis = jedisPool.getResource(); | |
| 2538 | +// jedis.select(indexdb); | |
| 2539 | +// String result = jedis.set(lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME_EX, expireTime); | |
| 2540 | +// if (LOCK_SUCCESS.equals(result)) { | |
| 2541 | +// return true; | |
| 2542 | +// } | |
| 2543 | +// } catch (Exception e) { | |
| 2544 | +// e.printStackTrace(); | |
| 2545 | +// return false; | |
| 2546 | +// } finally { | |
| 2547 | +// returnResource(jedis); | |
| 2548 | +// } | |
| 2549 | +// return false; | |
| 2550 | +// } | |
| 2551 | +// /** | |
| 2552 | +// * jedis 上锁 | |
| 2553 | +// * @param lockKey | |
| 2554 | +// * @param requestId 锁的值 | |
| 2555 | +// * @param expireTime | |
| 2556 | +// * @return | |
| 2557 | +// */ | |
| 2558 | +// public boolean tryLockSec(String lockKey, String requestId, int expireTime) { | |
| 2559 | +// Jedis jedis = null; | |
| 2560 | +// try { | |
| 2561 | +// jedis = jedisPool.getResource(); | |
| 2562 | +// jedis.select(indexdb); | |
| 2563 | +// String result = jedis.set(lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME_EX, expireTime); | |
| 2564 | +// if (LOCK_SUCCESS.equals(result)) { | |
| 2565 | +// return true; | |
| 2566 | +// } | |
| 2567 | +// } catch (Exception e) { | |
| 2568 | +// e.printStackTrace(); | |
| 2569 | +// return false; | |
| 2570 | +// } finally { | |
| 2571 | +// returnResource(jedis); | |
| 2572 | +// } | |
| 2573 | +// return false; | |
| 2574 | +// } | |
| 2575 | +// /** | |
| 2576 | +// * jedis 上锁 | |
| 2577 | +// * @param lockKey | |
| 2578 | +// * @param requestId 锁的值 | |
| 2579 | +// * @return | |
| 2580 | +// */ | |
| 2581 | +// public boolean tryLock(String lockKey, String requestId) { | |
| 2582 | +// return this.tryLock( lockKey, requestId, lockWaitTime); | |
| 2583 | +// } | |
| 2584 | +// | |
| 2585 | +// | |
| 2586 | +// /** | |
| 2587 | +// * jedis 上锁没返回 | |
| 2588 | +// * @param lockKey | |
| 2589 | +// * @param requestId | |
| 2590 | +// * @param expireTime | |
| 2591 | +// */ | |
| 2592 | +// public void lock(String lockKey, String requestId, int expireTime) { | |
| 2593 | +// while (true) { | |
| 2594 | +// if (tryLock(lockKey, requestId, expireTime)) { | |
| 2595 | +// return; | |
| 2596 | +// } | |
| 2597 | +// } | |
| 2598 | +// } | |
| 2599 | +// | |
| 2600 | +// /** | |
| 2601 | +// * jedis解锁 | |
| 2602 | +// * @param lockKey | |
| 2603 | +// * @param requestId | |
| 2604 | +// * @return | |
| 2605 | +// */ | |
| 2606 | +// public boolean unLock(String lockKey, String requestId) { | |
| 2607 | +// String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"; | |
| 2608 | +// Jedis jedis = null; | |
| 2609 | +// try { | |
| 2610 | +// jedis = jedisPool.getResource(); | |
| 2611 | +// jedis.select(indexdb); | |
| 2612 | +// Object result = jedis.eval(script, Collections.singletonList(lockKey), | |
| 2613 | +// Collections.singletonList(requestId)); | |
| 2614 | +// if (RELEASE_SUCCESS.equals(result)) { | |
| 2615 | +// System.out.println("unlock "+ Thread.currentThread().getName()+ " requestId:" + requestId); | |
| 2616 | +// return true; | |
| 2617 | +// } | |
| 2618 | +// jedis.del(lockKey); | |
| 2619 | +// } catch (Exception e) { | |
| 2620 | +// throw e; | |
| 2621 | +// } finally { | |
| 2622 | +// returnResource(jedis); | |
| 2623 | +// } | |
| 2624 | +// return false; | |
| 2625 | +// } | |
| 2626 | +// | |
| 2627 | +// | |
| 2628 | +// @Cacheable(value="getSelectRedis" ,key="#sCacheableName") | |
| 2629 | +// public List<Map<String,Object>> getSelectRedis(String sCacheableName,List<Map<String,Object>> selectDate) { | |
| 2630 | +// return selectDate; | |
| 2631 | +// } | |
| 2632 | +// | |
| 2633 | +// public static void main(String[] args) { | |
| 2634 | +// /*JedisPool jedisPool = new JedisPool(null,"localhost",6379,100,"123456"); | |
| 2635 | +// Jedis jedis = jedisPool.getResource(); | |
| 2636 | +// //r.get("", RedisConstants.datebase4); | |
| 2637 | +// jedis.select(RedisConstants.datebase4); | |
| 2638 | +// Set<String> str = jedis.keys("*"); | |
| 2639 | +// for (String string : str) { | |
| 2640 | +// System.out.println(string); | |
| 2641 | +// }*/ | |
| 2642 | +// } | |
| 2643 | +//} | |
| 0 | 2644 | \ No newline at end of file | ... | ... |
src/main/java/com/xly/entity/UserSceneSession.java
| ... | ... | @@ -19,7 +19,12 @@ public class UserSceneSession { |
| 19 | 19 | * 唯一标识:用户ID |
| 20 | 20 | */ |
| 21 | 21 | private String userId; |
| 22 | + private String userName; | |
| 22 | 23 | private String authorization; |
| 24 | + | |
| 25 | + private String sUserName; | |
| 26 | + private String sBrandsId; | |
| 27 | + private String sSubsidiaryId; | |
| 23 | 28 | /** |
| 24 | 29 | * 该用户权限内可访问的所有场景(从权限映射中获取) |
| 25 | 30 | */ | ... | ... |
src/main/java/com/xly/service/UserSceneSessionService.java
| ... | ... | @@ -90,7 +90,13 @@ public class UserSceneSessionService { |
| 90 | 90 | ERP_DynamicTableNl2SqlAiAgent_CACHE.remove(sUserId); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - public UserSceneSession getUserSceneSession(String sUserId, String sUserType,String authorization){ | |
| 93 | + public UserSceneSession getUserSceneSession(String sUserId, | |
| 94 | + String sUserName, | |
| 95 | + String sBrandsId, | |
| 96 | + String sSubsidiaryId, | |
| 97 | + String sUserType, | |
| 98 | + String authorization){ | |
| 99 | + | |
| 94 | 100 | if (USER_SCENE_SESSION_CACHE.containsKey(sUserId)) { |
| 95 | 101 | return USER_SCENE_SESSION_CACHE.get(sUserId); |
| 96 | 102 | } |
| ... | ... | @@ -102,6 +108,9 @@ public class UserSceneSessionService { |
| 102 | 108 | userSceneSession.setUserId(sUserId);//存入用户ID |
| 103 | 109 | userSceneSession.setAuthTool(tools);//方法 |
| 104 | 110 | userSceneSession.setAuthScenes(sceneDtos);//场景 |
| 111 | + userSceneSession.setUserName(sUserName); | |
| 112 | + userSceneSession.setSBrandsId(sBrandsId); | |
| 113 | + userSceneSession.setSSubsidiaryId(sSubsidiaryId); | |
| 105 | 114 | // 3. 缓存会话 |
| 106 | 115 | USER_SCENE_SESSION_CACHE.put(sUserId, userSceneSession); |
| 107 | 116 | return userSceneSession; | ... | ... |
src/main/java/com/xly/service/XlyErpService.java
| ... | ... | @@ -56,13 +56,19 @@ public class XlyErpService { |
| 56 | 56 | * @return java.lang.String |
| 57 | 57 | * @Description 问答 |
| 58 | 58 | **/ |
| 59 | - public AiResponseDTO erpUserInput(String userInput, String userId , String sUserType, String authorization) { | |
| 59 | + public AiResponseDTO erpUserInput(String userInput, | |
| 60 | + String userId , | |
| 61 | + String sUserName , | |
| 62 | + String sBrandsId , | |
| 63 | + String sSubsidiaryId, | |
| 64 | + String sUserType, | |
| 65 | + String authorization) { | |
| 60 | 66 | long startTime = System.currentTimeMillis(); |
| 61 | 67 | try { |
| 62 | 68 | // 0. 预处理用户输入:去空格、转小写(方便匹配) |
| 63 | 69 | String input= InputPreprocessor.preprocessWithCommons(userInput); |
| 64 | 70 | // 1. 初始化用户场景会话(权限内场景) |
| 65 | - UserSceneSession session = userSceneSessionService.getUserSceneSession(userId, sUserType,authorization); | |
| 71 | + UserSceneSession session = userSceneSessionService.getUserSceneSession(userId,sUserName,sBrandsId,sSubsidiaryId,sUserType,authorization); | |
| 66 | 72 | session.setAuthorization(authorization); |
| 67 | 73 | session.setSFunPrompts(null); |
| 68 | 74 | // 2. 特殊指令:重置场景(无论是否已选,都可重置) |
| ... | ... | @@ -207,9 +213,9 @@ public class XlyErpService { |
| 207 | 213 | * @param sUserId 用户ID(前端传入,如user-001) sUserType 角色状态 |
| 208 | 214 | * @return 场景选择引导词(即原buildSceneSelectHint生成的文案) |
| 209 | 215 | */ |
| 210 | - public AiResponseDTO initSceneGuide(String systemText,String sUserId,String sUserType,String authorization) { | |
| 216 | + public AiResponseDTO initSceneGuide(String systemText,String sUserId,String sUserName,String sBrandsId,String sSubsidiaryId,String sUserType,String authorization) { | |
| 211 | 217 | try { |
| 212 | - UserSceneSession userSceneSession = userSceneSessionService.getUserSceneSession( sUserId, sUserType,authorization); | |
| 218 | + UserSceneSession userSceneSession = userSceneSessionService.getUserSceneSession( sUserId,sUserName,sBrandsId,sSubsidiaryId,sUserType,authorization); | |
| 213 | 219 | systemText = userSceneSession.buildSceneSelectHint(); |
| 214 | 220 | } catch (Exception e) { |
| 215 | 221 | systemText = "<p style='color:red;'>抱歉,你暂无任何业务场景的访问权限,请联系管理员开通!</p>"; | ... | ... |
src/main/java/com/xly/token/RedisTokenManager.java
0 → 100644
| 1 | +//package com.xly.token; | |
| 2 | +// | |
| 3 | +//import cn.hutool.core.util.ObjectUtil; | |
| 4 | +//import cn.hutool.core.util.StrUtil; | |
| 5 | +//import cn.hutool.json.JSONObject; | |
| 6 | +//import cn.hutool.json.JSONUtil; | |
| 7 | +//import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | +//import org.springframework.stereotype.Component; | |
| 9 | +//import org.springframework.util.StringUtils; | |
| 10 | +// | |
| 11 | +///** | |
| 12 | +// * 通过Redis存储和验证token的实现类 | |
| 13 | +// * @author qianbao | |
| 14 | +// * @see TokenManager | |
| 15 | +// */ | |
| 16 | +//@Component | |
| 17 | +//public class RedisTokenManager{ | |
| 18 | +// | |
| 19 | +// private @Autowired | |
| 20 | +// JedisUtil jedisUtil; | |
| 21 | +// | |
| 22 | +// public TokenModel createToken(String userId, String sBrandsId, String sSubsidiaryId, String userType , UserInfo gdslogininfo,String sLoginType) { | |
| 23 | +// //使用uuid作为源token | |
| 24 | +// String token = new IdGen().getNextId(); | |
| 25 | +// TokenModel model = new TokenModel(userId, sBrandsId, sSubsidiaryId, token,userType,sLoginType,gdslogininfo); | |
| 26 | +// //存储到redis并设置过期时间 | |
| 27 | +// jedisUtil.createAndExpireMinutes(sLoginType+userId, token, Constants.TOKEN_EXPIRES_MINUTES); | |
| 28 | +// return model; | |
| 29 | +// } | |
| 30 | +// | |
| 31 | +// @Override | |
| 32 | +// public TokenModel getToken(String authentication) { | |
| 33 | +// if(StringUtils.isEmpty(authentication)){ | |
| 34 | +// return null; | |
| 35 | +// }else{ | |
| 36 | +// authentication= AesUtil.me().decrypt(authentication,AesUtil.me().getKey()); | |
| 37 | +// if (authentication == null || authentication.length() == 0) { | |
| 38 | +// return null; | |
| 39 | +// } | |
| 40 | +// String[] param = authentication.split("_"); | |
| 41 | +// if (param.length != 6) { | |
| 42 | +// return null; | |
| 43 | +// } | |
| 44 | +// //使用userId,sBrandsId,sSubsidiaryId,源token简单拼接成的token,可以增加加密措施 | |
| 45 | +// String userId = param[0]; | |
| 46 | +// String sBrandsId = param[1]; | |
| 47 | +// String sSubsidiaryId = param[2]; | |
| 48 | +// String token = param[3]; | |
| 49 | +// String userType = param[4]; | |
| 50 | +// String sLoginType = param[5]; | |
| 51 | +// UserInfo gdslogininfo= null; | |
| 52 | +// Object v = jedisUtil.getObject(userId+"_"+sBrandsId+"_"+sSubsidiaryId); | |
| 53 | +// if(ObjectUtil.isNotEmpty(v)){ | |
| 54 | +// gdslogininfo = JSONUtil.toBean((JSONObject) v,UserInfo.class); | |
| 55 | +// } | |
| 56 | +// return new TokenModel(userId, sBrandsId, sSubsidiaryId, token,userType,sLoginType,gdslogininfo); | |
| 57 | +// } | |
| 58 | +// } | |
| 59 | +// | |
| 60 | +// @Override | |
| 61 | +// public int checkToken(TokenModel model) { | |
| 62 | +// String token = String.valueOf(jedisUtil.get(model.getsLoginType()+model.getUserId())); | |
| 63 | +// if (StrUtil.isNullOrUndefined(token)) { | |
| 64 | +// return 1; | |
| 65 | +// } | |
| 66 | +// if(!token.equals(model.getToken())) { | |
| 67 | +// return 2; | |
| 68 | +// } | |
| 69 | +// //如果验证成功,说明此用户进行了一次有效操作,延长token的过期时间 | |
| 70 | +// jedisUtil.expireMinutes(model.getsLoginType()+model.getUserId(),Constants.TOKEN_EXPIRES_MINUTES); | |
| 71 | +// return 0; | |
| 72 | +// } | |
| 73 | +// | |
| 74 | +// @Override | |
| 75 | +// public void deleteToken(String userId,String sLoginType) { | |
| 76 | +// jedisUtil.del(sLoginType+userId); | |
| 77 | +// } | |
| 78 | +//} | ... | ... |
src/main/java/com/xly/tool/DynamicToolProvider.java
| ... | ... | @@ -603,10 +603,10 @@ public class DynamicToolProvider implements ToolProvider { |
| 603 | 603 | **/ |
| 604 | 604 | private void appendConfirmAll(StringBuilder markdown,String sName){ |
| 605 | 605 | sName = ObjectUtil.isEmpty(sName)?StrUtil.EMPTY:"["+sName+"]"; |
| 606 | - markdown.append("请确认是否执行").append(sName).append("操作?如果全部,直接回复"全部确认",如果部分,选择后回复"部分确认"\n"); | |
| 606 | + markdown.append("请确认是否执行").append(sName).append("操作?1.全部数据生成多个单据 回复【全部确认】;2.全部数据生成一个单据 回复【合并确认】;3.按自然语义描述生成一个单据 如"1,3行确认"\n"); | |
| 607 | 607 | //全部确认 ,部分确认,取消 |
| 608 | 608 | markdown.append("回复:  ").append("**<a href=\"#\" data-action=\"reset\" data-text=\"全部确认\">全部确认</a>**").append(" ") |
| 609 | - .append("**<a href=\"#\" data-action=\"reset\" data-text=\"确认\">部分确认</a>**").append(" ") | |
| 609 | + .append("**<a href=\"#\" data-action=\"reset\" data-text=\"确认\">合并确认</a>**").append(" ") | |
| 610 | 610 | .append("**<a href=\"#\" data-action=\"reset\" data-text=\"取消\">取消</a>**"); |
| 611 | 611 | } |
| 612 | 612 | |
| ... | ... | @@ -847,6 +847,12 @@ public class DynamicToolProvider implements ToolProvider { |
| 847 | 847 | String sBizContent = meta.getSBizContent(); |
| 848 | 848 | Integer iBizType = meta.getIBizType(); |
| 849 | 849 | args.put("sUserId",session.getUserId()); |
| 850 | + args.put("sLoginId",session.getUserName()); | |
| 851 | + args.put("sMakePerson",session.getUserName()); | |
| 852 | + args.put("sBrId",session.getSBrandsId()); | |
| 853 | + args.put("sBrandsId",session.getSBrandsId()); | |
| 854 | + args.put("sSuId",session.getSSubsidiaryId()); | |
| 855 | + args.put("sSubsidiaryId",session.getSSubsidiaryId()); | |
| 850 | 856 | if(iBizType==1 || iBizType==4){ |
| 851 | 857 | Map<String,Object> data = new HashMap<>(args); |
| 852 | 858 | data.put("sData", JSONObject.toJSONString(data)); |
| ... | ... | @@ -910,7 +916,7 @@ public class DynamicToolProvider implements ToolProvider { |
| 910 | 916 | String sUrl = meta.getSendUrl(); |
| 911 | 917 | Map<String,Object> sBody = new HashMap<>(); |
| 912 | 918 | sBody.put("pageNum",1); |
| 913 | - sBody.put("pageSize",5); | |
| 919 | + sBody.put("pageSize",10000); | |
| 914 | 920 | log.info("doGetFromData========================"); |
| 915 | 921 | List<Map<String,Object>> list = new ArrayList<>(); |
| 916 | 922 | if(ObjectUtil.isNotEmpty(args)){ | ... | ... |
src/main/java/com/xly/tts/bean/TTSRequestDTO.java
| ... | ... | @@ -6,6 +6,9 @@ import lombok.Data; |
| 6 | 6 | public class TTSRequestDTO { |
| 7 | 7 | private String text; |
| 8 | 8 | private String userid; |
| 9 | + private String username; | |
| 10 | + private String brandsid; | |
| 11 | + private String subsidiaryid; | |
| 9 | 12 | private String usertype; |
| 10 | 13 | private String authorization; |
| 11 | 14 | private String voice = "zh-CN-XiaoxiaoNeural"; | ... | ... |
src/main/java/com/xly/tts/service/PythonTtsProxyService.java
| ... | ... | @@ -71,9 +71,14 @@ public class PythonTtsProxyService { |
| 71 | 71 | //调用AI返回请求内容 |
| 72 | 72 | String userInput = request.getText(); |
| 73 | 73 | String sUserId = request.getUserid(); |
| 74 | + String sUserName = request.getUsername(); | |
| 75 | + String sBrandsId = request.getBrandsid(); | |
| 76 | + String sSubsidiaryId = request.getSubsidiaryid(); | |
| 74 | 77 | String sUserType = request.getUsertype(); |
| 75 | 78 | String authorization = request.getAuthorization(); |
| 76 | - AiResponseDTO voiceText = xlyErpService.erpUserInput(userInput,sUserId,sUserType, authorization); | |
| 79 | + //校验登录token 是否有效 | |
| 80 | + | |
| 81 | + AiResponseDTO voiceText = xlyErpService.erpUserInput(userInput,sUserId,sUserName,sBrandsId,sSubsidiaryId,sUserType, authorization); | |
| 77 | 82 | return synthesizeStreamAi(request,voiceText); |
| 78 | 83 | } |
| 79 | 84 | |
| ... | ... | @@ -87,12 +92,16 @@ public class PythonTtsProxyService { |
| 87 | 92 | public ResponseEntity<TTSResponseDTO> init(TTSRequestDTO request) { |
| 88 | 93 | //调用AI返回请求内容 |
| 89 | 94 | String sUserId = request.getUserid(); |
| 95 | + String sUserName = request.getUsername(); | |
| 96 | + String sBrandsId = request.getBrandsid(); | |
| 97 | + String sSubsidiaryId = request.getSubsidiaryid(); | |
| 90 | 98 | String sUserType = request.getUsertype(); |
| 91 | 99 | String authorization = request.getAuthorization(); |
| 100 | + | |
| 92 | 101 | //清空记忆 |
| 93 | 102 | userSceneSessionService.cleanUserSession(sUserId); |
| 94 | 103 | // xlyErpService.initSceneGuide(sUserId,sUserType,StrUtil.EMPTY) |
| 95 | - AiResponseDTO voiceText = xlyErpService.initSceneGuide(StrUtil.EMPTY,sUserId,sUserType, authorization); | |
| 104 | + AiResponseDTO voiceText = xlyErpService.initSceneGuide(StrUtil.EMPTY,sUserId,sUserName,sBrandsId,sSubsidiaryId,sUserType, authorization); | |
| 96 | 105 | voiceText.setSReturnType(ReturnTypeCode.HTML.getCode()); |
| 97 | 106 | return synthesizeStreamAi(request,voiceText); |
| 98 | 107 | } | ... | ... |
src/main/resources/templates/chat.html
| ... | ... | @@ -463,6 +463,9 @@ |
| 463 | 463 | let sessionId =""; |
| 464 | 464 | // let userid= "17706006510007934913359242990000"; |
| 465 | 465 | let userid= "17502321750004978169421209637000"; |
| 466 | + let username= "admin"; | |
| 467 | + let brandsid= "1111111111"; | |
| 468 | + let subsidiaryid= "1111111111"; | |
| 466 | 469 | let usertype= "sysadmin"; |
| 467 | 470 | // let usertype= "General"; |
| 468 | 471 | let authorization="1EDB99C9BF070115F7A57AC43D8CB09F0B8C49F979DAB63A2AEA84B372B2B42BF3419238942A93E9AD666629E18D159AF7FE144A6407DE745BA0AEC8B235FC1D2D86C92E4DCE571A8ECF0767494BBDE2495FD8E662F2065F9430347C7E4472B5538155B7ADAEE71E899235DC1122F426"; |
| ... | ... | @@ -531,6 +534,9 @@ |
| 531 | 534 | const data = { |
| 532 | 535 | text: "", |
| 533 | 536 | userid: userid, |
| 537 | + username: username, | |
| 538 | + brandsid: brandsid, | |
| 539 | + subsidiaryid: subsidiaryid, | |
| 534 | 540 | // usertype: "General", |
| 535 | 541 | usertype: usertype, |
| 536 | 542 | authorization: authorization, | ... | ... |