This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BITFIELD command taken from http://redis.io/commands/BITFIELD | |
// BITFIELD mykey INCRBY i5 100 1 GET u4 0 | |
final CmdByteArray<long[]> bitfieldCmd = CmdByteArray.startBuilding(Cmds.BITFIELD, 9) | |
.addSlotKey("mykey") | |
.addSubCmd(Cmds.BITFIELD_INCRBY, "i5", "100", "1") | |
.addSubCmd(Cmds.BITFIELD_GET, "u4", "0").create(); | |
try (final RedisClient client = | |
RedisClientFactory.startBuilding().create(Node.create("localhost", 6379))) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static int runWithJedipus(final IntStream keys) { | |
int count = 0; | |
try (final RedisClient client = | |
RedisClientFactory.startBuilding().create(Node.create("127.0.0.1", 6379))) { | |
client.sendCmd(Cmds.FLUSHALL); | |
final long start = System.currentTimeMillis(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Map<Node, Node> nodeMappings = new HashMap<>(3); | |
nodeMappings.put(Node.create("internal1", 7001), Node.create("public1", 7001)); | |
nodeMappings.put(Node.create("internal1", 7002), Node.create("public2", 7002)); | |
nodeMappings.put(Node.create("internal1", 7003), Node.create("public3", 7003)); | |
final Collection<Node> discoveryNodes = Collections.singleton(Node.create("public1", 7001)); | |
// Static mapper, could easily be something dynamic as well. | |
final NodeMapper nodeMapper = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Node node = Node.create("127.0.0.1", 6379); | |
final String channel = "jedipus"; | |
final RedisClientFactory.Builder clientFactory = RedisClientFactory.startBuilding(); | |
final ElementRetryDelay<Node> nodeRetryDelay = | |
ElementRetryDelay.startBuilding().withMaxDelay(Duration.ofSeconds(30)).create(); | |
final RedisClientExecutor clientExecutor = RedisClientExecutor.startBuilding() | |
.withClientFactory(clientFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.PrimitiveIterator; | |
import static java.lang.Character.digit; | |
public final class Hex { | |
private Hex() {} | |
private static final char[] HEX_CHARS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', | |
'9', 'a', 'b', 'c', 'd', 'e', 'f'}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.servlet.http.HttpServletRequest; | |
public class RequestUtil { | |
public static String getRequestIp(final HttpServletRequest request) { | |
String ip = request.getHeader("X-Forwarded-For"); | |
if (ip == null) { | |
return request.getRemoteAddr(); | |
} | |
ip = ip.trim(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#./createMasters.sh 7001 5 redis-cluster-m- comodal/alpine-redis | |
readonly STARTING_PORT=${1:-0} | |
readonly NUM_MASTERS=${2:-0} | |
readonly NAME_PREFIX=${3:-"redis-cluster-m-"} | |
readonly IMAGE=${4:-"comodal/alpine-redis"} | |
for ((port = STARTING_PORT, endPort = port + NUM_MASTERS; port < endPort; port++)) do | |
name="$NAME_PREFIX$port" | |
docker service create\ | |
--name "$name"\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#./forEach.sh 7001 5 redis-cluster-m- CLUSTER INFO | |
readonly STARTING_PORT=$1 | |
readonly NUM_MASTERS=$2 | |
readonly NAME_PREFIX=$3 | |
readonly REDIS_CMD=("${@:4}") | |
readonly LOCAL_CONTAINER_ID=$(docker ps -f name="$NAME_PREFIX" -q | head -n 1) | |
readonly LOCAL_PORT=$(docker inspect --format='{{index .Config.Labels "com.docker.swarm.service.name"}}' "$LOCAL_CONTAINER_ID" | sed 's|.*-||') | |
for ((port = STARTING_PORT, endPort = port + NUM_MASTERS; port < endPort; port++)) do | |
host=$([ "$LOCAL_PORT" == $port ] && echo "127.0.0.1" || echo "$NAME_PREFIX$port") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#./rmServices.sh redis-cluster-m- | |
readonly FILTER=${1:-"redis-cluster-m-"} | |
docker service ls | grep "$FILTER" | awk '{print $1}' | xargs docker service rm | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#./meetNodes.sh 7001 5 redis-cluster-m- | |
readonly STARTING_PORT=${1:-0} | |
readonly NUM_MASTERS=${2:-0} | |
readonly NAME_PREFIX=${3:-"redis-cluster-m-"} | |
readonly LOCAL_CONTAINER_ID=$(docker ps -f name="$NAME_PREFIX" -q | head -n 1) | |
readonly LOCAL_PORT=$(docker inspect --format='{{index .Config.Labels "com.docker.swarm.service.name"}}' "$LOCAL_CONTAINER_ID" | sed 's|.*-||') | |
# From local service task, meet all other nodes | |
for ((port = STARTING_PORT, endPort = STARTING_PORT + NUM_MASTERS; port < endPort; port++)) do | |
if [ "$LOCAL_PORT" == $port ]; then |
OlderNewer