在redistemplate中提供了幾個常用的介面方法的使用,分別是:
valueoperationsprivate valueoperationsvalueops;
private listoperationslistops;
private setoperationssetops;
private zsetoperationszsetops;
這個介面的實現類為:defaultvalueoperations.
在redistemplate中,已經提供了乙個工廠方法:opsforvalue()。這個方法會返回乙個預設的操作類。另外,我們可以直接通過註解@resource(name = 「redistemplate」)來進行注入。
這個介面並沒有定義成員變數,但是直接提供了方法。//宣告
@resource(name = "redistemplate")
private redistemplatetemplate;
//呼叫方法
template.opsforvalue().set("key","value");
public hashoperationsopsforhash()
方法2//注入hashoperations物件
@resource(name = "redistemplate")
private hashoperationshashops;
//具體呼叫
mapmap = new hashmap();
map.put("value","code");
map.put("key","keyvalue");
hashops.putall("hashops",map);
//注入redistemplate物件
@resource(name = "redistemplate")
private redistemplatetemplate;
//具體呼叫
mapmap = new hashmap();
map.put("value","code");
map.put("key","keyvalue");
template.opsforhash().putall("hashops",map);
RedisTemplate操作Redis常用
redistemplate中定義了對5種資料結構操作 redistemplate.opsforvalue 操作字串 redistemplate.opsforhash 操作hash redistemplate.opsforlist 操作list redistemplate.opsforset 操作se...
redistemplate事務實踐
code public object testredismulti catch interruptedexception e now string operations.opsforvalue get testredismulti system.out.println now object rs o...
RedisTemplate快取用法小記
2 redis的引用包 org.springframework.data spring data redis 1.8.6.release 3 redistemplate裡面有如下幾種常用的形式 1 string型別 redistemplate.opsforvalue 2 list型別 rediste...