1.Sno报错关于字段和引包的锅2.知识,3.Redis工具类+nacos配置4.oracel和mysql用sql分页

本文探讨了数据库如何通过TCP/IP协议与应用程序交互,解释了数据库对SQL92查询标准协议的支持。同时,提到了在实际应用中,如oracel和mysql使用SQL进行分页查询的场景。
摘要由CSDN通过智能技术生成

在这里插入图片描述
2.
大家在写应用程序查询数据库时,并没有考虑过为什么可以将查询结果返回给上层的应用程序,甚至认为,这就是数据库应该做的,其实不然,这是数据库通过TCP/IP协议与另一个应用程序进行交流的结果,而上层是什么样的应用程序,是用什么语言,数据库本身并不知道,它只知道接收到了一份协议,这就是SQL92查询标准协议。
3.

package cn.***.***.**.biz.****.****.utils;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

@Component
public final class RedisUtil {
   

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    public Set<String> keys(String keys) {
   
        try {
   
            return redisTemplate.keys(keys);
        } catch (Exception e) {
   
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 指定缓存失效时间
     * 
     * @param key
     *            键
     * @param time
     *            时间(秒)
     * @return
     */
    public boolean expire(String key, long time) {
   
        try {
   
            if (time > 0) {
   
                redisTemplate.expire(key, time, TimeUnit.SECONDS);
            }
            return true;
        } catch (Exception e) {
   
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 根据key 获取过期时间
     * 
     * @param key
     *            键 不能为null
     * @return 时间(秒) 返回0代表为永久有效
     */
    public long getExpire(String key) {
   
        return redisTemplate.getExpire(key, TimeUnit.SECONDS);
    }

    /**
     * 判断key是否存在
     * 
     * @param key
     *            键
     * @return true 存在 false不存在
     */
    public boolean hasKey(String key) {
   
        try {
   
            return redisTemplate.hasKey(key);
        } catch (Exception e) {
   
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 删除缓存
     * 
     * @param key
     *            可以传一个值 或多个
     */
    @SuppressWarnings("unchecked")
    public void del(String... key) {
   
        if (key != null && key.length > 0) {
   
            if (key.length == 1) {
   
                redisTemplate.delete(key[0]);
            } else {
   
                redisTemplate.delete((Collection<String>)CollectionUtils.arrayToList(key));
            }
        }
    }

    /**
     * 普通缓存获取
     * 
     * @param key
     *            键
     * @return 值
     */
    public Object get(String key) {
   
        return key == null ? null : redisTemplate.opsForValue().get(key);
    }

    /**
     * 普通缓存放入
     * 
     * @param key
     *            键
     * @param value
     *            值
     * @return true成功 false失败
     */
    public boolean set(String key, Object value) {
   
        try {
   
            redisTemplate.opsForValue().set(key, value);
            return true;
        } catch (Exception e) {
   
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 普通缓存放入, 不存在放入,存在返回
     * 
     * @param key
     *            键
     * @param value
     *            值
     * @return true成功 false失败
     */
    public boolean setnx(String key, Object value) {
   
        try {
   
            redisTemplate.opsForValue().setIfAbsent(key, value);
            return true
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值