首页 \ 问答 \ redis是怎么存储数据的

redis是怎么存储数据的

正常应该事从redis查,如果没有就去数据库查询, 那么redis里边的数据哪儿来的?认为写进去还是自动的
更新时间:2023-06-22 16:06

最满意答案

参考我下面的程序, 可以通过修改宏定义 M 来修改发送的数字 M

#include 

 
#include 
 


  #define M 6

int main()
{
    int pipefd[2];
    int pid;
    int m;

    if (pipe(pipefd) < 0)
    {
        printf("Unable to create pipe!\n");
        return 1;
    }

    pid = fork();

    if (pid > 0) //parent
    {
        m = M;
        close(pipefd[0]); //close read end
        write(pipefd[1], &m, sizeof(int)); //write M
        wait(NULL); // wait for child complete
        close(pipefd[1]);
    }
    else if (pid == 0)
    {
        close(pipefd[1]);
        read(pipefd[0], &m, sizeof(int)); //read M
        while(m>0)
        {
            printf("Hello world.\n");
            m--;
        }
        close(pipefd[0]);
    }
    else
    {
        printf("Unable to fork!\n");
        return 1;
    }

    return 0;
}
 

其他回答

没看懂什么意思?

相关问答

更多
  • 到Ubuntu的中文去学习吧,学习只能靠自己: http://forum.ubuntu.org.cn/
  • man waitpid WIFEXITED(status) returns true if the child terminated normally, that is, by calling exit(3) or _exit(2), or by returning from main(). WEXITSTATUS(status) returns the exit status of the child. This consists of the least significant 16-8 bits of ...
  • 参考我下面的程序, 可以通过修改宏定义 M 来修改发送的数字 M #include #include #define M 6 int main() { int pipefd[2]; int pid; int m; if (pipe(pipefd) < 0) { printf("Unable to create pipe!\n"); return 1; } pid = fork(); if (pid > 0) //parent { m = M; close(pipefd[0]); //close read e ...
  • 你可以装“Ubuntu10.04” 你可以到百度视屏里找安装教程。 还可以先看一下效果,非常漂亮,比win7漂亮多了。 我当时看了一下,有一种惊艳的感觉,太漂亮了。 安装也简单,唯一一点就是,我的英语不好,还需要学习学习,再用。 告别windows盗版系统。
  • //这个是我学Unix C++时对知识点总结程序,应该对你有些用吧。 /* istream ostream | \ / | ifstream iostream ofstream | fstream */ #include #include using namespace std; int main() { char ch[6]; cout << "Input a line: "; ch[5] = cin.peek(); cout << "Peek first char: " << ch[5] << endl ...
  • UNIX是一个功能强大、性能全面的多用户、多任务操作系统,可以应用从巨型计算机到普通PC机等多种不同的平台上,是应用面最广、影响力最大的操作系统。 Linux是一种外观和性能与UNIX相同或更好的操作系统,但,Linux不源于任何版本的UNIX的源代码,并不是UNIX,而是一个类似于UNIX的产品。Linux产品成功的模仿了UNIX系统和功能,具体讲Linux是一套兼容于System V以及BSD UNIX的操作系统,对于System V来说,目前把软件程序源代码拿到Linux底下重新编译之后就可以运行,而 ...
  • 它会打印它2 ^ 3 = 8次。 请记住,每次调用fork时,都会创建一个子进程,该子进程会在分叉后继续执行,因此它本身也可以分叉。 树会看起来像这样。 First process. Forked1 Forked2 Forked3 叉形4 ---叉形5 --------------叉形6 Forked7 因此,我们将共有8个进程(主进程和7个分叉进程)运行并打印该打印语句。 作为一个方面说明:如果print语句在fork之前 ...
  • 在父进程中调用waitpid之前,必须关闭不需要的管道中的所有文件描述符。 这些是: pid_a filedes[0]在pid_a filedes[1]在pid_b 父进程中的filedes[0]和filedes[1] 你还应该检查pipe()和fork()没有返回-1 ,这意味着发生了一个错误。 Before calling waitpid in the parent process you have to close all file descriptors from the pipe that you ...
  • 使用printf ,输出将被缓冲。 所以,在printf之后做一个fflush或\n 。 添加fflush或\n虽然强制刷新缓冲区并输出到屏幕。 这发生在前叉之前,因此只打印一次。 C99 7.19.2p2 最后一行是否需要终止换行符是实现定义的。 它没有定义如果没有提供终止换行字符会发生什么。 由于标准未定义行为,因此行为未定义。 When you use printf, the output is buffered. So, do a fflush or \n right after printf. A ...
  • 当fork()保留argv[1]时,为什么要通过管道写文件名? 您没有根据缓冲区长度检查读取长度。 你没有传输尾随的nul( strlen()不包括它)所以buffer的文件名字符串的终结符是未初始化的。 在所有strlen()值上附加+1以更正它。 然后, execl("/bin/cat","cat",buffer,(char*)0); 会做你要求的,但是你已经关闭stdout所以cat (而不是execl )会失败,你没有检查它的退出代码。 Why are you writing the filena ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。