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
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());
}
}