Login
网站首页 > 文章中心 > 其它

Redis_七):RedisTemplate 操作API

作者:小编 更新时间:2023-10-22 18:29:17 浏览量:112人看过

第一段:scan

SCAN 命令用于迭代当前数据库中的数据库键.

Redis_七):RedisTemplate 操作API-图1

SSCAN 命令用于迭代集合键中的元素.

HSCAN 命令用于迭代哈希键中的键值对.

ZSCAN 命令用于迭代有序集合中的元素(包括元素成员和元素分值).

① 数据库基本命令

①.)扫描所有数据表



//1. 一次性获取Real_Gps中数据  
Map map1 =redisTemplate.opsForHash().entries("Real_Gps");

//2. 使用Scan方式遍历获取Real_Gps中的数据   
ScanOptions scanOptions = ScanOptions.scanOptions().count(1).match("*").build();  
Cursor> cursor = redisTemplate.opsForHash().scan("Real_Gps", scanOptions);  
while(cursor.hasNext()) {  
Map.Entry entry = cursor.next();  
entry.getValue();  
}  

第二段:HashMap

public class RedisUtil {
/*
 */

private RedisTemplate redisTemplate;

/**
 * @param key
 * @param hashKey
 * @return
 */
public Object get(Object key, Object hashKey){
    return redisTemplate.opsForHash().get(key, hashKey);
/**
 * @param key
 * @param hashKeys
 * @return
 */
public List multiGet(Object key, Collection hashKeys){
    return redisTemplate.opsForHash().multiGet(key, hashKeys);
/**
 * @param key
 * @param hashKey
 * @param value
 */
public void put(Object key, Object hashKey, Object value){
/**
 * @param key
 * @param map
 */
public void putAll(Object key, Map map){
/**
 * @param key
 * @param hashKey
 * @param value
 * @return
 */
public Boolean putIfAbsent(Object key, Object hashKey, Object value){
    return redisTemplate.opsForHash().putIfAbsent(key, hashKey, value);
/**
 * @param key
 * @param item
 * @return
 */
public Long delete(Object key, Object... item){
    return redisTemplate.opsForHash().delete(key, item);
/**
 * @param key
 * @param hashKey
 * @return
 */
public Boolean hasKey(Object key, Object hashKey){
    return redisTemplate.opsForHash().hasKey(key, hashKey);
/**
 * @param key
 * @return
 */
public Map entries(Object key){
    return redisTemplate.opsForHash().entries(key);
/**
 * @param key
 * @param hashKey
 * @param delta
 * @return
 */
public Long increment(Object key, Object hashKey, long delta){
    return redisTemplate.opsForHash().increment(key, hashKey, delta);
/**
 * @param key
 * @param hashKey
 * @param delta
 * @return
 */
public Double increment(Object key, Object hashKey, double delta){
    return redisTemplate.opsForHash().increment(key, hashKey, delta);
/**
 * @param key
 * @return
 */
public Set keys(Object key){
    return redisTemplate.opsForHash().keys(key);
/**
 * @param key
 * @return
 */
public List values(Object key){
    return redisTemplate.opsForHash().values(key);
/**
 * @param key
 * @return
 */
public Long size(Object key){
    return redisTemplate.opsForHash().size(key);
}
}

以上就是土嘎嘎小编为大家整理的Redis_七):RedisTemplate 操作API相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章