zoukankan      html  css  js  c++  java
  • redis相关

    安装与使用 见 
    http://www.runoob.com/redis/redis-install.html runoob
    ♦♦https://www.cnblogs.com/ym65536/p/7077216.html 编译加+make分析+目录文件分析

    查看redis版本:redis-server –version 和 redis-server -v 

    修改redis端口号:
    为redis分配一个8888端口,操作步骤如下:
    1、$REDIS_HOME/redis.conf重新复制一份,重命名为redis8888.conf。
    2、打开redis8888.conf配置文件,找到port 6379这行,把6379改为8888。
    3、把redis8888.conf移到$REDIS_HOME/redis-svrs/taobaoAny目录下(taobaoAny为自己新建)。
    4、启动redis服务:redis-server /home/redis/redis-2.4.15/redis-svrs/taobaoAny/redis8888.conf &
    5、通过“ps -x | grep redis”查看进程,在输出的信息中会看到/home/redis/redis-2.4.15/redis-svrs/taobaoAny/redis8888.conf
    6、redis-cli -p 8888, 测试端口是否创建成功。

    Redis设计与实现
    媲美 scip,apue,unp,csapp,clrs,aocp 

    Redis C API接口的调用
     1 1、hiredis是redis数据库的C接口,目录为/redis-3.2.6/deps/hiredis
     2 2、示例代码如下:
     3     #include <stdio.h>
     4     #include <stdlib.h>
     5     #include <stddef.h>
     6     #include <stdarg.h>
     7     #include <string.h>
     8     #include <assert.h>
     9     #include "hiredis.h"
    10     
    11     int main()
    12     {
    13         //连接redis
    14         redisContext* c = redisConnect("127.0.0.1", 6379);
    15         if ( c->err)
    16         {
    17             redisFree(c);
    18             printf("Connect to redisServer faile
    ");
    19             return -1;
    20         }
    21         printf("Connect to redisServer Success
    ");
    22         
    23         const char* setCommand = "set name andy";
    24         redisReply* r = (redisReply*)redisCommand(c, setCommand);
    25         
    26         if( NULL == r)
    27         {
    28             printf("Execut setCommand failure
    ");
    29             redisFree(c);
    30             return -1;
    31         }
    32         if( !(r->type == REDIS_REPLY_STATUS && strcasecmp(r->str,"OK")==0))
    33         {
    34             printf("Failed to execute command[%s]
    ",setCommand);
    35             freeReplyObject(r);
    36             redisFree(c);
    37             return -1;
    38         }
    39         freeReplyObject(r);
    40         printf("Succeed to execute command[%s]
    ", setCommand);
    41         
    42         
    43         const char* getCommand = "get name";
    44         r = (redisReply*)redisCommand(c, getCommand);
    45         if ( r->type != REDIS_REPLY_STRING)
    46         {
    47             printf("Failed to execute command[%s]
    ",getCommand);
    48             freeReplyObject(r);
    49             redisFree(c);
    50             return -1;
    51         }
    52         printf("Succeed to execute command[%s]
    ", getCommand);
    53         printf("The value of 'name' is %s
    ", r->str);
    54         freeReplyObject(r);
    55         
    56         redisFree(c);
    57         return 0;
    58     }
    59 3、编译,运行如下:
    60     [root@localhost hiredis]# g++ -o main main.cpp libhiredis.a
    61     [root@localhost hiredis]# ./main
    62     Connect to redisServer Success
    63     Succeed to execute command[set name andy]
    64     Succeed to execute command[get name]
    65     The value of 'name' is andy
    View Code

      ps -ef | grep procedure_name | grep -v grep | awk '{print $2}' | xargs kill -9

      远程连接redis时,提示
      [root@localhost src]# redis-cli -h 10.9.139.171 -p 6379
      Could not connect to Redis at 10.9.139.171:6379: Connection refused

      原来是server端,默认是bind 127.0.0.1,注释掉 重启即可。

      [root@localhost src]# redis-cli -h 10.9.139.171 -p 6379
      10.9.139.171:6379>

     ==================================================================

     redis持久化摘自:https://blog.csdn.net/liqingtx/article/details/60330555

    【聊聊redis持久化 – 两种方式】

    redis提供了两种持久化的方式,分别是RDB(Redis DataBase)和AOF(Append Only File)。

    RDB,简而言之,就是在不同的时间点,将redis存储的数据生成快照并存储到磁盘等介质上;

    AOF,则是换了一个角度来实现持久化,那就是将redis执行过的所有写指令记录下来,在下次redis重新启动时,只要把这些写指令从前到后再重复执行一遍,就可以实现数据恢复了。

    其实RDB和AOF两种方式也可以同时使用,在这种情况下,如果redis重启的话,则会优先采用AOF方式来进行数据恢复,这是因为AOF方式的数据恢复完整度更高。

    如果你没有数据持久化的需求,也完全可以关闭RDB和AOF方式,这样的话,redis将变成一个纯内存数据库,就像memcache一样。

    ===================================================================

    https://www.cnblogs.com/wujuntian/p/9218961.html

    Redis的内部运作机制 

    本文将分五个部分来分析和总结Redis的内部机制,分别是:Redis数据库、Redis客户端、Redis事件、Redis服务器的初始化步骤、Redis命令的执行过程。

    ===================================================================

    save

    od -c dump.rdb

    127.0.0.1:6379> help flushall     //help command
    HISTORY: /home/yangpeng/.rediscli_history

    FLUSHALL -
    summary: Remove all keys from all databases
    since: 1.0.0
    group: server

  • 相关阅读:
    November 13th 2016 Week 47th Sunday The 1st Day
    November 12th 2016 Week 46th Saturday
    November 11th 2016 Week 46th Friday
    November 10th 2016 Week 46th Thursday
    November 9th 2016 Week 46th Wednesday
    November 8th 2016 Week 46th Tuesday
    windows 7文件共享方法
    Win7无线网络共享设置方法
    常量指针和指针常量
    如何查找局域网的外网ip
  • 原文地址:https://www.cnblogs.com/cjyp/p/10006582.html
Copyright © 2011-2022 走看看