redis 命令行密码登录, jedis 基本操作, INCRBY key increment,报错WRONGTYPE Operation

redis 命令行密码登录

  redis-cli -h [ip] -p [port]
  auth [password]

jedis 常用操作 [来源]

  System.out.println("判断某个键是否存在:"+jedis.exists("username"));
  System.out.println("新增<'username','wukong'>的键值对:"+jedis.set("username", "wukong"));
  System.out.println("设置键username的过期时间为5s:"+jedis.expire("username", 5));
  System.out.println("移除键username的生存时间:"+jedis.persist("username"));
  System.out.println("查看键username的剩余生存时间:"+jedis.ttl("username"));
  System.out.println("查看键username所存储的值的类型:"+jedis.type("username"));

  // NX是不存在时才set, XX是存在时才set, EX是秒,PX是毫秒
  jedisCluster.set("11", value, SetParams.setParams().nx().ex(10));

  System.out.println("===========添加一个list===========");
  jedis.lpush("collections", "ArrayList", "Vector", "Stack", "HashMap", "WeakHashMap", "LinkedHashMap");
  jedis.lpush("collections", "HashSet");
  System.out.println("collections的内容:"+jedis.lrange("collections", 0, -1));//-1代表倒数第一个元素,-2代表倒数第二个元素
  System.out.println("collections列表出栈(左端):"+jedis.lpop("collections"));
  System.out.println("删除下表0-3区间之外的元素:"+jedis.ltrim("collections", 0, 3));
  // 删除列表指定的值 ,第二个参数为删除的个数(有重复时),后add进去的值先被删,类似于出栈
  System.out.println("删除指定元素个数:"+jedis.lrem("collections", 2, "HashMap"));
  System.out.println("collections的长度:"+jedis.llen("collections"));
  System.out.println("获取collections下标为2的元素:"+jedis.lindex("collections", 2));

INCRBY key increment [来源]

为键 key 储存的数字值加上增量 increment 。
如果键 key 不存在, 那么键 key 的值会先被初始化为 0 , 然后再执行 INCRBY 命令。
如果键 key 储存的值不能被解释为数字, 那么 INCRBY 命令将返回一个错误。
本操作的值限制在 64 位(bit)有符号数字表示之内。

Redis报错:WRONGTYPE Operation against a key holding the wrong kind of value 解决处理

jedis方法与redis服务器中存储数据的类型存在冲突。
type key 查看类型,然后使用与类型对应的方法

posted @ 2021-02-09 15:54  CalronLoveRonnie  阅读(471)  评论(0编辑  收藏  举报
AmazingCounters.com