• 常用API之string


    public static void main(String[] args) {
            Jedis jedis = new Jedis("127.0.0.1",6379);
            jedis.auth("12345");
    
            System.out.println("==================增加数据==================");
            System.out.println(jedis.set("key1","value1"));
            System.out.println(jedis.set("key2","value2"));
            System.out.println(jedis.set("key3","value3"));
            System.out.println("删除键key2:"+jedis.del("key2"));
            System.out.println("获取键值key2:"+jedis.get("key2"));
            System.out.println("修改key1:"+jedis.set("key1","value1Changed"));
            System.out.println("获取键值key1:"+jedis.get("key1"));
            System.out.println("在key3后面加入值:"+jedis.append("key3","End"));
            System.out.println("获取键值key3:"+jedis.get("key3"));
            System.out.println("增加多个键值对:"+jedis.mset("key01","value01","key02","value02"));
            System.out.println("获取多个键值对:"+jedis.mget("key01","key02","key03"));
            System.out.println("获取多个键值对:"+jedis.mget("key01","key02","key03","key04"));
            System.out.println("删除多个键值对:"+jedis.del("key01","key02","key03"));
            System.out.println("获取多个键值对:"+jedis.mget("key01","key02","key03"));
    
            jedis.flushDB();
            System.out.println("=====================新增键值对防止覆盖原先值=====================");
            System.out.println(jedis.setnx("key1","value1"));
            System.out.println(jedis.setnx("key2","value2"));
            System.out.println(jedis.setnx("key2","value2-new"));
            System.out.println(jedis.get("key1"));
            System.out.println(jedis.get("key2"));
    
            System.out.println("=====================新增键值对并设置有效时间=====================");
            System.out.println(jedis.setex("key3",2,"value3"));
            System.out.println(jedis.get("key3"));
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(jedis.get("key3"));
    
            System.out.println("=====================获取原值,更新为新值=====================");
            System.out.println(jedis.getSet("key2","key2GetSet"));
            System.out.println(jedis.get("key2"));
    
            System.out.println("截取key2的值:"+jedis.getrange("key2",2,4));
        }
    

     

  • 相关阅读:
    div的自动滚动
    异步发送添加请求的客户端实现
    asp.net防止一个用户登录多次的方法
    asp.net ajax动态显示时间
    也谈Javascript的效率,createElement和innerHTML,为innerHTML平反
    精妙MSSql语句
    看看国外做的js效果
    prototype.js常用函数及其用法
    PPTP 服务器配置
    Linux date 命令使用技巧
  • 原文地址:https://www.cnblogs.com/zz-newbie/p/15090857.html
Copyright © 2020-2023  润新知