redis之简单存取操作

注入
@Autowired
private StringRedisTemplate stringRedisTemplate;

HASH:

    one

    save

 
 
创建操作对象
HashOperations<String, String, String> accountingCache = stringRedisTemplate.opsForHash();
构造数据
value.put("acntDeptId",acntDeptId);
value.put("accounting",accounting);
value.put("accounting1",accounting1);
String _key = new StringBuffer("accounting_").append(orderChangeId).toString();
HashMap<String, String> value = new HashMap<>();
value.put("acntDeptId",acntDeptId);
value.put("accountingCode"+accountingCode,accountingCode);
value.put("accountingCode"+accountingCode1,accountingCode1);
数据存入redis 设置超时时间
accountingCache.putAll(_key,value);
accountingCache.getOperations().expire(_key,10,TimeUnit.HOURS);

    get

HashOperations<String, String, String> accountingCache = stringRedisTemplate.opsForHash();
String _key = new StringBuffer("accounting_").append(fltOrderRech.getOrderRechId()).toString();
Map<String, String> entries = accountingCache.entries(_key);//获取数据
============================================================================




猜你喜欢

转载自blog.csdn.net/qq_18259357/article/details/80279051