node-redis-dump icon indicating copy to clipboard operation
node-redis-dump copied to clipboard

Split/Shorten command buffer per redis command length limitation of 4096 bytes

Open odnarb opened this issue 7 years ago • 5 comments

redis-cli uses linenoise custom library for terminal input, which happens to have hard-coded input buffer size of 4096 bytes: linenoise.c: at time of this writing, line 121,

#define LINENOISE_MAX_LINE 4096

https://github.com/antirez/redis/blob/unstable/deps/linenoise/linenoise.c#L121

Shortening commands will help tremendously with future headaches.

Thank you

odnarb avatar Apr 11 '17 19:04 odnarb

Do you have an example of use case to illustrate the problem? I am not completely sure about what you are suggesting.

jeremyfa avatar Apr 11 '17 21:04 jeremyfa

Yes, with a large set of data this is easily achieved:

Assume test.log has:

DEL     test:_indicies:id
SADD    test:_indicies:id 6 670 63 231 1013 766 857 115 78 912 682 807 647 475 310 1006 870 900 412 609 511 35 827 240 992 645 553 963 936 641 358 672 138 980 253 769 162 669 343 746 521 298 38 573 114 286 646 83 43 8 972 701 242 1005 501 39 1022 917 551 789 202 125 22 548 15 779 426 393 126 1018 314 727 547 799 198 973 722 290 119 26 630 711 770 494 391 803 203 320 907 834 740 458 435 1017 408 183 927 786 528 525 309 110 598 236 87 840 385 681 425 1023 533 921 541 585 25 987 941 781 463 449 245 622 536 451 879 853 947 793 620 499 661 285 728 30 765 915 758 534 227 705 527 572 394 503 446 851 98 614 381 142 106 342 66 946 485 772 940 277 897 377 363 27 317 209 5 143 1016 424 318 55 756 584 1003 291 41 179 709 974 812 726 410 795 569 271 79 979 688 559 374 911 230 508 216 859 392 12 442 935 889 714 255 843 338 99 732 887 235 281 998 607 64 796 149 398 639 751 470 421 171 659 841 867 838 244 817 280 278 574 369 274 576 270 113 901 205 176 161 608 601 546 514 140 415 135 1 686 606 51 100 602 909 468 299 554 122 197 775 306 131 939 860 739 702 9 977 995 873 524 272 761 411 710 689 448 92 986 384 62 301 208 736 956 725 427 891 680 660 157 465 1009 156 697 328 173 903 865 744 847 305 356 737 605 506 316 856 303 593 742 65 362 166 636 302 753 357 334 914 692 145 455 128 58 407 520 371 215 493 733 663 496 34 587 757 187 127 719 300 94 333 129 153 863 678 592 662 137 555 52 894 539 49 453 368 918 45 954 674 413 820 323 495 473 82 341 152 509 252 164 93 729 151 409 805 46 858 195 578 502 951 399 948 628 749 933 19 414 349 246 471 545 261 36 952 24 397 257 955 773 330 477 68 880 754 882 594 304 564 924 238 101 258 762 616 703 654 540 443 396 268 557 965 331 223 213 862 14 378 640 111 44 953 764 379 667 329 836 791 395 54 975 888 759 352 165 96 999 4 845 389 869 629 239 993 884 596 214 586 150 60 666 943 56 558 854 336 228 370 712 361 222 417 776 704 610 293 1007 723 543 146 347 916 741 721 673 207 777 906 375 542 600 480 390 784 871 846 204 29 591 315 168 121 13 824 565 275 735 345 675 535 383 1008 961 905 694 872 848 949 159 549 904 422 326 294 123 813 461 1014 852 130 707 447 249 263 287 529 492 962 861 631 380 28 988 288 798 658 155 652 476 91 186 324 259 74 57 486 116 61 771 490 160 780 968 522 715 353 327 816 319 750 716 552 154 618 104 677 172 837 247 885 913 785 312 211 507 217 109 633 23 783 225 627 430 484 802 241 117 971 491 950 589 16 1021 567 84 77 404 482 1004 967 832 717 782 163 842 297 804 577 457 433 526 18 822 581 808 267 419 212 210 59 898 566 550 874 133 1011 332 40 683 664 283 679 875 72 866 656 583 597 530 839 354 730 604 373 177 896 436 360 826 497 964 86 254 923 919 269 651 279 196 833 811 367 625 97 989 981 868 763 296 699 350 139 517 1019 818 908 932 850 460 934 523 265 193 474 512 930 691 344 167 849 190 734 488 224 264 67 48 997 387 118 308 182 33 990 423 944 232 815 684 479 718 10 957 538 431 1012 191 925 922 706 321 262 650 20 170 50 612 364 2 575 464 653 560 835 969 322 745 648 428 966 590 382 1010 698 970 844 747 440 634 1002 199 621 266 657 724 623 445 37 778 743 144 69 42 355 251 752 17 801 307 806 774 823 617 790 273 768 562 185 624 218 886 920 544 800 47 937 926 579 487 665 819 515 147 731 256 825 638 483 71 942 189 1001 289 720 611 595 899 708 53 902 828 582 416 556 1015 978 881 237 976 432 489 696 599 120 403 365 124 105 250 90 70 632 938 219 892 444 103 325 1020 194 372 580 206 713 615 178 883 518 188 243 890 472 700 537 192 112 466 158 613 982 788 588 11 626 459 568 141 960 339 434 366 643 671 809 985 73 831 418 201 996 437 642 984 561 311 1075 498 462 134 504 181 644 478 931 1073 401 108 1054 180 797 88 959 260 351 810 400 814 649 450 284 895 248 519 1032 991 454 402 337 668 637 876 983 877 767 500 635 175 405 821 220 221 89 32 994 438 1030 1049 1043 1065 1046 1044 1052 1055 1053 1031 1064 1057 1061 1070 1062 21 429 80 695 945 513 467 570 693 439 452 787 510 830 1067 516 505 76 313 102 829 760 1059 794 676 292 441 95 928 335 388 81 864 132 1024 295 346 690 226 481 878 107 31 456 687 200 738 1000 910 792 174 386 234 929 276 531 655 148 619 184 893 229 136 958 755 855 340 75 233 748 359 603 469 348 685 376 282 7 420 571 85 3 532 169 406 563 1037 1060 1047 1050 1029 1035 1041 1034 1063 1048 1072 1027 1036 1038 1033 1026 1071 1058 1025 1051 1045 1028 1042 1039 1068 1040 1074 1066 1056 1069

And then try to import:

cat test.log | redis-cli

Output:

(integer) 0
(integer) 1031
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'

After breaking up the long line into several the import works fine.

odnarb avatar Apr 11 '17 22:04 odnarb

Can you confirm this?

odnarb avatar Apr 13 '17 17:04 odnarb

I am on latest stable redis, which doesn't seem to have the problem, but if you can reproduce it on your side and can come up with a fix, a pull request is more than welcome.

jeremyfa avatar Apr 14 '17 12:04 jeremyfa

brandon@brandon_local_vm:~/redis-backup$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
NAME="Ubuntu"
VERSION="16.04.2 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.2 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
brandon@brandon_local_vm:~/redis-backup$ npm install redis-dump
/home/brandon/redis-backup
└── [email protected]
brandon@brandon_local_vm:~/redis-backup$ redis-cli -v
redis-cli 3.0.6

(assume test.log has command content shown in first post)

brandon@brandon_local_vm:~/redis-backup$ cat test.log | redis-cli
(integer) 0
(integer) 1031
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
(error) ERR unknown command '348'
brandon@brandon_local_vm:~/sails-projects/jibweb$ redis-cli
127.0.0.1:6379> smembers "test:_indicies:id"
   1) "878"
   2) "481"
   3) "226"
......
1027) "75"
1028) "748"
1029) "233"
1030) "359"
1031) "603"
1032) "469"
1033) "3"
127.0.0.1:6379>

After splitting the command content to two lines, like:

DEL     test:_indicies:id
SADD test:_indicies:id 6 670 63 231 1013 766 857 115 78 912 682 807 647 475 310 1006 870 900 412 609 511 35 827 240 992 645 553 963 936 641 358 672 138 980 253 769 162 669 343 746 521 298 38 573 114 286 646 83 43 8 972 701 242 1005 501 39 1022 917 551 789 202 125 22 548 15 779 426 393 126 1018 314 727 547 799 198 973 722 290 119 26 630 711 770 494 391 803 203 320 907 834 740 458 435 1017 408 183 927 786 528 525 309 110 598 236 87 840 385 681 425 1023 533 921 541 585 25 987 941 781 463 449 245 622 536 451 879 853 947 793 620 499 661 285 728 30 765 915 758 534 227 705 527 572 394 503 446 851 98 614 381 142 106 342 66 946 485 772 940 277 897 377 363 27 317 209 5 143 1016 424 318 55 756 584 1003 291 41 179 709 974 812 726 410 795 569 271 79 979 688 559 374 911 230 508 216 859 392 12 442 935 889 714 255 843 338 99 732 887 235 281 998 607 64 796 149 398 639 751 470 421 171 659 841 867 838 244 817 280 278 574 369 274 576 270 113 901 205 176 161 608 601 546 514 140 415 135 1 686 606 51 100 602 909 468 299 554 122 197 775 306 131 939 860 739 702 9 977 995 873 524 272 761 411 710 689 448 92 986 384 62 301 208 736 956 725 427 891 680 660 157 465 1009 156 697 328 173 903 865 744 847 305 356 737 605 506 316 856 303 593 742 65 362 166 636 302 753 357 334 914 692 145 455 128 58 407 520 371 215 493 733 663 496 34 587 757 187 127 719 300 94 333 129 153 863 678 592 662 137 555 52 894 539 49 453 368 918 45 954 674 413 820 323 495 473 82 341 152 509 252 164 93 729 151 409 805 46 858 195 578 502 951 399 948 628 749 933 19 414 349 246 471 545 261 36 952 24 397 257 955 773 330 477 68 880 754 882 594 304 564 924 238 101 258 762 616 703 654 540 443 396 268 557 965 331 223 213 862 14 378 640 111 44 953 764 379 667 329 836 791 395 54 975 888 759 352 165 96 999 4 845 389 869 629 239 993 884 596 214 586 150 60 666 943 56 558 854 336 228 370 712 361 222 417 776 704 610 293 1007 723 543 146 347 916 741 721 673 207 777 906 375 542 600 480 390 784 871 846 204 29 591 315 168 121 13 824 565 275 735 345 675 535 383 1008 961 905 694 872 848 949 159 549 904 422 326 294 123 813 461 1014 852 130 707 447 249 263 287 529 492 962 861 631 380 28 988 288 798 658 155 652 476 91 186 324 259 74 57 486 116 61 771 490 160 780 968 522 715 353 327 816 319 750 716 552 154 618 104 677 172 837 247 885 913 785 312 211 507 217 109 633 23 783 225 627 430 484 802 241 117 971 491 950 589 16 1021 567 84 77 404 482 1004 967 832 717 782 163 842 297 804 577 457 433 526 18 822 581 808 267 419 212 210 59 898 566 550 874 133 1011 332 40 683 664 283 679 875 72 866 656 583 597 530 839 354 730 604 373 177 896 436 360 826 497 964 86 254 923 919 269 651 279 196 833 811 367 625 97 989 981 868 763 296 699 350 139 517 1019 818 908 932 850 460 934 523 265 193 474 512 930 691 344 167 849 190 734 488 224 264 67 48 997 387 118 308 182 33 990 423 944 232 815 684 479 718 10 957 538 431 1012 191 925 922 706 321 262 650 20 170 50 612 364 2 575 464 653 560 835 969 322 745 648 428 966 590 382 1010 698 970 844 747 440 634 1002 199 621 266 657 724 623 445 37 778 743 144 69 42 355 251 752 17 801 307 806 774 823 617 790 273 768 562 185 624 218 886 920 544 800 47 937 926 579 487 665 819 515 147 731 256 825 638 483 71 942 189 1001 289 720 611 595 899 708 53 902 828 582 416 556 1015 978 881 237 976 432 489 696 599 120 403 365 124 105 250 90 70 632 938 219 892 444 103 325 1020 194 372 580 206 713 615 178 883 518 188 243 890 472 700 537 192 112 466 158 613 982 788 588 11 626 459 568 141 960 339 434 366 643 671 809 985 73 831 418 201 996 437 642 984 561 311 1075 498 462 134 504 181 644 478 931 1073 401 108 1054 180 797 88 959 260 351 810 400 814 649 450 284 895 248 519 1032 991 454 402 337 668 637 876 983 877 767 500 635 175 405 821 220 221 89 32 994 438 1030 1049 1043 1065 1046 1044 1052 1055 1053 1031 1064 1057 1061 1070 1062 21 429 80 695 945 513 467 570 693 439 452 787 510 830 1067 516 505 76 313 102 829 760 1059 794 676 292 441 95 928 335 388 81 864 132 1024 295 346 690 226 481 878 107 31 456 687 200 738 1000 910 792 174 386 234 929 276 531 655 148 619 184 893 229 136 958 755 855 340 75 233 748 359 603 469
SADD test:_indicies:id  348 685 376 282 7 420 571 85 3 532 169 406 563 1037 1060 1047 1050 1029 1035 1041 1034 1063 1048 1072 1027 1036 1038 1033 1026 1071 1058 1025 1051 1045 1028 1042 1039 1068 1040 1074 1066 1056 1069
brandon@brandon_local_vm:~/redis-backup$ cat test.log | redis-cli
(integer) 0
(integer) 1032
(integer) 43
127.0.0.1:6379> smembers "test:_indicies:id"
   1) "878"
   2) "481"
   3) "226"
...
1057) "1027"
1058) "1036"
1059) "1038"
1060) "1033"
1061) "1026"
1062) "1071"
1063) "1058"
1064) "1025"
1065) "1051"
1066) "1045"
1067) "1028"
1068) "1042"
1069) "1039"
1070) "1068"
1071) "1040"
1072) "1074"
1073) "1066"
1074) "1056"
1075) "1069"
127.0.0.1:6379>

odnarb avatar Apr 14 '17 17:04 odnarb