Redis相關操作

2021-10-05 08:40:33 字數 3659 閱讀 5707

set key value [ex seconds] [px milliseconds] [nx|xx]

ex seconds:為鍵設定秒級過期時間

px milliseconds:為鍵設定毫秒級過期時間

nx:鍵必須不存在,才可以設定成功,用於新增

xx:鍵必須存在,才可以設定成功,用於更新

public class redislock 

public redislock(int selectdb, string key)

public redislock(string key, long leasetime)

public redislock(int selectdb, string key, long leasetime)

public void lock()

try

if (suplustime == -2)

continue;

if (suplustime > 0)

}} catch (exception e) finally

}private long trylock(jedis jedis, string key) throws exception else

if (suplustime == -1)

if (suplustime > 0)

}return 0;

}public void unlock()

try

} catch (exception e) finally

}}

public class redisutil 

public static void putmap(int selectdb, string key, map<?, ?> map)

public static void putmap(jedis jedis, string key, map<?, ?> map) ", key);

return;

}mapnewmap = new hashmap<>();

try catch (jsonprocessingexception e)

});if (newmap.size() > 0)

} finally

}/**

* 獲取map

** @param * @param key

* @return

*/public static mapgetmap(string key, classk, typereferencev)

public static mapgetmap(int selectdb, string key, classk, typereferencev)

public static mapgetmap(jedis jedis, string key, classk, typereferencev) ", key);

return null;

}mapresultmap = new hashmap<>();

try catch (ioexception e) }}

} finally

return resultmap;

}/**

* 判斷字段是否存在 key 指定的雜湊集中。

** @param key

* @param field

* @return

*/public static boolean i***istfieldinhashmap(string key, object field)

public static boolean i***istfieldinhashmap(int selectdb, string key, object field)

public static boolean i***istfieldinhashmap(jedis jedis, string key, object field) , fiels:{}", key, field);

return false;

}try catch (jsonprocessingexception e) finally

return false;

}/**

* 獲取雜湊集中指定的key。

** @param key

* @param field

* @return

*/public static v getvalueinhashmap(string key, object field, typereferencev)

public static v getvalueinhashmap(int selectdb, string key, object field, typereferencev)

public static v getvalueinhashmap(jedis jedis, string key, object field, typereferencev) , field:{}", key, field);

return null;

}try

return null;

} catch (ioexception e) finally

return null;

}/**

* 更新雜湊集中指定的key的value。

** @param key

* @param field

* @return

*/public static void setvalueinhashmap(string key, object field, object v)

public static void setvalueinhashmap(int selectdb, string key, object field, object v)

public static void setvalueinhashmap(jedis jedis, string key, object field, object v) , field:{}", key, field);

return;

}try catch (jsonprocessingexception e) finally

}/**

* 移除雜湊集中指定的key

** @param key

* @param field

* @return

*/public static void removekeyinhashmap(string key, object... fields)

public static void removekeyinhashmap(int selectdb, string key, object... fields)

public static void removekeyinhashmap(jedis jedis, string key, object... fields)

if(jedis == null) , fields:{}", key, stringutils.join(fields, ";"));

return;

}try

long rtn = jedis.hdel(key, delfieldjsons);

} catch (jsonprocessingexception e) finally

}}

redis相關操作

字串操作 列表操作 有序,重複 左新增 lpush websites baidu.com 右新增 rpush websites google.com 左移除 lpop websites 右移除 rpop websites 指定元素移除 lrem websites count google.com c...

Redis 相關操作命令

本來想搞個桌布的,不但放不下還非常醜 命令說明 select 下標 選擇下標所處的資料庫 dbsize 檢視當前資料庫的鍵數量 flushdb 清空當前db flushall 清空所有的db 命令說明 keys 匹配符 匹配符有 和 代表了乙個字元,號代表了n個字元!exists 鍵名 是否存在這個...

Redis相關操作命令

解壓安裝後編譯 localhost redis 3.0.0 make 編譯後 localhost redis 3.0.0 make install prefix usr local redis 啟動 localhost redis 3.0.0 cd bin localhost bin redis s...