Skip to content

Instantly share code, notes, and snippets.

View abhirockzz's full-sized avatar
👋
fmt.Println(hello, world!)

Abhishek Gupta abhirockzz

👋
fmt.Println(hello, world!)
View GitHub Profile
...
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" {
...
//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))
}
...
todoID, incrErr := client.Incr(todoIDCounterName).Result()
todoInfo := make(map[string]interface{})
todoInfo["todoid"] = todoID
todoInfo["title"] = todoTitle
todoInfo["completed"] = "false"
txPipe := client.TxPipeline()
@abhirockzz
abhirockzz / txpipeline.go
Last active November 14, 2018 07:36
Go redis tx pipeline
...
txPipe := client.TxPipeline()
hmsetResult := txPipe.HMSet(todoHashNamePrefix+strconv.Itoa(int(todoID)), todoInfo)
lpushResult := txPipe.LPush(pendingTodosListName, strconv.Itoa(int(todoID)))
_, execErr := txPipe.Exec()
...
@abhirockzz
abhirockzz / func.go
Last active November 12, 2018 13:58
store redis connection globally for possible re-use and create new one only if needed
...
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
@abhirockzz
abhirockzz / func.go
Created October 31, 2018 09:26
Fn Go function
package main
import (
"context"
"encoding/json"
"fmt"
"io"
"time"
fdk "github.com/fnproject/fdk-go"
@abhirockzz
abhirockzz / func.go
Created October 31, 2018 09:25
Fn Go function
package main
import (
"context"
"io"
"math/rand"
"strconv"
"time"
fdk "github.com/fnproject/fdk-go"
@abhirockzz
abhirockzz / redis-cluster-creation-output.txt
Created August 31, 2018 11:52
Redis Cluster creation output
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
@abhirockzz
abhirockzz / create-redis-cluster.sh
Created August 31, 2018 11:51
Use redis-cli to create a Redis Cluster on Docker (with Redis 5.0)
#------------ 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 ------------------------
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';