zoukankan      html  css  js  c++  java
  • redis实践 —— redisReply简析

    redisReply 定义如下:

    /* This is the reply object returned by redisCommand() */
    typedef struct redisReply {
        int type; /* 返回值类型 */
        long long integer; /* 当返回类型为 REDIS_REPLY_INTEGER 时 */
        size_t len; /* 返回的字符串长度 */
        char *str; /* 当返回值类型为 REDIS_REPLY_ERROR 和 REDIS_REPLY_STRING */
        size_t elements; /* 返回的数组长度 */
        struct redisReply **element; /* 当返回值类型为 REDIS_REPLY_ARRAY */
    } redisReply;

    type 有以下几种类型:

      REDIS_REPLY_STRING  : 1 
      REDIS_REPLY_ARRAY : 2
      REDIS_REPLY_INTEGER :3 
      REDIS_REPLY_NIL  : 4
      REDIS_REPLY_STATUS : 5
      REDIS_REPLY_ERROR : 6

    如:

    _reply = static_cast<redisReply *>(redisCommand(_context, "SETNX  test 1");

    此时 _reply->type 为 REDIS_REPLY_INTEGER ,且值存放在 _reply->integer 中。
    _reply = static_cast<redisReply *>(redisCommand(_context, "GET  test");

    此时 _reply->type 为 REDIS_REPLY_STATUS,且值存放在 _reply->str 中。("OK")

    具体的返回值和返回类型与 redis 相关命令相同。

  • 相关阅读:
    JavaScript 实现深度拷贝
    JacaScript arguments
    EMACS 使用入门
    ubuntu 14.04 nginx + mysql + php源码安装
    c语言 头文件
    程序员技术练级攻略
    if和switch的选择
    .htaccess (分布式配置文件)
    yii2 windows 安装过程
    Js 冒泡事件阻止
  • 原文地址:https://www.cnblogs.com/qing2019/p/11627682.html
Copyright © 2011-2022 走看看