| | |
| | | package com.hx.redis; |
| | | |
| | | import org.junit.Before; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | import redis.clients.jedis.Jedis; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * hash 删除操作 |
| | | * |
| | | * @param key 键 |
| | | * @param valueKey 值 |
| | | * @return true成功 false 失败 |
| | | */ |
| | | public boolean hashDel(String key, Object... valueKey) { |
| | | try { |
| | | redisTemplate.opsForHash().delete(key,valueKey); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * hash 设置hashMapt操作 |
| | | * |
| | | * @param key 键 |
| | | * @return true成功 false 失败 |
| | | */ |
| | | public boolean hashSetMap(String key, Map<String,Object> map) { |
| | | try { |
| | | redisTemplate.opsForHash().putAll(key, map); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * hash 设置单个hashMap操作 |
| | | * |
| | | * @param key 键 |
| | | * @return true成功 false 失败 |
| | | */ |
| | | public boolean hashSet(String hashKey, String key, Object value) { |
| | | try { |
| | | redisTemplate.opsForHash().put(hashKey,key,value); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | } |