Skip to content

ERR unknown command 'cat' #1039

Closed
Closed

Description

@subhash-rajapaksha

redisReply *reply;
redisContext *c = redisConnect("127.0.0.1", 6379);
reply = redisCommand(c, "cat redisMassDataLoader.txt | redis-cli --pipe");

this is my code and the text file (redisMassDataLoader.txt) contains,
"*3\r\n$3\r\nSET\r\n$3\r\n123\r\n$5\r\n12345\r\n"
after run this command it gives this Error: ERR unknown command 'cat'
I'm using redis 2.6.12.

please help...

Activity

  1. antirez commented on Apr 8, 2013

    @antirez
    Contributor

    Hello, this is about the hiredis library, not Redis itself, so I'm closing the issue.

    Btw an hint: you can't use redisCommand() like that.

  2. charsyam commented on Apr 8, 2013

    @charsyam
    Contributor

    @subhash-rajapaksha hi guy. you used hiredis in a wrong way.

    just use like this:
    reply = redisCommand(c, "*3\r\n$3\r\nSET\r\n$3\r\n123\r\n$5\r\n12345\r\n");

  3. subhash-rajapaksha commented on Apr 9, 2013

    @subhash-rajapaksha
    Author

    I need to load some what big MYSQL data table to REDIS memory from a C program. To test this I'm using hiredis libraries and a prototype text file which contains this line - "*3\r\n$3\r\nSET\r\n$3\r\n123\r\n$5\r\n12345\r\n".
    (got details from this link - http://redis.io/topics/mass-insert)

    please give me a link for more information, sample code is preferred.

    Thanks for sharing your knowledge....

    This is the code i used which gives errors,

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include "hiredis.h"

    int main(void){

        redisReply *reply;
        long int i;
    
        //      Start measuring time
        clock_t start = clock();
    
        //      For local connections:
        redisContext *c = redisConnect("127.0.0.1", 6379);
    
        if (c->err) {
                printf("Error: %s\n", c->errstr);
        }else{
                printf("Connection Made! \n");
        }
    
        //      Get all keys for testing
        reply = redisCommand(c, "cat data.txt | redis-cli --pipe");
    
        if ( reply->type == REDIS_REPLY_ERROR )
                printf( "Error: %s\n", reply->str );
        else if ( reply->type == REDIS_REPLY_ARRAY )
                printf( "Unexpected type: %d\n", reply->type );
        else {
                printf( "Result:%lu: %s\n", i,reply->str );
        }
    
        printf( "Total Number of Results: %lu\n", i );
        //      Output Elapsed time
        printf ( "%f Seconds\n", ( (double)clock() - start ) /CLOCKS_PER_SEC );
    
        freeReplyObject(reply);
    

    }

  4. charsyam commented on Apr 9, 2013

    @charsyam
    Contributor

    @subhash-rajapaksha if you dump yourl mysql data to data.txt, you don't need to use hiredis
    just use redis-cli like this:

    in shell:
    cat data.txt | redis-cli --pipe

    but if you need to use hiredis.
    open data.txt and read each line, and execute redisCommand in loop.

  5. subhash-rajapaksha commented on Apr 9, 2013

    @subhash-rajapaksha
    Author
    1. Since my requirement is to do the data insertion automatically, i have to use a code and then i have go for hiredis.

    And when reading the file line by line and executing the command, it will take extra time as mentioned in http://redis.io/topics/mass-insert
    (for round trip time for each execution with each reply)

    1. in redis-cli, when the command "cat data.txt | redis-cli --pipe" is run, it gives
      ERR unknown command 'cat'
      Don't know whether this is a configuration issue.

    I'm totally new to Redis ans to hiredis.

    AND THANKS FOR YOUR PROMPT REPLY

  6. badboy commented on Apr 9, 2013

    @badboy
    Contributor

    @subhash-rajapaksha
    You seem to confuse things here.
    redis-cli is a command line tool to interact with redis. It features the --pipe mode to mass-insert data it reads from stdin.
    hiredis is the C library used internally. You can use it to directly send redis commands over the network. You cannot use it to execute shell commands.

    So either you execute redis-cli and pipe the file in (you can do this from within C, too) or you read the file and call redisCommand as said above. To avoid the extra time this can cause use pipelining (a good start would be to read the code of redis-cli)

  7. subhash-rajapaksha commented on Apr 9, 2013

    @subhash-rajapaksha
    Author

    OK,

    I have created a mass insertion prototype data file(text) which contains following data line.

    *3\r\n$3\r\nSET\r\n$3\r\n123\r\n$5\r\n12345\r\n

    then I tried to insert that data to redis memory in redis-cli using below command.

    redis 127.0.0.1:6379> cat redisMassDataLoader.txt | redis-cli --pipe
    (error) ERR unknown command 'cat'

    can somebody explain this then.

  8. badboy commented on Apr 9, 2013

    @badboy
    Contributor

    Execute the cat file.txt | redis-cli --pipe on the shell, NOT IN redis-cli. You should really read a bit about how the shell, redis and the libraries involved work.

  9. subhash-rajapaksha commented on Apr 9, 2013

    @subhash-rajapaksha
    Author

    Finally got it.thanks a lot everybody... :-)

  10. HydTechie commented on Aug 2, 2018

    @HydTechie

    With IP address the error is resolved, as below:
    cat dataload.txt | redis-cli -h -p -c --pipe

    Without IP address this command says "cat" is unknown command.

  11. MilkTeaDrink commented on Nov 22, 2020

    @MilkTeaDrink

    你真的懂了吗?

  12. vikramsalunkhe49 commented on Oct 21, 2022

    @vikramsalunkhe49

    In the file, you can add values like the below and save that file student.txt

    HMSET STUDENT:Id:123 ID "123" NAME"JONE DOE"
    HMSET STUDENT:Id:121 ID "121" NAME"JONE DOE1"

    Now open the command prompt/terminal and hit the below command

    cat student.txt | sed 's/$/\r/g' | redis-cli --pipe

    • If Redis have the password then hit the below command.
      cat student.txt | sed 's/$/\r/g' | redis-cli -a "password" --pipe
  13. added a commit that references this issue on Oct 16, 2025
  14. added a commit that references this issue on Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions