How to Remove Multiple Redis Cache

Tags: January 25, 2017 9:07 PM


Remove multiple Redis cache key using one liner command.


Assume keys that we want to delete are keys beginning with 'laravel:' prefix.

$ redis-cli KEYS 'laravel:*'
1) "laravel:featured:2bf46b40ed15"
2) "laravel:list:5509f57fdaef"
3) "laravel:list:2bf46b40ed15"
4) "laravel:list:e1bf5bfc2ab8"
5) "laravel:list-total-rec:adc81409d693"
6) "laravel:list-total-rec:e1bf5bfc2ab8"
7) "laravel:promotion-list:adc81409d693"
8) "laravel:list:d1f68333e3bb"
9) "laravel:list:c6a45c5cf5c5"

Just pipe the output above to xargs command. By default redis-cli will use raw format when STDOUT is not tty, which in case is true for xargs.

$ redis-cli KEYS 'laravel:*' | xargs redis-cli DEL
(integer) 9


Share on Facebook Twitter

Redis: How to Increase File Descriptor Limits

Tags: November 25, 2016 8:06 PM


When you run redis server it complains can not set maximum open files because it has reached the OS max file descriptor limits. Here is the sample output.

$ ./bin/redis-server
28436:C 25 Nov 20:10:03.978 # Warning: no config file specified, using the default config. In order to specify a config file use ./bin/redis-server /path/to/redis.conf
28436:M 25 Nov 20:10:03.979 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
28436:M 25 Nov 20:10:03.979 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
28436:M 25 Nov 20:10:03.979 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.

When you try to increase the maximum file descriptor using ulimit as root by issuing sudo it returns an error.

$ sudo ulimit -n 65000
sudo: ulimit: command not found

Wow, WTF is that? ulimit is a shell built so giving sudo an instruction to run a command called ulimit will not work. It will the same as statement below.

$ sudo for
sudo: for: command not found


The easiest solution is become a root user to run set the file descriptor using ulimit. Right after that run redis as normal user in single command line.

$ sudo sh -c "ulimit -n 65000 && exec su -c '/path/to/redis/bin/redis-server' rio"
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 30789
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |         
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           

30789:M 25 Nov 20:33:03.362 # Server started, Redis version 3.2.5
30789:M 25 Nov 20:33:03.362 * DB loaded from disk: 0.000 seconds
30789:M 25 Nov 20:33:03.362 * The server is now ready to accept connections on port 6379


Share on Facebook Twitter

How to Fix No Sound After Mute and Unmute on XFCE

Tags: October 7, 2016 7:36 PM


There is no sound after doing mute then unmute on XFCE 4 Ubuntu 14.04.


Try running amixer command to see the status of the Master sound.

$ amixer get Master
Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Front Left: Playback 65536 [100%] [off]
  Front Right: Playback 65536 [100%] [off]

In above result the status of Front Left and Front Right is [off]. Meaning it is still muted even has been unmuted from the XFCE panel. Try to toggle the switch to make it [on].

Share on Facebook Twitter

How to Extract Specific Directory from Tarball

Tags: September 24, 2016 9:30 PM


We have huge file of gzipped tarball and we want to extract only specific directory from the tarball.


Make sure the pattern we want to extract by searching it first. As an example we want to extract directory named johndoe-website, but we did not know the full pattern of the directory.

$ tar tvf the-archive.tar.gz | grep johndoe-website
From the output above we knew that the pattern of the directory is home/sites/clients/johndoe-website. Command below will extract johndoe-website from the archive and strip the 3 leading directories.
$ tar xvf the-archive.tar.gz --strip-components=3 -C /destination/path home/sites/clients/johndoe-website
Command above works in GNU Tar and BSD Tar (Mac OS X).

Share on Facebook Twitter

Quickest Way: Using STDIN and Pipe to Copy SSH Public Key to Server

Tags: July 27, 2016 8:13 PM


Copy SSH public key to another machine without using external tools such as ssh-copy-id - Only pure shell built-in or at least standard commands.


The solution is using shell STDIN and PIPE it to ssh.

$ cat ~/.ssh/ | ssh [email protected] 'cat >> .ssh/authorized_keys -'
The quote for the ssh arguments is important because without it the redirection will goes to your local machine instead of remote machine. The "-" at the last of cat command on the remote indicate it reads the input from STDIN.


Share on Facebook Twitter

Expose Port Inside Running Container on Docker Toolbox for Mac

Tags: July 20, 2016 11:05 PM


Docker only allows to define port that need to be exposed when doing container creation. When the container already running and new port need to be exposed, you're out of luck.


You want to expose new port which run by application inside a running container, so you can hit the docker-vm-ip:port to access the port on Mac OS X.


  • IP of Boot2Docker VM (Which run by Virtualbox) is
  • IP of the docker container running the application is
  • The application listen on address and port 80

Share on Facebook Twitter

How to Create Root Certificate Authority (CA) and Self Signed Certificate

Tags: June 18, 2016 9:47 AM


Make client application such as web browser to trust our self signed certificate, so we can use any custom domain in development or internal network.

Generate Root CA

The first is to generate private key for our Certificate Authority (CA). Command below will generate RSA based private key 2048 bits key size.

$ mkdir self-root-ca && cd self-root-ca
$ openssl genrsa -out myRootCA.key
Generating RSA private key, 2048 bit long modulus
e is 65537 (0x10001)
$ chmod 0600 myRootCA.key

Command above will produce a file called myRootCA.key. The chmod command will make sure that only super user and the creator of the key able to read the file.

Share on Facebook Twitter