A basic implemenation for distributed caching layer aimed primarily for redis server to support sharding data and distributing load on multiple servers
To run server
make run
List of envs needs to be setup before starting the service
REDIS_CONNECTION_URL
default url for redis to connect to if none suppliedSHARDS_CONNECTION_URLS
comma separated list of redis urls to use for sharding the dataSERVER_PORT
port used to serve http requests
sample request to send when server is up to do any kind of command on redis
curl --location --request POST 'http://localhost:5000/execute_command' \
--header 'Content-Type: application/json' \
--data-raw '{
"command_name":"SET",
"key": "XY",
"command_args": [
"XY",
"XZ"
]
}'
Notice you need to mention the key twice, one time in the command args
array and another time in the key
field
yes as long you implemnent the interface cache.client
, then you can easily swap in your new caching layer instead of redis, no assumptions are made for redis beyond the interface level.
// Client a contract interface for any caching third party client to be used with our system
type Client interface {
Init(string) error
InitWithDefault() error
ExecuteRawCommand(commandName string, args ...interface{}) (string, error)
}