Github Education
  • Github學生免費服務推薦
  • name.com免費網域申請
  • SendGrid - Email Service
  • Configcat - Global config setting
  • Transloadit - File conversion to cloud storage
  • i18n 管理平台 - lingohub
  • Push Notifications - PushBots
  • BrowserStack
  • Page
  • Ai
    • Stable diffusion
    • Changing Images Backgrounds
  • Copy of Crypto currency games
    • Gods Unchained
  • Digital Ocean
    • How to create cloud instance and access it on Digital Ocean
    • Deploy nodeJs on DigitalOcean droplet using docker
    • Deploy Redis to your local
  • Heroku
    • Heroku Cli
    • How to deploy Hello world to Heroku using docker
    • How to deploy NodeJS application to Heroku using docker
  • APIs
    • Google Geocoding API
    • FourSquare
    • Building APIs with Swagger
  • Util
    • Google Cloud Storage - Object storage
    • Google Search Console
    • Google Sign-in with Angular Front End
    • Google Sign-in with Nodejs Backend
    • Github Package
  • 推薦課程
  • Currently interested in
  • Useful info
  • Become a Front End Web Developer | Udacity
    • 2. CSS, Website Layout, Website Components
      • Lesson 2: CSS
      • Lesson 3: Flexbox
      • Lesson 4: CSS Grid
      • Lesson 5: Creating Responsive Layouts
      • How to use Adobe Design tokens - Spectrum
    • 3. Javascript & The DOM
      • Lesson 1: Syntax
      • Lesson 2: The Document Object Model
      • Lesson 3: Creating Content with JavaScript
      • Lesson 4: Working with Browser Events
  • Some tips
    • Github Blame View
  • Free
    • Openshift(WIP)
Powered by GitBook
On this page
  • Run redis docker image
  • Check running container
  • Attach another processor to open console in the container
  • Enter redis-cli and test
  • Test using netcat from your local terminal
  • Test using Java

Was this helpful?

  1. Digital Ocean

Deploy Redis to your local

Below steps are running on MacOS. It might now work if you're using Windows OS.

Run redis docker image

>> docker run --rm -ti --name test-redis -p 6379:6379 redis:6.2-rc3-alpine

1:C 20 Feb 2021 19:39:26.881 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 20 Feb 2021 19:39:26.881 # Redis version=6.1.242, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 20 Feb 2021 19:39:26.881 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 20 Feb 2021 19:39:26.883 * monotonic clock: POSIX clock_gettime
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 6.1.242 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

1:M 20 Feb 2021 19:39:26.885 # Server initialized
1:M 20 Feb 2021 19:39:26.885 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memor
y = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 20 Feb 2021 19:39:26.885 * Ready to accept connections

Check running container

>> docker ps

CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS                    NAMES
ccc47d8fe03e   redis:6.2-rc3-alpine   "docker-entrypoint.s…"   38 seconds ago   Up 37 seconds   0.0.0.0:6379->6379/tcp   test-redis

Attach another processor to open console in the container

>> docker exec -ti <CONTAINER ID> <command>
>> docker exec -ti ccc47d8fe03e sh

Enter redis-cli and test

/data # redis-cli

127.0.0.1:6379> ping
PONG

127.0.0.1:6379> set key value
OK

127.0.0.1:6379> get key
"value"

Test using netcat from your local terminal

>> (printf "PING\r\n";) | nc localhost 6379

+PONG

Test using Java

Import Redis Java driver using maven

        <!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>3.3.0</version>
        </dependency>

Sample Java program

import redis.clients.jedis.Jedis;

public class RedisTest {

    public static void main(String[] args){
        //Connecting to Redis server on localhost
        Jedis jedis = new Jedis("localhost");

        System.out.println("Connection to server sucessfully");
        //check whether server is running or not
        System.out.println("Server is running: "+jedis.ping());
    }
}

PreviousDeploy nodeJs on DigitalOcean droplet using dockerNextHeroku Cli

Last updated 4 years ago

Was this helpful?

Ref:

https://stackoverflow.com/a/33246275/3117474
https://mvnrepository.com/artifact/redis.clients/jedis