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
... | |
currentCompletedStatus := client.HGet(todoHashNamePrefix+todoID, "completed").Val() | |
txPipe := client.TxPipeline() | |
hsetResult := txPipe.HSet(todoHashNamePrefix+todoID, "completed", completed) | |
if completed == "true" { | |
lremResult = txPipe.LRem(pendingTodosListName, 0, todoID) | |
rpushResult = txPipe.RPush(completedTodosListName, todoID) | |
} else if completed == "false" { |
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
... | |
//ALL todos | |
keys, _, _ := client.Scan(0, todoHashNamePrefix+"*", 1000).Result() | |
var todoInfoMaps []*redis.StringStringMapCmd | |
txPipe := client.TxPipeline() | |
for _, todoHashName := range keys { | |
todoInfoMaps = append(todoInfoMaps, txPipe.HGetAll(todoHashName)) | |
} |
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
... | |
todoID, incrErr := client.Incr(todoIDCounterName).Result() | |
todoInfo := make(map[string]interface{}) | |
todoInfo["todoid"] = todoID | |
todoInfo["title"] = todoTitle | |
todoInfo["completed"] = "false" | |
txPipe := client.TxPipeline() |
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
... | |
txPipe := client.TxPipeline() | |
hmsetResult := txPipe.HMSet(todoHashNamePrefix+strconv.Itoa(int(todoID)), todoInfo) | |
lpushResult := txPipe.LPush(pendingTodosListName, strconv.Itoa(int(todoID))) | |
_, execErr := txPipe.Exec() | |
... |
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
... | |
var client *redis.Client | |
func createTODOHandler(ctx context.Context, in io.Reader, out io.Writer) { | |
redisHost := fdk.Context(ctx).Config["REDIS_HOST"] | |
redisPort := fdk.Context(ctx).Config["REDIS_PORT"] | |
if client == nil { | |
//create a new one |
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
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"io" | |
"time" | |
fdk "github.com/fnproject/fdk-go" |
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
package main | |
import ( | |
"context" | |
"io" | |
"math/rand" | |
"strconv" | |
"time" | |
fdk "github.com/fnproject/fdk-go" |
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
redis_cluster_net created | |
f66517db305c3f270f756f1fbd40611d123fc69c040695147bb43cc153491093 | |
created redis cluster node redis-6379 | |
726672fad3d815e7a07ac892acd7bb412e91193b28527654c483cd5debbfd011 | |
created redis cluster node redis-6380 | |
75d8621153b3cbb7962fcf90a5a35108fe042a05e9a78b920c2655caa5a1f7ec | |
created redis cluster node redis-6381 | |
d9df8c47ccaf21470bcbc2b89f485e1cd9f68917019fa6ba7ebbac59b792b41b | |
created redis cluster node redis-6382 | |
21edb22225abc54140e437091ddb19cd452542e3d82e7839470a3bbf6a0ddbf7 |
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
#------------ bootstrap the cluster nodes -------------------- | |
start_cmd='redis-server --port 6379 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes' | |
redis_image='redis:5.0-rc' | |
network_name='redis_cluster_net' | |
docker network create $network_name | |
echo $network_name " created" | |
#---------- create the cluster ------------------------ |
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
Basic queries | |
//Give me all tweets with the hashtag cloud | |
select * from hashtags_by_date where hashtag = 'cloud'; | |
//Show me tweets with hashtag java on 6th March 2018 ? | |
select * from hashtags_by_date where hashtag = 'java' and created_date = '2018-03-06'; | |
//Show me tweets with hashtag java, cloud or trump on 6th March 2018 ? | |
select * from hashtags_by_date where hashtag IN ('java', 'cloud', 'trump') and created_date = '2018-03-06'; |