欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java中使用Jedis连接Redis对String进行操作的常用命令

程序员文章站 2022-06-17 21:52:11
场景 Centos中Redis的下载编译与安装(超详细): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103967334 Redis的启动和关闭(前台启动和后台启动): https://blog.csdn.net/BADAO_ ......

场景

centos中redis的下载编译与安装(超详细):

https://blog.csdn.net/badao_liumang_qizhi/article/details/103967334

redis的启动和关闭(前台启动和后台启动):

https://blog.csdn.net/badao_liumang_qizhi/article/details/103972348

redisdesktopmanager客户端可视化工具下载安装与使用:

https://blog.csdn.net/badao_liumang_qizhi/article/details/103983147

java中使用jedis连接redis对key进行操作的常用命令:

https://blog.csdn.net/badao_liumang_qizhi/article/details/104915569

参考上面对key进行操作的命令后,下面是对string进行常用操作。

注:

博客:

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

新建junit方法teststring,然后依次打开以下注释代码

    @test
    public void teststring()
    {
        //system.out.println("增加数据key1-value1"+jedis.set("key1","value1"));
        //system.out.println("增加数据key2-value2"+jedis.set("key2","value2"));
        //system.out.println("增加数据key3-value3" + jedis.set("key3", "value3"));
        //system.out.println("删除数据key3"+jedis.del("key3"));
        //system.out.println("获取数据key2"+jedis.get("key2"));
        //system.out.println("在key2后面追加值"+jedis.append("key2","append"));
        //system.out.println("在key2后面追加值"+jedis.append("key2","append"));
        //system.out.println("增加多个键值:" + jedis.mset("key01", "value01", "key02", "value02", "key03", "value03"));
        //system.out.println("获取多个键值:" + jedis.mget("key01", "key02", "key03"));
        //system.out.println("删除多个键值:"+jedis.del("key02","key03"));

        //新增键值对防止覆盖原先值
        //输出1
        //system.out.println(jedis.setnx("key4","badao"));
        //输出0
        //system.out.println(jedis.setnx("key4","liumang"));
        //输出badao
        //system.out.println(jedis.get("key4"));

        //新增键值对并设置有效时间--5秒
        //system.out.println(jedis.setex("key5",5,"liumang"));

        //获取原值并更新为新值
        system.out.println(jedis.getset("key4","key4getset"));
        system.out.println(jedis.get("key4"));
    }