redis-cli-lite localhost 6379
package main
import (
"fmt"
"github.com/needl3/redis-cli-lite/pkg/api"
)
func main() {
api, err := api.Initialize("localhost", 6379, 10, nil)
if err != nil {
panic(err)
}
resp, err := api.Ping()
if err != nil {
panic(err)
}
fmt.Println("Got: ", resp)
}
You can use this on cli but that has limitations. For example, there is not really a way to tell if the value is string, number or array from cli. So, everything is stored as string. We could implement something intelligent but this is unnecessarily complex and unusable and not even official cli tool does it afaik.
Note: This will only work with SAN certificate and not CN ones as official redis-server
requires. So make sure to have a configuration file for openssl as per your organization.
For example, you can use the following content as SAN configuration file:
[ req ]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_ca
prompt = no
[ req_distinguished_name ]
C = US
ST = California
L = San Francisco
O = MyCompany
OU = MyDivision
CN = localhost
[ req_ext ]
subjectAltName = @alt_names
[ v3_ca ]
subjectAltName = @alt_names
keyUsage = keyCertSign, cRLSign, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
[ alt_names ]
DNS.1 = localhost
- Generate a private key
openssl genpkey -algorithm RSA -out redis.key
- Generate a self signed certificate with SAN using config file
openssl req -x509 -nodes -new -key redis.key -sha256 -days 3650 -out redis.crt -config openssl.cnf
- Update redis-server config file with below content to use certificates with SAN then restart redis
tls-port 6379
tls-ca-cert-file /etc/pki/tls/certs/redis.crt
tls-cert-file /etc/pki/tls/certs/redis.crt
tls-key-file /etc/pki/tls/certs/redis.key
tls-auth-clients no
- Use certificate path while connecting to tls configured server. Check any test file e.g pkg/api/del_test.go
tlsConfig, err := utils.PrepareTLSConfig("../../redis.crt", "../../redis.key")
- Run tests to check if it works
- Implement pretty printer
- Change string type value to []byte
- TODO: Use _ instead of ignoring
- Use native integer instead of string
- Expand as golang library
- Support for blocking send due to connection pooling
- Support for secure tcp
- Support for secure tcp on cli mode