repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6 values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
alicebob/miniredis | direct.go | FlushDB | func (db *RedisDB) FlushDB() {
db.master.Lock()
defer db.master.Unlock()
db.flush()
} | go | func (db *RedisDB) FlushDB() {
db.master.Lock()
defer db.master.Unlock()
db.flush()
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"FlushDB",
"(",
")",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"\n",
"db",
".",
"flush",
"(",
")",
"\n",
"}"
] | // FlushDB removes all keys. | [
"FlushDB",
"removes",
"all",
"keys",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L59-L63 | train |
alicebob/miniredis | direct.go | Get | func (m *Miniredis) Get(k string) (string, error) {
return m.DB(m.selectedDB).Get(k)
} | go | func (m *Miniredis) Get(k string) (string, error) {
return m.DB(m.selectedDB).Get(k)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"Get",
"(",
"k",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"m",
".",
"DB",
"(",
"m",
".",
"selectedDB",
")",
".",
"Get",
"(",
"k",
")",
"\n",
"}"
] | // Get returns string keys added with SET. | [
"Get",
"returns",
"string",
"keys",
"added",
"with",
"SET",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L66-L68 | train |
alicebob/miniredis | direct.go | Get | func (db *RedisDB) Get(k string) (string, error) {
db.master.Lock()
defer db.master.Unlock()
if !db.exists(k) {
return "", ErrKeyNotFound
}
if db.t(k) != "string" {
return "", ErrWrongType
}
return db.stringGet(k), nil
} | go | func (db *RedisDB) Get(k string) (string, error) {
db.master.Lock()
defer db.master.Unlock()
if !db.exists(k) {
return "", ErrKeyNotFound
}
if db.t(k) != "string" {
return "", ErrWrongType
}
return db.stringGet(k), nil
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"Get",
"(",
"k",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"db",
"."... | // Get returns a string key. | [
"Get",
"returns",
"a",
"string",
"key",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L71-L81 | train |
alicebob/miniredis | direct.go | Set | func (m *Miniredis) Set(k, v string) error {
return m.DB(m.selectedDB).Set(k, v)
} | go | func (m *Miniredis) Set(k, v string) error {
return m.DB(m.selectedDB).Set(k, v)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"Set",
"(",
"k",
",",
"v",
"string",
")",
"error",
"{",
"return",
"m",
".",
"DB",
"(",
"m",
".",
"selectedDB",
")",
".",
"Set",
"(",
"k",
",",
"v",
")",
"\n",
"}"
] | // Set sets a string key. Removes expire. | [
"Set",
"sets",
"a",
"string",
"key",
".",
"Removes",
"expire",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L84-L86 | train |
alicebob/miniredis | direct.go | Set | func (db *RedisDB) Set(k, v string) error {
db.master.Lock()
defer db.master.Unlock()
if db.exists(k) && db.t(k) != "string" {
return ErrWrongType
}
db.del(k, true) // Remove expire
db.stringSet(k, v)
return nil
} | go | func (db *RedisDB) Set(k, v string) error {
db.master.Lock()
defer db.master.Unlock()
if db.exists(k) && db.t(k) != "string" {
return ErrWrongType
}
db.del(k, true) // Remove expire
db.stringSet(k, v)
return nil
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"Set",
"(",
"k",
",",
"v",
"string",
")",
"error",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"\n",
"if",
"db",
".",
"exists",
"(",
"k"... | // Set sets a string key. Removes expire.
// Unlike redis the key can't be an existing non-string key. | [
"Set",
"sets",
"a",
"string",
"key",
".",
"Removes",
"expire",
".",
"Unlike",
"redis",
"the",
"key",
"can",
"t",
"be",
"an",
"existing",
"non",
"-",
"string",
"key",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L90-L100 | train |
alicebob/miniredis | direct.go | Push | func (db *RedisDB) Push(k string, v ...string) (int, error) {
db.master.Lock()
defer db.master.Unlock()
if db.exists(k) && db.t(k) != "list" {
return 0, ErrWrongType
}
return db.listPush(k, v...), nil
} | go | func (db *RedisDB) Push(k string, v ...string) (int, error) {
db.master.Lock()
defer db.master.Unlock()
if db.exists(k) && db.t(k) != "list" {
return 0, ErrWrongType
}
return db.listPush(k, v...), nil
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"Push",
"(",
"k",
"string",
",",
"v",
"...",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"... | // Push add element at the end. Is called RPUSH in redis. Returns the new length. | [
"Push",
"add",
"element",
"at",
"the",
"end",
".",
"Is",
"called",
"RPUSH",
"in",
"redis",
".",
"Returns",
"the",
"new",
"length",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L200-L208 | train |
alicebob/miniredis | direct.go | SetTTL | func (m *Miniredis) SetTTL(k string, ttl time.Duration) {
m.DB(m.selectedDB).SetTTL(k, ttl)
} | go | func (m *Miniredis) SetTTL(k string, ttl time.Duration) {
m.DB(m.selectedDB).SetTTL(k, ttl)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"SetTTL",
"(",
"k",
"string",
",",
"ttl",
"time",
".",
"Duration",
")",
"{",
"m",
".",
"DB",
"(",
"m",
".",
"selectedDB",
")",
".",
"SetTTL",
"(",
"k",
",",
"ttl",
")",
"\n",
"}"
] | // SetTTL sets the TTL of a key. | [
"SetTTL",
"sets",
"the",
"TTL",
"of",
"a",
"key",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L332-L334 | train |
alicebob/miniredis | direct.go | SetTTL | func (db *RedisDB) SetTTL(k string, ttl time.Duration) {
db.master.Lock()
defer db.master.Unlock()
db.ttl[k] = ttl
db.keyVersion[k]++
} | go | func (db *RedisDB) SetTTL(k string, ttl time.Duration) {
db.master.Lock()
defer db.master.Unlock()
db.ttl[k] = ttl
db.keyVersion[k]++
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"SetTTL",
"(",
"k",
"string",
",",
"ttl",
"time",
".",
"Duration",
")",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"\n",
"db",
".",
"ttl"... | // SetTTL sets the time to live of a key. | [
"SetTTL",
"sets",
"the",
"time",
"to",
"live",
"of",
"a",
"key",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L337-L342 | train |
alicebob/miniredis | direct.go | HGet | func (m *Miniredis) HGet(k, f string) string {
return m.DB(m.selectedDB).HGet(k, f)
} | go | func (m *Miniredis) HGet(k, f string) string {
return m.DB(m.selectedDB).HGet(k, f)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"HGet",
"(",
"k",
",",
"f",
"string",
")",
"string",
"{",
"return",
"m",
".",
"DB",
"(",
"m",
".",
"selectedDB",
")",
".",
"HGet",
"(",
"k",
",",
"f",
")",
"\n",
"}"
] | // HGet returns hash keys added with HSET.
// This will return an empty string if the key is not set. Redis would return
// a nil.
// Returns empty string when the key is of a different type. | [
"HGet",
"returns",
"hash",
"keys",
"added",
"with",
"HSET",
".",
"This",
"will",
"return",
"an",
"empty",
"string",
"if",
"the",
"key",
"is",
"not",
"set",
".",
"Redis",
"would",
"return",
"a",
"nil",
".",
"Returns",
"empty",
"string",
"when",
"the",
"... | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L372-L374 | train |
alicebob/miniredis | direct.go | HGet | func (db *RedisDB) HGet(k, f string) string {
db.master.Lock()
defer db.master.Unlock()
h, ok := db.hashKeys[k]
if !ok {
return ""
}
return h[f]
} | go | func (db *RedisDB) HGet(k, f string) string {
db.master.Lock()
defer db.master.Unlock()
h, ok := db.hashKeys[k]
if !ok {
return ""
}
return h[f]
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"HGet",
"(",
"k",
",",
"f",
"string",
")",
"string",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"\n",
"h",
",",
"ok",
":=",
"db",
".",
... | // HGet returns hash keys added with HSET.
// Returns empty string when the key is of a different type. | [
"HGet",
"returns",
"hash",
"keys",
"added",
"with",
"HSET",
".",
"Returns",
"empty",
"string",
"when",
"the",
"key",
"is",
"of",
"a",
"different",
"type",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L378-L386 | train |
alicebob/miniredis | direct.go | Publish | func (m *Miniredis) Publish(channel, message string) int {
m.Lock()
defer m.Unlock()
return m.publish(channel, message)
} | go | func (m *Miniredis) Publish(channel, message string) int {
m.Lock()
defer m.Unlock()
return m.publish(channel, message)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"Publish",
"(",
"channel",
",",
"message",
"string",
")",
"int",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"m",
".",
"publish",
"(",
"channel",
",",
"mes... | // Publish a message to subscribers. Returns the number of receivers. | [
"Publish",
"a",
"message",
"to",
"subscribers",
".",
"Returns",
"the",
"number",
"of",
"receivers",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L552-L556 | train |
alicebob/miniredis | direct.go | PubSubNumPat | func (m *Miniredis) PubSubNumPat() int {
m.Lock()
defer m.Unlock()
return countPsubs(m.allSubscribers())
} | go | func (m *Miniredis) PubSubNumPat() int {
m.Lock()
defer m.Unlock()
return countPsubs(m.allSubscribers())
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"PubSubNumPat",
"(",
")",
"int",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"countPsubs",
"(",
"m",
".",
"allSubscribers",
"(",
")",
")",
"\n",
"}"
] | // PubSubNumPat is "PUBSUB NUMPAT" | [
"PubSubNumPat",
"is",
"PUBSUB",
"NUMPAT"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L583-L588 | train |
alicebob/miniredis | server/proto.go | readArray | func readArray(rd *bufio.Reader) ([]string, error) {
line, err := rd.ReadString('\n')
if err != nil {
return nil, err
}
if len(line) < 3 {
return nil, ErrProtocol
}
switch line[0] {
default:
return nil, ErrProtocol
case '*':
l, err := strconv.Atoi(line[1 : len(line)-2])
if err != nil {
return nil, err
}
// l can be -1
var fields []string
for ; l > 0; l-- {
s, err := readString(rd)
if err != nil {
return nil, err
}
fields = append(fields, s)
}
return fields, nil
}
} | go | func readArray(rd *bufio.Reader) ([]string, error) {
line, err := rd.ReadString('\n')
if err != nil {
return nil, err
}
if len(line) < 3 {
return nil, ErrProtocol
}
switch line[0] {
default:
return nil, ErrProtocol
case '*':
l, err := strconv.Atoi(line[1 : len(line)-2])
if err != nil {
return nil, err
}
// l can be -1
var fields []string
for ; l > 0; l-- {
s, err := readString(rd)
if err != nil {
return nil, err
}
fields = append(fields, s)
}
return fields, nil
}
} | [
"func",
"readArray",
"(",
"rd",
"*",
"bufio",
".",
"Reader",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"line",
",",
"err",
":=",
"rd",
".",
"ReadString",
"(",
"'\\n'",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
... | // client always sends arrays with bulk strings | [
"client",
"always",
"sends",
"arrays",
"with",
"bulk",
"strings"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/proto.go#L13-L41 | train |
alicebob/miniredis | pubsub.go | Count | func (s *Subscriber) Count() int {
s.mu.Lock()
defer s.mu.Unlock()
return s.count()
} | go | func (s *Subscriber) Count() int {
s.mu.Lock()
defer s.mu.Unlock()
return s.count()
} | [
"func",
"(",
"s",
"*",
"Subscriber",
")",
"Count",
"(",
")",
"int",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"s",
".",
"count",
"(",
")",
"\n",
"}"
] | // Count the total number of channels and patterns | [
"Count",
"the",
"total",
"number",
"of",
"channels",
"and",
"patterns"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L41-L45 | train |
alicebob/miniredis | pubsub.go | Channels | func (s *Subscriber) Channels() []string {
s.mu.Lock()
defer s.mu.Unlock()
var cs []string
for c := range s.channels {
cs = append(cs, c)
}
sort.Strings(cs)
return cs
} | go | func (s *Subscriber) Channels() []string {
s.mu.Lock()
defer s.mu.Unlock()
var cs []string
for c := range s.channels {
cs = append(cs, c)
}
sort.Strings(cs)
return cs
} | [
"func",
"(",
"s",
"*",
"Subscriber",
")",
"Channels",
"(",
")",
"[",
"]",
"string",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"var",
"cs",
"[",
"]",
"string",
"\n",
"for",
"c",
... | // List all subscribed channels, in alphabetical order | [
"List",
"all",
"subscribed",
"channels",
"in",
"alphabetical",
"order"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L92-L102 | train |
alicebob/miniredis | pubsub.go | Patterns | func (s *Subscriber) Patterns() []string {
s.mu.Lock()
defer s.mu.Unlock()
var ps []string
for p := range s.patterns {
ps = append(ps, p)
}
sort.Strings(ps)
return ps
} | go | func (s *Subscriber) Patterns() []string {
s.mu.Lock()
defer s.mu.Unlock()
var ps []string
for p := range s.patterns {
ps = append(ps, p)
}
sort.Strings(ps)
return ps
} | [
"func",
"(",
"s",
"*",
"Subscriber",
")",
"Patterns",
"(",
")",
"[",
"]",
"string",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"var",
"ps",
"[",
"]",
"string",
"\n",
"for",
"p",
... | // List all subscribed patterns, in alphabetical order | [
"List",
"all",
"subscribed",
"patterns",
"in",
"alphabetical",
"order"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L105-L115 | train |
alicebob/miniredis | pubsub.go | Publish | func (s *Subscriber) Publish(c, msg string) int {
s.mu.Lock()
defer s.mu.Unlock()
found := 0
subs:
for sub := range s.channels {
if sub == c {
s.publish <- PubsubMessage{c, msg}
found++
break subs
}
}
pats:
for _, pat := range s.patterns {
if pat.MatchString(c) {
s.publish <- PubsubMessage{c, msg}
found++
break pats
}
}
return found
} | go | func (s *Subscriber) Publish(c, msg string) int {
s.mu.Lock()
defer s.mu.Unlock()
found := 0
subs:
for sub := range s.channels {
if sub == c {
s.publish <- PubsubMessage{c, msg}
found++
break subs
}
}
pats:
for _, pat := range s.patterns {
if pat.MatchString(c) {
s.publish <- PubsubMessage{c, msg}
found++
break pats
}
}
return found
} | [
"func",
"(",
"s",
"*",
"Subscriber",
")",
"Publish",
"(",
"c",
",",
"msg",
"string",
")",
"int",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"found",
":=",
"0",
"\n",
"subs",
":",
... | // Publish a message. Will return return how often we sent the message (can be
// a match for a subscription and for a psubscription. | [
"Publish",
"a",
"message",
".",
"Will",
"return",
"return",
"how",
"often",
"we",
"sent",
"the",
"message",
"(",
"can",
"be",
"a",
"match",
"for",
"a",
"subscription",
"and",
"for",
"a",
"psubscription",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L119-L144 | train |
alicebob/miniredis | pubsub.go | activeChannels | func activeChannels(subs []*Subscriber, pat string) []string {
channels := map[string]struct{}{}
for _, s := range subs {
for c := range s.channels {
channels[c] = struct{}{}
}
}
var cpat *regexp.Regexp
if pat != "" {
cpat = compileChannelPattern(pat)
}
var cs []string
for k := range channels {
if cpat != nil && !cpat.MatchString(k) {
continue
}
cs = append(cs, k)
}
sort.Strings(cs)
return cs
} | go | func activeChannels(subs []*Subscriber, pat string) []string {
channels := map[string]struct{}{}
for _, s := range subs {
for c := range s.channels {
channels[c] = struct{}{}
}
}
var cpat *regexp.Regexp
if pat != "" {
cpat = compileChannelPattern(pat)
}
var cs []string
for k := range channels {
if cpat != nil && !cpat.MatchString(k) {
continue
}
cs = append(cs, k)
}
sort.Strings(cs)
return cs
} | [
"func",
"activeChannels",
"(",
"subs",
"[",
"]",
"*",
"Subscriber",
",",
"pat",
"string",
")",
"[",
"]",
"string",
"{",
"channels",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"subs",
... | // List all pubsub channels. If `pat` isn't empty channels names must match the
// pattern. Channels are returned alphabetically. | [
"List",
"all",
"pubsub",
"channels",
".",
"If",
"pat",
"isn",
"t",
"empty",
"channels",
"names",
"must",
"match",
"the",
"pattern",
".",
"Channels",
"are",
"returned",
"alphabetically",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L153-L175 | train |
alicebob/miniredis | pubsub.go | countPsubs | func countPsubs(subs []*Subscriber) int {
n := 0
for _, p := range subs {
n += len(p.patterns)
}
return n
} | go | func countPsubs(subs []*Subscriber) int {
n := 0
for _, p := range subs {
n += len(p.patterns)
}
return n
} | [
"func",
"countPsubs",
"(",
"subs",
"[",
"]",
"*",
"Subscriber",
")",
"int",
"{",
"n",
":=",
"0",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"subs",
"{",
"n",
"+=",
"len",
"(",
"p",
".",
"patterns",
")",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"... | // Count the total of all client psubscriptions. | [
"Count",
"the",
"total",
"of",
"all",
"client",
"psubscriptions",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L193-L199 | train |
alicebob/miniredis | cmd_scripting.go | requireGlobal | func requireGlobal(l *lua.LState, id, modName string) {
if err := l.CallByParam(lua.P{
Fn: l.GetGlobal("require"),
NRet: 1,
Protect: true,
}, lua.LString(modName)); err != nil {
panic(err)
}
mod := l.Get(-1)
l.Pop(1)
l.SetGlobal(id, mod)
} | go | func requireGlobal(l *lua.LState, id, modName string) {
if err := l.CallByParam(lua.P{
Fn: l.GetGlobal("require"),
NRet: 1,
Protect: true,
}, lua.LString(modName)); err != nil {
panic(err)
}
mod := l.Get(-1)
l.Pop(1)
l.SetGlobal(id, mod)
} | [
"func",
"requireGlobal",
"(",
"l",
"*",
"lua",
".",
"LState",
",",
"id",
",",
"modName",
"string",
")",
"{",
"if",
"err",
":=",
"l",
".",
"CallByParam",
"(",
"lua",
".",
"P",
"{",
"Fn",
":",
"l",
".",
"GetGlobal",
"(",
"\"require\"",
")",
",",
"N... | // requireGlobal imports module modName into the global namespace with the
// identifier id. panics if an error results from the function execution | [
"requireGlobal",
"imports",
"module",
"modName",
"into",
"the",
"global",
"namespace",
"with",
"the",
"identifier",
"id",
".",
"panics",
"if",
"an",
"error",
"results",
"from",
"the",
"function",
"execution"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_scripting.go#L218-L230 | train |
alicebob/miniredis | miniredis.go | NewMiniRedis | func NewMiniRedis() *Miniredis {
m := Miniredis{
dbs: map[int]*RedisDB{},
scripts: map[string]string{},
subscribers: map[*Subscriber]struct{}{},
}
m.signal = sync.NewCond(&m)
return &m
} | go | func NewMiniRedis() *Miniredis {
m := Miniredis{
dbs: map[int]*RedisDB{},
scripts: map[string]string{},
subscribers: map[*Subscriber]struct{}{},
}
m.signal = sync.NewCond(&m)
return &m
} | [
"func",
"NewMiniRedis",
"(",
")",
"*",
"Miniredis",
"{",
"m",
":=",
"Miniredis",
"{",
"dbs",
":",
"map",
"[",
"int",
"]",
"*",
"RedisDB",
"{",
"}",
",",
"scripts",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
",",
"subscribers",
":",
"map",
... | // NewMiniRedis makes a new, non-started, Miniredis object. | [
"NewMiniRedis",
"makes",
"a",
"new",
"non",
"-",
"started",
"Miniredis",
"object",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L80-L88 | train |
alicebob/miniredis | miniredis.go | Close | func (m *Miniredis) Close() {
m.Lock()
if m.srv == nil {
m.Unlock()
return
}
srv := m.srv
m.srv = nil
m.Unlock()
// the OnDisconnect callbacks can lock m, so run Close() outside the lock.
srv.Close()
} | go | func (m *Miniredis) Close() {
m.Lock()
if m.srv == nil {
m.Unlock()
return
}
srv := m.srv
m.srv = nil
m.Unlock()
// the OnDisconnect callbacks can lock m, so run Close() outside the lock.
srv.Close()
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"Close",
"(",
")",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"if",
"m",
".",
"srv",
"==",
"nil",
"{",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"srv",
":=",
"m",
".",
"srv",
"\n",
... | // Close shuts down a Miniredis. | [
"Close",
"shuts",
"down",
"a",
"Miniredis",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L159-L173 | train |
alicebob/miniredis | miniredis.go | RequireAuth | func (m *Miniredis) RequireAuth(pw string) {
m.Lock()
defer m.Unlock()
m.password = pw
} | go | func (m *Miniredis) RequireAuth(pw string) {
m.Lock()
defer m.Unlock()
m.password = pw
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"RequireAuth",
"(",
"pw",
"string",
")",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"m",
".",
"password",
"=",
"pw",
"\n",
"}"
] | // RequireAuth makes every connection need to AUTH first. Disable again by
// setting an empty string. | [
"RequireAuth",
"makes",
"every",
"connection",
"need",
"to",
"AUTH",
"first",
".",
"Disable",
"again",
"by",
"setting",
"an",
"empty",
"string",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L177-L181 | train |
alicebob/miniredis | miniredis.go | DB | func (m *Miniredis) DB(i int) *RedisDB {
m.Lock()
defer m.Unlock()
return m.db(i)
} | go | func (m *Miniredis) DB(i int) *RedisDB {
m.Lock()
defer m.Unlock()
return m.db(i)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"DB",
"(",
"i",
"int",
")",
"*",
"RedisDB",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"m",
".",
"db",
"(",
"i",
")",
"\n",
"}"
] | // DB returns a DB by ID. | [
"DB",
"returns",
"a",
"DB",
"by",
"ID",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L184-L188 | train |
alicebob/miniredis | miniredis.go | db | func (m *Miniredis) db(i int) *RedisDB {
if db, ok := m.dbs[i]; ok {
return db
}
db := newRedisDB(i, &m.Mutex) // the DB has our lock.
m.dbs[i] = &db
return &db
} | go | func (m *Miniredis) db(i int) *RedisDB {
if db, ok := m.dbs[i]; ok {
return db
}
db := newRedisDB(i, &m.Mutex) // the DB has our lock.
m.dbs[i] = &db
return &db
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"db",
"(",
"i",
"int",
")",
"*",
"RedisDB",
"{",
"if",
"db",
",",
"ok",
":=",
"m",
".",
"dbs",
"[",
"i",
"]",
";",
"ok",
"{",
"return",
"db",
"\n",
"}",
"\n",
"db",
":=",
"newRedisDB",
"(",
"i",
",",... | // get DB. No locks! | [
"get",
"DB",
".",
"No",
"locks!"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L191-L198 | train |
alicebob/miniredis | miniredis.go | SwapDB | func (m *Miniredis) SwapDB(i, j int) bool {
m.Lock()
defer m.Unlock()
return m.swapDB(i, j)
} | go | func (m *Miniredis) SwapDB(i, j int) bool {
m.Lock()
defer m.Unlock()
return m.swapDB(i, j)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"SwapDB",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"m",
".",
"swapDB",
"(",
"i",
",",
"j",
")",
"\n",
"}"
... | // SwapDB swaps DBs by IDs. | [
"SwapDB",
"swaps",
"DBs",
"by",
"IDs",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L201-L205 | train |
alicebob/miniredis | miniredis.go | swapDB | func (m *Miniredis) swapDB(i, j int) bool {
db1 := m.db(i)
db2 := m.db(j)
db1.id = j
db2.id = i
m.dbs[i] = db2
m.dbs[j] = db1
return true
} | go | func (m *Miniredis) swapDB(i, j int) bool {
db1 := m.db(i)
db2 := m.db(j)
db1.id = j
db2.id = i
m.dbs[i] = db2
m.dbs[j] = db1
return true
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"swapDB",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"db1",
":=",
"m",
".",
"db",
"(",
"i",
")",
"\n",
"db2",
":=",
"m",
".",
"db",
"(",
"j",
")",
"\n",
"db1",
".",
"id",
"=",
"j",
"\n",
"db2",
... | // swap DB. No locks! | [
"swap",
"DB",
".",
"No",
"locks!"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L208-L219 | train |
alicebob/miniredis | miniredis.go | CommandCount | func (m *Miniredis) CommandCount() int {
m.Lock()
defer m.Unlock()
return int(m.srv.TotalCommands())
} | go | func (m *Miniredis) CommandCount() int {
m.Lock()
defer m.Unlock()
return int(m.srv.TotalCommands())
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"CommandCount",
"(",
")",
"int",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"int",
"(",
"m",
".",
"srv",
".",
"TotalCommands",
"(",
")",
")",
"\n",
"}"
... | // CommandCount returns the number of processed commands. | [
"CommandCount",
"returns",
"the",
"number",
"of",
"processed",
"commands",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L244-L248 | train |
alicebob/miniredis | miniredis.go | CurrentConnectionCount | func (m *Miniredis) CurrentConnectionCount() int {
m.Lock()
defer m.Unlock()
return m.srv.ClientsLen()
} | go | func (m *Miniredis) CurrentConnectionCount() int {
m.Lock()
defer m.Unlock()
return m.srv.ClientsLen()
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"CurrentConnectionCount",
"(",
")",
"int",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"m",
".",
"srv",
".",
"ClientsLen",
"(",
")",
"\n",
"}"
] | // CurrentConnectionCount returns the number of currently connected clients. | [
"CurrentConnectionCount",
"returns",
"the",
"number",
"of",
"currently",
"connected",
"clients",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L251-L255 | train |
alicebob/miniredis | miniredis.go | TotalConnectionCount | func (m *Miniredis) TotalConnectionCount() int {
m.Lock()
defer m.Unlock()
return int(m.srv.TotalConnections())
} | go | func (m *Miniredis) TotalConnectionCount() int {
m.Lock()
defer m.Unlock()
return int(m.srv.TotalConnections())
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"TotalConnectionCount",
"(",
")",
"int",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"int",
"(",
"m",
".",
"srv",
".",
"TotalConnections",
"(",
")",
")",
"... | // TotalConnectionCount returns the number of client connections since server start. | [
"TotalConnectionCount",
"returns",
"the",
"number",
"of",
"client",
"connections",
"since",
"server",
"start",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L258-L262 | train |
alicebob/miniredis | miniredis.go | FastForward | func (m *Miniredis) FastForward(duration time.Duration) {
m.Lock()
defer m.Unlock()
for _, db := range m.dbs {
db.fastForward(duration)
}
} | go | func (m *Miniredis) FastForward(duration time.Duration) {
m.Lock()
defer m.Unlock()
for _, db := range m.dbs {
db.fastForward(duration)
}
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"FastForward",
"(",
"duration",
"time",
".",
"Duration",
")",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"db",
":=",
"range",
"m",
".",
"dbs",
"{... | // FastForward decreases all TTLs by the given duration. All TTLs <= 0 will be
// expired. | [
"FastForward",
"decreases",
"all",
"TTLs",
"by",
"the",
"given",
"duration",
".",
"All",
"TTLs",
"<",
"=",
"0",
"will",
"be",
"expired",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L266-L272 | train |
alicebob/miniredis | miniredis.go | redigo | func (m *Miniredis) redigo() redigo.Conn {
c1, c2 := net.Pipe()
m.srv.ServeConn(c1)
c := redigo.NewConn(c2, 0, 0)
if m.password != "" {
if _, err := c.Do("AUTH", m.password); err != nil {
// ?
}
}
return c
} | go | func (m *Miniredis) redigo() redigo.Conn {
c1, c2 := net.Pipe()
m.srv.ServeConn(c1)
c := redigo.NewConn(c2, 0, 0)
if m.password != "" {
if _, err := c.Do("AUTH", m.password); err != nil {
// ?
}
}
return c
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"redigo",
"(",
")",
"redigo",
".",
"Conn",
"{",
"c1",
",",
"c2",
":=",
"net",
".",
"Pipe",
"(",
")",
"\n",
"m",
".",
"srv",
".",
"ServeConn",
"(",
"c1",
")",
"\n",
"c",
":=",
"redigo",
".",
"NewConn",
... | // redigo returns a redigo.Conn, connected using net.Pipe | [
"redigo",
"returns",
"a",
"redigo",
".",
"Conn",
"connected",
"using",
"net",
".",
"Pipe"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L275-L285 | train |
alicebob/miniredis | miniredis.go | Dump | func (m *Miniredis) Dump() string {
m.Lock()
defer m.Unlock()
var (
maxLen = 60
indent = " "
db = m.db(m.selectedDB)
r = ""
v = func(s string) string {
suffix := ""
if len(s) > maxLen {
suffix = fmt.Sprintf("...(%d)", len(s))
s = s[:maxLen-len(suffix)]
}
return fmt.Sprintf("%q%s", s, suffix)
}
)
for _, k := range db.allKeys() {
r += fmt.Sprintf("- %s\n", k)
t := db.t(k)
switch t {
case "string":
r += fmt.Sprintf("%s%s\n", indent, v(db.stringKeys[k]))
case "hash":
for _, hk := range db.hashFields(k) {
r += fmt.Sprintf("%s%s: %s\n", indent, hk, v(db.hashGet(k, hk)))
}
case "list":
for _, lk := range db.listKeys[k] {
r += fmt.Sprintf("%s%s\n", indent, v(lk))
}
case "set":
for _, mk := range db.setMembers(k) {
r += fmt.Sprintf("%s%s\n", indent, v(mk))
}
case "zset":
for _, el := range db.ssetElements(k) {
r += fmt.Sprintf("%s%f: %s\n", indent, el.score, v(el.member))
}
default:
r += fmt.Sprintf("%s(a %s, fixme!)\n", indent, t)
}
}
return r
} | go | func (m *Miniredis) Dump() string {
m.Lock()
defer m.Unlock()
var (
maxLen = 60
indent = " "
db = m.db(m.selectedDB)
r = ""
v = func(s string) string {
suffix := ""
if len(s) > maxLen {
suffix = fmt.Sprintf("...(%d)", len(s))
s = s[:maxLen-len(suffix)]
}
return fmt.Sprintf("%q%s", s, suffix)
}
)
for _, k := range db.allKeys() {
r += fmt.Sprintf("- %s\n", k)
t := db.t(k)
switch t {
case "string":
r += fmt.Sprintf("%s%s\n", indent, v(db.stringKeys[k]))
case "hash":
for _, hk := range db.hashFields(k) {
r += fmt.Sprintf("%s%s: %s\n", indent, hk, v(db.hashGet(k, hk)))
}
case "list":
for _, lk := range db.listKeys[k] {
r += fmt.Sprintf("%s%s\n", indent, v(lk))
}
case "set":
for _, mk := range db.setMembers(k) {
r += fmt.Sprintf("%s%s\n", indent, v(mk))
}
case "zset":
for _, el := range db.ssetElements(k) {
r += fmt.Sprintf("%s%f: %s\n", indent, el.score, v(el.member))
}
default:
r += fmt.Sprintf("%s(a %s, fixme!)\n", indent, t)
}
}
return r
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"Dump",
"(",
")",
"string",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"var",
"(",
"maxLen",
"=",
"60",
"\n",
"indent",
"=",
"\" \"",
"\n",
"db",
"=",
"m",
".... | // Dump returns a text version of the selected DB, usable for debugging. | [
"Dump",
"returns",
"a",
"text",
"version",
"of",
"the",
"selected",
"DB",
"usable",
"for",
"debugging",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L288-L333 | train |
alicebob/miniredis | miniredis.go | handleAuth | func (m *Miniredis) handleAuth(c *server.Peer) bool {
m.Lock()
defer m.Unlock()
if m.password == "" {
return true
}
if !getCtx(c).authenticated {
c.WriteError("NOAUTH Authentication required.")
return false
}
return true
} | go | func (m *Miniredis) handleAuth(c *server.Peer) bool {
m.Lock()
defer m.Unlock()
if m.password == "" {
return true
}
if !getCtx(c).authenticated {
c.WriteError("NOAUTH Authentication required.")
return false
}
return true
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"handleAuth",
"(",
"c",
"*",
"server",
".",
"Peer",
")",
"bool",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"if",
"m",
".",
"password",
"==",
"\"\"",
"{",
"return... | // handleAuth returns false if connection has no access. It sends the reply. | [
"handleAuth",
"returns",
"false",
"if",
"connection",
"has",
"no",
"access",
".",
"It",
"sends",
"the",
"reply",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L344-L355 | train |
alicebob/miniredis | miniredis.go | checkPubsub | func (m *Miniredis) checkPubsub(c *server.Peer) bool {
m.Lock()
defer m.Unlock()
ctx := getCtx(c)
if ctx.subscriber == nil {
return false
}
c.WriteError("ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context")
return true
} | go | func (m *Miniredis) checkPubsub(c *server.Peer) bool {
m.Lock()
defer m.Unlock()
ctx := getCtx(c)
if ctx.subscriber == nil {
return false
}
c.WriteError("ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context")
return true
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"checkPubsub",
"(",
"c",
"*",
"server",
".",
"Peer",
")",
"bool",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"ctx",
":=",
"getCtx",
"(",
"c",
")",
"\n",
"if",
"... | // handlePubsub sends an error to the user if the connection is in PUBSUB mode.
// It'll return true if it did. | [
"handlePubsub",
"sends",
"an",
"error",
"to",
"the",
"user",
"if",
"the",
"connection",
"is",
"in",
"PUBSUB",
"mode",
".",
"It",
"ll",
"return",
"true",
"if",
"it",
"did",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L359-L370 | train |
alicebob/miniredis | miniredis.go | setDirty | func setDirty(c *server.Peer) {
if c.Ctx == nil {
// No transaction. Not relevant.
return
}
getCtx(c).dirtyTransaction = true
} | go | func setDirty(c *server.Peer) {
if c.Ctx == nil {
// No transaction. Not relevant.
return
}
getCtx(c).dirtyTransaction = true
} | [
"func",
"setDirty",
"(",
"c",
"*",
"server",
".",
"Peer",
")",
"{",
"if",
"c",
".",
"Ctx",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"getCtx",
"(",
"c",
")",
".",
"dirtyTransaction",
"=",
"true",
"\n",
"}"
] | // setDirty can be called even when not in an tx. Is an no-op then. | [
"setDirty",
"can",
"be",
"called",
"even",
"when",
"not",
"in",
"an",
"tx",
".",
"Is",
"an",
"no",
"-",
"op",
"then",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L409-L415 | train |
alicebob/miniredis | miniredis.go | removeSubscriber | func (m *Miniredis) removeSubscriber(s *Subscriber) {
_, ok := m.subscribers[s]
delete(m.subscribers, s)
if ok {
s.Close()
}
} | go | func (m *Miniredis) removeSubscriber(s *Subscriber) {
_, ok := m.subscribers[s]
delete(m.subscribers, s)
if ok {
s.Close()
}
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"removeSubscriber",
"(",
"s",
"*",
"Subscriber",
")",
"{",
"_",
",",
"ok",
":=",
"m",
".",
"subscribers",
"[",
"s",
"]",
"\n",
"delete",
"(",
"m",
".",
"subscribers",
",",
"s",
")",
"\n",
"if",
"ok",
"{",
... | // closes and remove the subscriber. | [
"closes",
"and",
"remove",
"the",
"subscriber",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L426-L432 | train |
alicebob/miniredis | miniredis.go | subscribedState | func (m *Miniredis) subscribedState(c *server.Peer) *Subscriber {
ctx := getCtx(c)
sub := ctx.subscriber
if sub != nil {
return sub
}
sub = newSubscriber()
m.addSubscriber(sub)
c.OnDisconnect(func() {
m.Lock()
m.removeSubscriber(sub)
m.Unlock()
})
ctx.subscriber = sub
go monitorPublish(c, sub.publish)
return sub
} | go | func (m *Miniredis) subscribedState(c *server.Peer) *Subscriber {
ctx := getCtx(c)
sub := ctx.subscriber
if sub != nil {
return sub
}
sub = newSubscriber()
m.addSubscriber(sub)
c.OnDisconnect(func() {
m.Lock()
m.removeSubscriber(sub)
m.Unlock()
})
ctx.subscriber = sub
go monitorPublish(c, sub.publish)
return sub
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"subscribedState",
"(",
"c",
"*",
"server",
".",
"Peer",
")",
"*",
"Subscriber",
"{",
"ctx",
":=",
"getCtx",
"(",
"c",
")",
"\n",
"sub",
":=",
"ctx",
".",
"subscriber",
"\n",
"if",
"sub",
"!=",
"nil",
"{",
... | // enter 'subscribed state', or return the existing one. | [
"enter",
"subscribed",
"state",
"or",
"return",
"the",
"existing",
"one",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L443-L464 | train |
alicebob/miniredis | miniredis.go | endSubscriber | func endSubscriber(m *Miniredis, c *server.Peer) {
ctx := getCtx(c)
if sub := ctx.subscriber; sub != nil {
m.removeSubscriber(sub) // will Close() the sub
}
ctx.subscriber = nil
} | go | func endSubscriber(m *Miniredis, c *server.Peer) {
ctx := getCtx(c)
if sub := ctx.subscriber; sub != nil {
m.removeSubscriber(sub) // will Close() the sub
}
ctx.subscriber = nil
} | [
"func",
"endSubscriber",
"(",
"m",
"*",
"Miniredis",
",",
"c",
"*",
"server",
".",
"Peer",
")",
"{",
"ctx",
":=",
"getCtx",
"(",
"c",
")",
"\n",
"if",
"sub",
":=",
"ctx",
".",
"subscriber",
";",
"sub",
"!=",
"nil",
"{",
"m",
".",
"removeSubscriber"... | // whenever the p?sub count drops to 0 subscribed state should be stopped, and
// all redis commands are allowed again. | [
"whenever",
"the",
"p?sub",
"count",
"drops",
"to",
"0",
"subscribed",
"state",
"should",
"be",
"stopped",
"and",
"all",
"redis",
"commands",
"are",
"allowed",
"again",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L468-L474 | train |
alicebob/miniredis | sorted_set.go | elems | func (ss *sortedSet) elems() ssElems {
elems := make(ssElems, 0, len(*ss))
for e, s := range *ss {
elems = append(elems, ssElem{s, e})
}
return elems
} | go | func (ss *sortedSet) elems() ssElems {
elems := make(ssElems, 0, len(*ss))
for e, s := range *ss {
elems = append(elems, ssElem{s, e})
}
return elems
} | [
"func",
"(",
"ss",
"*",
"sortedSet",
")",
"elems",
"(",
")",
"ssElems",
"{",
"elems",
":=",
"make",
"(",
"ssElems",
",",
"0",
",",
"len",
"(",
"*",
"ss",
")",
")",
"\n",
"for",
"e",
",",
"s",
":=",
"range",
"*",
"ss",
"{",
"elems",
"=",
"appe... | // elems gives the list of ssElem, ready to sort. | [
"elems",
"gives",
"the",
"list",
"of",
"ssElem",
"ready",
"to",
"sort",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/sorted_set.go#L54-L60 | train |
alicebob/miniredis | cmd_generic.go | commandsGeneric | func commandsGeneric(m *Miniredis) {
m.srv.Register("DEL", m.cmdDel)
// DUMP
m.srv.Register("EXISTS", m.cmdExists)
m.srv.Register("EXPIRE", makeCmdExpire(m, false, time.Second))
m.srv.Register("EXPIREAT", makeCmdExpire(m, true, time.Second))
m.srv.Register("KEYS", m.cmdKeys)
// MIGRATE
m.srv.Register("MOVE", m.cmdMove)
// OBJECT
m.srv.Register("PERSIST", m.cmdPersist)
m.srv.Register("PEXPIRE", makeCmdExpire(m, false, time.Millisecond))
m.srv.Register("PEXPIREAT", makeCmdExpire(m, true, time.Millisecond))
m.srv.Register("PTTL", m.cmdPTTL)
m.srv.Register("RANDOMKEY", m.cmdRandomkey)
m.srv.Register("RENAME", m.cmdRename)
m.srv.Register("RENAMENX", m.cmdRenamenx)
// RESTORE
// SORT
m.srv.Register("TTL", m.cmdTTL)
m.srv.Register("TYPE", m.cmdType)
m.srv.Register("SCAN", m.cmdScan)
} | go | func commandsGeneric(m *Miniredis) {
m.srv.Register("DEL", m.cmdDel)
// DUMP
m.srv.Register("EXISTS", m.cmdExists)
m.srv.Register("EXPIRE", makeCmdExpire(m, false, time.Second))
m.srv.Register("EXPIREAT", makeCmdExpire(m, true, time.Second))
m.srv.Register("KEYS", m.cmdKeys)
// MIGRATE
m.srv.Register("MOVE", m.cmdMove)
// OBJECT
m.srv.Register("PERSIST", m.cmdPersist)
m.srv.Register("PEXPIRE", makeCmdExpire(m, false, time.Millisecond))
m.srv.Register("PEXPIREAT", makeCmdExpire(m, true, time.Millisecond))
m.srv.Register("PTTL", m.cmdPTTL)
m.srv.Register("RANDOMKEY", m.cmdRandomkey)
m.srv.Register("RENAME", m.cmdRename)
m.srv.Register("RENAMENX", m.cmdRenamenx)
// RESTORE
// SORT
m.srv.Register("TTL", m.cmdTTL)
m.srv.Register("TYPE", m.cmdType)
m.srv.Register("SCAN", m.cmdScan)
} | [
"func",
"commandsGeneric",
"(",
"m",
"*",
"Miniredis",
")",
"{",
"m",
".",
"srv",
".",
"Register",
"(",
"\"DEL\"",
",",
"m",
".",
"cmdDel",
")",
"\n",
"m",
".",
"srv",
".",
"Register",
"(",
"\"EXISTS\"",
",",
"m",
".",
"cmdExists",
")",
"\n",
"m",
... | // commandsGeneric handles EXPIRE, TTL, PERSIST, &c. | [
"commandsGeneric",
"handles",
"EXPIRE",
"TTL",
"PERSIST",
"&c",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_generic.go#L15-L37 | train |
alicebob/miniredis | cmd_generic.go | makeCmdExpire | func makeCmdExpire(m *Miniredis, unix bool, d time.Duration) func(*server.Peer, string, []string) {
return func(c *server.Peer, cmd string, args []string) {
if len(args) != 2 {
setDirty(c)
c.WriteError(errWrongNumber(cmd))
return
}
if !m.handleAuth(c) {
return
}
if m.checkPubsub(c) {
return
}
key := args[0]
value := args[1]
i, err := strconv.Atoi(value)
if err != nil {
setDirty(c)
c.WriteError(msgInvalidInt)
return
}
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)
// Key must be present.
if _, ok := db.keys[key]; !ok {
c.WriteInt(0)
return
}
if unix {
var ts time.Time
switch d {
case time.Millisecond:
ts = time.Unix(int64(i/1000), 1000000*int64(i%1000))
case time.Second:
ts = time.Unix(int64(i), 0)
default:
panic("invalid time unit (d). Fixme!")
}
now := m.now
if now.IsZero() {
now = time.Now().UTC()
}
db.ttl[key] = ts.Sub(now)
} else {
db.ttl[key] = time.Duration(i) * d
}
db.keyVersion[key]++
db.checkTTL(key)
c.WriteInt(1)
})
}
} | go | func makeCmdExpire(m *Miniredis, unix bool, d time.Duration) func(*server.Peer, string, []string) {
return func(c *server.Peer, cmd string, args []string) {
if len(args) != 2 {
setDirty(c)
c.WriteError(errWrongNumber(cmd))
return
}
if !m.handleAuth(c) {
return
}
if m.checkPubsub(c) {
return
}
key := args[0]
value := args[1]
i, err := strconv.Atoi(value)
if err != nil {
setDirty(c)
c.WriteError(msgInvalidInt)
return
}
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)
// Key must be present.
if _, ok := db.keys[key]; !ok {
c.WriteInt(0)
return
}
if unix {
var ts time.Time
switch d {
case time.Millisecond:
ts = time.Unix(int64(i/1000), 1000000*int64(i%1000))
case time.Second:
ts = time.Unix(int64(i), 0)
default:
panic("invalid time unit (d). Fixme!")
}
now := m.now
if now.IsZero() {
now = time.Now().UTC()
}
db.ttl[key] = ts.Sub(now)
} else {
db.ttl[key] = time.Duration(i) * d
}
db.keyVersion[key]++
db.checkTTL(key)
c.WriteInt(1)
})
}
} | [
"func",
"makeCmdExpire",
"(",
"m",
"*",
"Miniredis",
",",
"unix",
"bool",
",",
"d",
"time",
".",
"Duration",
")",
"func",
"(",
"*",
"server",
".",
"Peer",
",",
"string",
",",
"[",
"]",
"string",
")",
"{",
"return",
"func",
"(",
"c",
"*",
"server",
... | // generic expire command for EXPIRE, PEXPIRE, EXPIREAT, PEXPIREAT
// d is the time unit. If unix is set it'll be seen as a unixtimestamp and
// converted to a duration. | [
"generic",
"expire",
"command",
"for",
"EXPIRE",
"PEXPIRE",
"EXPIREAT",
"PEXPIREAT",
"d",
"is",
"the",
"time",
"unit",
".",
"If",
"unix",
"is",
"set",
"it",
"ll",
"be",
"seen",
"as",
"a",
"unixtimestamp",
"and",
"converted",
"to",
"a",
"duration",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_generic.go#L42-L96 | train |
alicebob/miniredis | redis.go | withTx | func withTx(
m *Miniredis,
c *server.Peer,
cb txCmd,
) {
ctx := getCtx(c)
if inTx(ctx) {
addTxCmd(ctx, cb)
c.WriteInline("QUEUED")
return
}
m.Lock()
cb(c, ctx)
// done, wake up anyone who waits on anything.
m.signal.Broadcast()
m.Unlock()
} | go | func withTx(
m *Miniredis,
c *server.Peer,
cb txCmd,
) {
ctx := getCtx(c)
if inTx(ctx) {
addTxCmd(ctx, cb)
c.WriteInline("QUEUED")
return
}
m.Lock()
cb(c, ctx)
// done, wake up anyone who waits on anything.
m.signal.Broadcast()
m.Unlock()
} | [
"func",
"withTx",
"(",
"m",
"*",
"Miniredis",
",",
"c",
"*",
"server",
".",
"Peer",
",",
"cb",
"txCmd",
",",
")",
"{",
"ctx",
":=",
"getCtx",
"(",
"c",
")",
"\n",
"if",
"inTx",
"(",
"ctx",
")",
"{",
"addTxCmd",
"(",
"ctx",
",",
"cb",
")",
"\n... | // withTx wraps the non-argument-checking part of command handling code in
// transaction logic. | [
"withTx",
"wraps",
"the",
"non",
"-",
"argument",
"-",
"checking",
"part",
"of",
"command",
"handling",
"code",
"in",
"transaction",
"logic",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/redis.go#L47-L63 | train |
alicebob/miniredis | redis.go | matchKeys | func matchKeys(keys []string, match string) []string {
re := patternRE(match)
if re == nil {
// Special case, the given pattern won't match anything / is
// invalid.
return nil
}
res := []string{}
for _, k := range keys {
if !re.MatchString(k) {
continue
}
res = append(res, k)
}
return res
} | go | func matchKeys(keys []string, match string) []string {
re := patternRE(match)
if re == nil {
// Special case, the given pattern won't match anything / is
// invalid.
return nil
}
res := []string{}
for _, k := range keys {
if !re.MatchString(k) {
continue
}
res = append(res, k)
}
return res
} | [
"func",
"matchKeys",
"(",
"keys",
"[",
"]",
"string",
",",
"match",
"string",
")",
"[",
"]",
"string",
"{",
"re",
":=",
"patternRE",
"(",
"match",
")",
"\n",
"if",
"re",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"res",
":=",
"[",
"]",
... | // matchKeys filters only matching keys.
// Will return an empty list on invalid match expression. | [
"matchKeys",
"filters",
"only",
"matching",
"keys",
".",
"Will",
"return",
"an",
"empty",
"list",
"on",
"invalid",
"match",
"expression",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/redis.go#L194-L209 | train |
alicebob/miniredis | db.go | allKeys | func (db *RedisDB) allKeys() []string {
res := make([]string, 0, len(db.keys))
for k := range db.keys {
res = append(res, k)
}
sort.Strings(res) // To make things deterministic.
return res
} | go | func (db *RedisDB) allKeys() []string {
res := make([]string, 0, len(db.keys))
for k := range db.keys {
res = append(res, k)
}
sort.Strings(res) // To make things deterministic.
return res
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"allKeys",
"(",
")",
"[",
"]",
"string",
"{",
"res",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"db",
".",
"keys",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"db",
".",
"keys",
... | // allKeys returns all keys. Sorted. | [
"allKeys",
"returns",
"all",
"keys",
".",
"Sorted",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L20-L27 | train |
alicebob/miniredis | db.go | flush | func (db *RedisDB) flush() {
db.keys = map[string]string{}
db.stringKeys = map[string]string{}
db.hashKeys = map[string]hashKey{}
db.listKeys = map[string]listKey{}
db.setKeys = map[string]setKey{}
db.sortedsetKeys = map[string]sortedSet{}
db.ttl = map[string]time.Duration{}
} | go | func (db *RedisDB) flush() {
db.keys = map[string]string{}
db.stringKeys = map[string]string{}
db.hashKeys = map[string]hashKey{}
db.listKeys = map[string]listKey{}
db.setKeys = map[string]setKey{}
db.sortedsetKeys = map[string]sortedSet{}
db.ttl = map[string]time.Duration{}
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"flush",
"(",
")",
"{",
"db",
".",
"keys",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"db",
".",
"stringKeys",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"db",
".",
"hashKeys... | // flush removes all keys and values. | [
"flush",
"removes",
"all",
"keys",
"and",
"values",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L30-L38 | train |
alicebob/miniredis | db.go | move | func (db *RedisDB) move(key string, to *RedisDB) bool {
if _, ok := to.keys[key]; ok {
return false
}
t, ok := db.keys[key]
if !ok {
return false
}
to.keys[key] = db.keys[key]
switch t {
case "string":
to.stringKeys[key] = db.stringKeys[key]
case "hash":
to.hashKeys[key] = db.hashKeys[key]
case "list":
to.listKeys[key] = db.listKeys[key]
case "set":
to.setKeys[key] = db.setKeys[key]
case "zset":
to.sortedsetKeys[key] = db.sortedsetKeys[key]
default:
panic("unhandled key type")
}
to.keyVersion[key]++
if v, ok := db.ttl[key]; ok {
to.ttl[key] = v
}
db.del(key, true)
return true
} | go | func (db *RedisDB) move(key string, to *RedisDB) bool {
if _, ok := to.keys[key]; ok {
return false
}
t, ok := db.keys[key]
if !ok {
return false
}
to.keys[key] = db.keys[key]
switch t {
case "string":
to.stringKeys[key] = db.stringKeys[key]
case "hash":
to.hashKeys[key] = db.hashKeys[key]
case "list":
to.listKeys[key] = db.listKeys[key]
case "set":
to.setKeys[key] = db.setKeys[key]
case "zset":
to.sortedsetKeys[key] = db.sortedsetKeys[key]
default:
panic("unhandled key type")
}
to.keyVersion[key]++
if v, ok := db.ttl[key]; ok {
to.ttl[key] = v
}
db.del(key, true)
return true
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"move",
"(",
"key",
"string",
",",
"to",
"*",
"RedisDB",
")",
"bool",
"{",
"if",
"_",
",",
"ok",
":=",
"to",
".",
"keys",
"[",
"key",
"]",
";",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"t",
",",
... | // move something to another db. Will return ok. Or not. | [
"move",
"something",
"to",
"another",
"db",
".",
"Will",
"return",
"ok",
".",
"Or",
"not",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L41-L71 | train |
alicebob/miniredis | db.go | stringIncr | func (db *RedisDB) stringIncr(k string, delta int) (int, error) {
v := 0
if sv, ok := db.stringKeys[k]; ok {
var err error
v, err = strconv.Atoi(sv)
if err != nil {
return 0, ErrIntValueError
}
}
v += delta
db.stringSet(k, strconv.Itoa(v))
return v, nil
} | go | func (db *RedisDB) stringIncr(k string, delta int) (int, error) {
v := 0
if sv, ok := db.stringKeys[k]; ok {
var err error
v, err = strconv.Atoi(sv)
if err != nil {
return 0, ErrIntValueError
}
}
v += delta
db.stringSet(k, strconv.Itoa(v))
return v, nil
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"stringIncr",
"(",
"k",
"string",
",",
"delta",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"v",
":=",
"0",
"\n",
"if",
"sv",
",",
"ok",
":=",
"db",
".",
"stringKeys",
"[",
"k",
"]",
";",
"ok",
"{",... | // change int key value | [
"change",
"int",
"key",
"value"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L139-L151 | train |
alicebob/miniredis | db.go | stringIncrfloat | func (db *RedisDB) stringIncrfloat(k string, delta float64) (float64, error) {
v := 0.0
if sv, ok := db.stringKeys[k]; ok {
var err error
v, err = strconv.ParseFloat(sv, 64)
if err != nil {
return 0, ErrFloatValueError
}
}
v += delta
db.stringSet(k, formatFloat(v))
return v, nil
} | go | func (db *RedisDB) stringIncrfloat(k string, delta float64) (float64, error) {
v := 0.0
if sv, ok := db.stringKeys[k]; ok {
var err error
v, err = strconv.ParseFloat(sv, 64)
if err != nil {
return 0, ErrFloatValueError
}
}
v += delta
db.stringSet(k, formatFloat(v))
return v, nil
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"stringIncrfloat",
"(",
"k",
"string",
",",
"delta",
"float64",
")",
"(",
"float64",
",",
"error",
")",
"{",
"v",
":=",
"0.0",
"\n",
"if",
"sv",
",",
"ok",
":=",
"db",
".",
"stringKeys",
"[",
"k",
"]",
";",... | // change float key value | [
"change",
"float",
"key",
"value"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L154-L166 | train |
alicebob/miniredis | db.go | listLpush | func (db *RedisDB) listLpush(k, v string) int {
l, ok := db.listKeys[k]
if !ok {
db.keys[k] = "list"
}
l = append([]string{v}, l...)
db.listKeys[k] = l
db.keyVersion[k]++
return len(l)
} | go | func (db *RedisDB) listLpush(k, v string) int {
l, ok := db.listKeys[k]
if !ok {
db.keys[k] = "list"
}
l = append([]string{v}, l...)
db.listKeys[k] = l
db.keyVersion[k]++
return len(l)
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"listLpush",
"(",
"k",
",",
"v",
"string",
")",
"int",
"{",
"l",
",",
"ok",
":=",
"db",
".",
"listKeys",
"[",
"k",
"]",
"\n",
"if",
"!",
"ok",
"{",
"db",
".",
"keys",
"[",
"k",
"]",
"=",
"\"list\"",
"... | // listLpush is 'left push', aka unshift. Returns the new length. | [
"listLpush",
"is",
"left",
"push",
"aka",
"unshift",
".",
"Returns",
"the",
"new",
"length",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L169-L178 | train |
alicebob/miniredis | db.go | listLpop | func (db *RedisDB) listLpop(k string) string {
l := db.listKeys[k]
el := l[0]
l = l[1:]
if len(l) == 0 {
db.del(k, true)
} else {
db.listKeys[k] = l
}
db.keyVersion[k]++
return el
} | go | func (db *RedisDB) listLpop(k string) string {
l := db.listKeys[k]
el := l[0]
l = l[1:]
if len(l) == 0 {
db.del(k, true)
} else {
db.listKeys[k] = l
}
db.keyVersion[k]++
return el
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"listLpop",
"(",
"k",
"string",
")",
"string",
"{",
"l",
":=",
"db",
".",
"listKeys",
"[",
"k",
"]",
"\n",
"el",
":=",
"l",
"[",
"0",
"]",
"\n",
"l",
"=",
"l",
"[",
"1",
":",
"]",
"\n",
"if",
"len",
... | // 'left pop', aka shift. | [
"left",
"pop",
"aka",
"shift",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L181-L192 | train |
alicebob/miniredis | db.go | setSet | func (db *RedisDB) setSet(k string, set setKey) {
db.keys[k] = "set"
db.setKeys[k] = set
db.keyVersion[k]++
} | go | func (db *RedisDB) setSet(k string, set setKey) {
db.keys[k] = "set"
db.setKeys[k] = set
db.keyVersion[k]++
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"setSet",
"(",
"k",
"string",
",",
"set",
"setKey",
")",
"{",
"db",
".",
"keys",
"[",
"k",
"]",
"=",
"\"set\"",
"\n",
"db",
".",
"setKeys",
"[",
"k",
"]",
"=",
"set",
"\n",
"db",
".",
"keyVersion",
"[",
... | // setset replaces a whole set. | [
"setset",
"replaces",
"a",
"whole",
"set",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L219-L223 | train |
alicebob/miniredis | db.go | setAdd | func (db *RedisDB) setAdd(k string, elems ...string) int {
s, ok := db.setKeys[k]
if !ok {
s = setKey{}
db.keys[k] = "set"
}
added := 0
for _, e := range elems {
if _, ok := s[e]; !ok {
added++
}
s[e] = struct{}{}
}
db.setKeys[k] = s
db.keyVersion[k]++
return added
} | go | func (db *RedisDB) setAdd(k string, elems ...string) int {
s, ok := db.setKeys[k]
if !ok {
s = setKey{}
db.keys[k] = "set"
}
added := 0
for _, e := range elems {
if _, ok := s[e]; !ok {
added++
}
s[e] = struct{}{}
}
db.setKeys[k] = s
db.keyVersion[k]++
return added
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"setAdd",
"(",
"k",
"string",
",",
"elems",
"...",
"string",
")",
"int",
"{",
"s",
",",
"ok",
":=",
"db",
".",
"setKeys",
"[",
"k",
"]",
"\n",
"if",
"!",
"ok",
"{",
"s",
"=",
"setKey",
"{",
"}",
"\n",
... | // setadd adds members to a set. Returns nr of new keys. | [
"setadd",
"adds",
"members",
"to",
"a",
"set",
".",
"Returns",
"nr",
"of",
"new",
"keys",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L226-L242 | train |
alicebob/miniredis | db.go | setRem | func (db *RedisDB) setRem(k string, fields ...string) int {
s, ok := db.setKeys[k]
if !ok {
return 0
}
removed := 0
for _, f := range fields {
if _, ok := s[f]; ok {
removed++
delete(s, f)
}
}
if len(s) == 0 {
db.del(k, true)
} else {
db.setKeys[k] = s
}
db.keyVersion[k]++
return removed
} | go | func (db *RedisDB) setRem(k string, fields ...string) int {
s, ok := db.setKeys[k]
if !ok {
return 0
}
removed := 0
for _, f := range fields {
if _, ok := s[f]; ok {
removed++
delete(s, f)
}
}
if len(s) == 0 {
db.del(k, true)
} else {
db.setKeys[k] = s
}
db.keyVersion[k]++
return removed
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"setRem",
"(",
"k",
"string",
",",
"fields",
"...",
"string",
")",
"int",
"{",
"s",
",",
"ok",
":=",
"db",
".",
"setKeys",
"[",
"k",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"0",
"\n",
"}",
"\n",
"rem... | // setrem removes members from a set. Returns nr of deleted keys. | [
"setrem",
"removes",
"members",
"from",
"a",
"set",
".",
"Returns",
"nr",
"of",
"deleted",
"keys",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L245-L264 | train |
alicebob/miniredis | db.go | setMembers | func (db *RedisDB) setMembers(k string) []string {
set := db.setKeys[k]
members := make([]string, 0, len(set))
for k := range set {
members = append(members, k)
}
sort.Strings(members)
return members
} | go | func (db *RedisDB) setMembers(k string) []string {
set := db.setKeys[k]
members := make([]string, 0, len(set))
for k := range set {
members = append(members, k)
}
sort.Strings(members)
return members
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"setMembers",
"(",
"k",
"string",
")",
"[",
"]",
"string",
"{",
"set",
":=",
"db",
".",
"setKeys",
"[",
"k",
"]",
"\n",
"members",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"set",
... | // All members of a set. | [
"All",
"members",
"of",
"a",
"set",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L267-L275 | train |
alicebob/miniredis | db.go | setIsMember | func (db *RedisDB) setIsMember(k, v string) bool {
set, ok := db.setKeys[k]
if !ok {
return false
}
_, ok = set[v]
return ok
} | go | func (db *RedisDB) setIsMember(k, v string) bool {
set, ok := db.setKeys[k]
if !ok {
return false
}
_, ok = set[v]
return ok
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"setIsMember",
"(",
"k",
",",
"v",
"string",
")",
"bool",
"{",
"set",
",",
"ok",
":=",
"db",
".",
"setKeys",
"[",
"k",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"_",
",",
"ok"... | // Is a SET value present? | [
"Is",
"a",
"SET",
"value",
"present?"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L278-L285 | train |
alicebob/miniredis | db.go | hashGet | func (db *RedisDB) hashGet(key, field string) string {
return db.hashKeys[key][field]
} | go | func (db *RedisDB) hashGet(key, field string) string {
return db.hashKeys[key][field]
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"hashGet",
"(",
"key",
",",
"field",
"string",
")",
"string",
"{",
"return",
"db",
".",
"hashKeys",
"[",
"key",
"]",
"[",
"field",
"]",
"\n",
"}"
] | // hashGet a value | [
"hashGet",
"a",
"value"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L299-L301 | train |
alicebob/miniredis | db.go | hashSet | func (db *RedisDB) hashSet(k, f, v string) bool {
if t, ok := db.keys[k]; ok && t != "hash" {
db.del(k, true)
}
db.keys[k] = "hash"
if _, ok := db.hashKeys[k]; !ok {
db.hashKeys[k] = map[string]string{}
}
_, ok := db.hashKeys[k][f]
db.hashKeys[k][f] = v
db.keyVersion[k]++
return ok
} | go | func (db *RedisDB) hashSet(k, f, v string) bool {
if t, ok := db.keys[k]; ok && t != "hash" {
db.del(k, true)
}
db.keys[k] = "hash"
if _, ok := db.hashKeys[k]; !ok {
db.hashKeys[k] = map[string]string{}
}
_, ok := db.hashKeys[k][f]
db.hashKeys[k][f] = v
db.keyVersion[k]++
return ok
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"hashSet",
"(",
"k",
",",
"f",
",",
"v",
"string",
")",
"bool",
"{",
"if",
"t",
",",
"ok",
":=",
"db",
".",
"keys",
"[",
"k",
"]",
";",
"ok",
"&&",
"t",
"!=",
"\"hash\"",
"{",
"db",
".",
"del",
"(",
... | // hashSet returns whether the key already existed | [
"hashSet",
"returns",
"whether",
"the",
"key",
"already",
"existed"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L304-L316 | train |
alicebob/miniredis | db.go | hashIncr | func (db *RedisDB) hashIncr(key, field string, delta int) (int, error) {
v := 0
if h, ok := db.hashKeys[key]; ok {
if f, ok := h[field]; ok {
var err error
v, err = strconv.Atoi(f)
if err != nil {
return 0, ErrIntValueError
}
}
}
v += delta
db.hashSet(key, field, strconv.Itoa(v))
return v, nil
} | go | func (db *RedisDB) hashIncr(key, field string, delta int) (int, error) {
v := 0
if h, ok := db.hashKeys[key]; ok {
if f, ok := h[field]; ok {
var err error
v, err = strconv.Atoi(f)
if err != nil {
return 0, ErrIntValueError
}
}
}
v += delta
db.hashSet(key, field, strconv.Itoa(v))
return v, nil
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"hashIncr",
"(",
"key",
",",
"field",
"string",
",",
"delta",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"v",
":=",
"0",
"\n",
"if",
"h",
",",
"ok",
":=",
"db",
".",
"hashKeys",
"[",
"key",
"]",
";... | // hashIncr changes int key value | [
"hashIncr",
"changes",
"int",
"key",
"value"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L319-L333 | train |
alicebob/miniredis | db.go | hashIncrfloat | func (db *RedisDB) hashIncrfloat(key, field string, delta float64) (float64, error) {
v := 0.0
if h, ok := db.hashKeys[key]; ok {
if f, ok := h[field]; ok {
var err error
v, err = strconv.ParseFloat(f, 64)
if err != nil {
return 0, ErrFloatValueError
}
}
}
v += delta
db.hashSet(key, field, formatFloat(v))
return v, nil
} | go | func (db *RedisDB) hashIncrfloat(key, field string, delta float64) (float64, error) {
v := 0.0
if h, ok := db.hashKeys[key]; ok {
if f, ok := h[field]; ok {
var err error
v, err = strconv.ParseFloat(f, 64)
if err != nil {
return 0, ErrFloatValueError
}
}
}
v += delta
db.hashSet(key, field, formatFloat(v))
return v, nil
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"hashIncrfloat",
"(",
"key",
",",
"field",
"string",
",",
"delta",
"float64",
")",
"(",
"float64",
",",
"error",
")",
"{",
"v",
":=",
"0.0",
"\n",
"if",
"h",
",",
"ok",
":=",
"db",
".",
"hashKeys",
"[",
"ke... | // hashIncrfloat changes float key value | [
"hashIncrfloat",
"changes",
"float",
"key",
"value"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L336-L350 | train |
alicebob/miniredis | db.go | sortedSet | func (db *RedisDB) sortedSet(key string) map[string]float64 {
ss := db.sortedsetKeys[key]
return map[string]float64(ss)
} | go | func (db *RedisDB) sortedSet(key string) map[string]float64 {
ss := db.sortedsetKeys[key]
return map[string]float64(ss)
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"sortedSet",
"(",
"key",
"string",
")",
"map",
"[",
"string",
"]",
"float64",
"{",
"ss",
":=",
"db",
".",
"sortedsetKeys",
"[",
"key",
"]",
"\n",
"return",
"map",
"[",
"string",
"]",
"float64",
"(",
"ss",
")"... | // sortedSet set returns a sortedSet as map | [
"sortedSet",
"set",
"returns",
"a",
"sortedSet",
"as",
"map"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L353-L356 | train |
alicebob/miniredis | db.go | ssetSet | func (db *RedisDB) ssetSet(key string, sset sortedSet) {
db.keys[key] = "zset"
db.keyVersion[key]++
db.sortedsetKeys[key] = sset
} | go | func (db *RedisDB) ssetSet(key string, sset sortedSet) {
db.keys[key] = "zset"
db.keyVersion[key]++
db.sortedsetKeys[key] = sset
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"ssetSet",
"(",
"key",
"string",
",",
"sset",
"sortedSet",
")",
"{",
"db",
".",
"keys",
"[",
"key",
"]",
"=",
"\"zset\"",
"\n",
"db",
".",
"keyVersion",
"[",
"key",
"]",
"++",
"\n",
"db",
".",
"sortedsetKeys"... | // ssetSet sets a complete sorted set. | [
"ssetSet",
"sets",
"a",
"complete",
"sorted",
"set",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L359-L363 | train |
alicebob/miniredis | db.go | ssetAdd | func (db *RedisDB) ssetAdd(key string, score float64, member string) bool {
ss, ok := db.sortedsetKeys[key]
if !ok {
ss = newSortedSet()
db.keys[key] = "zset"
}
_, ok = ss[member]
ss[member] = score
db.sortedsetKeys[key] = ss
db.keyVersion[key]++
return !ok
} | go | func (db *RedisDB) ssetAdd(key string, score float64, member string) bool {
ss, ok := db.sortedsetKeys[key]
if !ok {
ss = newSortedSet()
db.keys[key] = "zset"
}
_, ok = ss[member]
ss[member] = score
db.sortedsetKeys[key] = ss
db.keyVersion[key]++
return !ok
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"ssetAdd",
"(",
"key",
"string",
",",
"score",
"float64",
",",
"member",
"string",
")",
"bool",
"{",
"ss",
",",
"ok",
":=",
"db",
".",
"sortedsetKeys",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"ss",
"="... | // ssetAdd adds member to a sorted set. Returns whether this was a new member. | [
"ssetAdd",
"adds",
"member",
"to",
"a",
"sorted",
"set",
".",
"Returns",
"whether",
"this",
"was",
"a",
"new",
"member",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L366-L377 | train |
alicebob/miniredis | db.go | ssetMembers | func (db *RedisDB) ssetMembers(key string) []string {
ss, ok := db.sortedsetKeys[key]
if !ok {
return nil
}
elems := ss.byScore(asc)
members := make([]string, 0, len(elems))
for _, e := range elems {
members = append(members, e.member)
}
return members
} | go | func (db *RedisDB) ssetMembers(key string) []string {
ss, ok := db.sortedsetKeys[key]
if !ok {
return nil
}
elems := ss.byScore(asc)
members := make([]string, 0, len(elems))
for _, e := range elems {
members = append(members, e.member)
}
return members
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"ssetMembers",
"(",
"key",
"string",
")",
"[",
"]",
"string",
"{",
"ss",
",",
"ok",
":=",
"db",
".",
"sortedsetKeys",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"elems",
... | // All members from a sorted set, ordered by score. | [
"All",
"members",
"from",
"a",
"sorted",
"set",
"ordered",
"by",
"score",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L380-L391 | train |
alicebob/miniredis | db.go | ssetElements | func (db *RedisDB) ssetElements(key string) ssElems {
ss, ok := db.sortedsetKeys[key]
if !ok {
return nil
}
return ss.byScore(asc)
} | go | func (db *RedisDB) ssetElements(key string) ssElems {
ss, ok := db.sortedsetKeys[key]
if !ok {
return nil
}
return ss.byScore(asc)
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"ssetElements",
"(",
"key",
"string",
")",
"ssElems",
"{",
"ss",
",",
"ok",
":=",
"db",
".",
"sortedsetKeys",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"ss",
"... | // All members+scores from a sorted set, ordered by score. | [
"All",
"members",
"+",
"scores",
"from",
"a",
"sorted",
"set",
"ordered",
"by",
"score",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L394-L400 | train |
alicebob/miniredis | db.go | ssetCard | func (db *RedisDB) ssetCard(key string) int {
ss := db.sortedsetKeys[key]
return ss.card()
} | go | func (db *RedisDB) ssetCard(key string) int {
ss := db.sortedsetKeys[key]
return ss.card()
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"ssetCard",
"(",
"key",
"string",
")",
"int",
"{",
"ss",
":=",
"db",
".",
"sortedsetKeys",
"[",
"key",
"]",
"\n",
"return",
"ss",
".",
"card",
"(",
")",
"\n",
"}"
] | // ssetCard is the sorted set cardinality. | [
"ssetCard",
"is",
"the",
"sorted",
"set",
"cardinality",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L403-L406 | train |
alicebob/miniredis | db.go | ssetRank | func (db *RedisDB) ssetRank(key, member string, d direction) (int, bool) {
ss := db.sortedsetKeys[key]
return ss.rankByScore(member, d)
} | go | func (db *RedisDB) ssetRank(key, member string, d direction) (int, bool) {
ss := db.sortedsetKeys[key]
return ss.rankByScore(member, d)
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"ssetRank",
"(",
"key",
",",
"member",
"string",
",",
"d",
"direction",
")",
"(",
"int",
",",
"bool",
")",
"{",
"ss",
":=",
"db",
".",
"sortedsetKeys",
"[",
"key",
"]",
"\n",
"return",
"ss",
".",
"rankByScore... | // ssetRank is the sorted set rank. | [
"ssetRank",
"is",
"the",
"sorted",
"set",
"rank",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L409-L412 | train |
alicebob/miniredis | db.go | ssetScore | func (db *RedisDB) ssetScore(key, member string) float64 {
ss := db.sortedsetKeys[key]
return ss[member]
} | go | func (db *RedisDB) ssetScore(key, member string) float64 {
ss := db.sortedsetKeys[key]
return ss[member]
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"ssetScore",
"(",
"key",
",",
"member",
"string",
")",
"float64",
"{",
"ss",
":=",
"db",
".",
"sortedsetKeys",
"[",
"key",
"]",
"\n",
"return",
"ss",
"[",
"member",
"]",
"\n",
"}"
] | // ssetScore is sorted set score. | [
"ssetScore",
"is",
"sorted",
"set",
"score",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L415-L418 | train |
alicebob/miniredis | db.go | ssetRem | func (db *RedisDB) ssetRem(key, member string) bool {
ss := db.sortedsetKeys[key]
_, ok := ss[member]
delete(ss, member)
if len(ss) == 0 {
// Delete key on removal of last member
db.del(key, true)
}
return ok
} | go | func (db *RedisDB) ssetRem(key, member string) bool {
ss := db.sortedsetKeys[key]
_, ok := ss[member]
delete(ss, member)
if len(ss) == 0 {
// Delete key on removal of last member
db.del(key, true)
}
return ok
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"ssetRem",
"(",
"key",
",",
"member",
"string",
")",
"bool",
"{",
"ss",
":=",
"db",
".",
"sortedsetKeys",
"[",
"key",
"]",
"\n",
"_",
",",
"ok",
":=",
"ss",
"[",
"member",
"]",
"\n",
"delete",
"(",
"ss",
... | // ssetRem is sorted set key delete. | [
"ssetRem",
"is",
"sorted",
"set",
"key",
"delete",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L421-L430 | train |
alicebob/miniredis | db.go | ssetExists | func (db *RedisDB) ssetExists(key, member string) bool {
ss := db.sortedsetKeys[key]
_, ok := ss[member]
return ok
} | go | func (db *RedisDB) ssetExists(key, member string) bool {
ss := db.sortedsetKeys[key]
_, ok := ss[member]
return ok
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"ssetExists",
"(",
"key",
",",
"member",
"string",
")",
"bool",
"{",
"ss",
":=",
"db",
".",
"sortedsetKeys",
"[",
"key",
"]",
"\n",
"_",
",",
"ok",
":=",
"ss",
"[",
"member",
"]",
"\n",
"return",
"ok",
"\n"... | // ssetExists tells if a member exists in a sorted set. | [
"ssetExists",
"tells",
"if",
"a",
"member",
"exists",
"in",
"a",
"sorted",
"set",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L433-L437 | train |
alicebob/miniredis | db.go | ssetIncrby | func (db *RedisDB) ssetIncrby(k, m string, delta float64) float64 {
ss, ok := db.sortedsetKeys[k]
if !ok {
ss = newSortedSet()
db.keys[k] = "zset"
db.sortedsetKeys[k] = ss
}
v, _ := ss.get(m)
v += delta
ss.set(v, m)
db.keyVersion[k]++
return v
} | go | func (db *RedisDB) ssetIncrby(k, m string, delta float64) float64 {
ss, ok := db.sortedsetKeys[k]
if !ok {
ss = newSortedSet()
db.keys[k] = "zset"
db.sortedsetKeys[k] = ss
}
v, _ := ss.get(m)
v += delta
ss.set(v, m)
db.keyVersion[k]++
return v
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"ssetIncrby",
"(",
"k",
",",
"m",
"string",
",",
"delta",
"float64",
")",
"float64",
"{",
"ss",
",",
"ok",
":=",
"db",
".",
"sortedsetKeys",
"[",
"k",
"]",
"\n",
"if",
"!",
"ok",
"{",
"ss",
"=",
"newSortedS... | // ssetIncrby changes float sorted set score. | [
"ssetIncrby",
"changes",
"float",
"sorted",
"set",
"score",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L440-L453 | train |
alicebob/miniredis | db.go | fastForward | func (db *RedisDB) fastForward(duration time.Duration) {
for _, key := range db.allKeys() {
if value, ok := db.ttl[key]; ok {
db.ttl[key] = value - duration
db.checkTTL(key)
}
}
} | go | func (db *RedisDB) fastForward(duration time.Duration) {
for _, key := range db.allKeys() {
if value, ok := db.ttl[key]; ok {
db.ttl[key] = value - duration
db.checkTTL(key)
}
}
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"fastForward",
"(",
"duration",
"time",
".",
"Duration",
")",
"{",
"for",
"_",
",",
"key",
":=",
"range",
"db",
".",
"allKeys",
"(",
")",
"{",
"if",
"value",
",",
"ok",
":=",
"db",
".",
"ttl",
"[",
"key",
... | // fastForward proceeds the current timestamp with duration, works as a time machine | [
"fastForward",
"proceeds",
"the",
"current",
"timestamp",
"with",
"duration",
"works",
"as",
"a",
"time",
"machine"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/db.go#L538-L545 | train |
alicebob/miniredis | cmd_sorted_set.go | commandsSortedSet | func commandsSortedSet(m *Miniredis) {
m.srv.Register("ZADD", m.cmdZadd)
m.srv.Register("ZCARD", m.cmdZcard)
m.srv.Register("ZCOUNT", m.cmdZcount)
m.srv.Register("ZINCRBY", m.cmdZincrby)
m.srv.Register("ZINTERSTORE", m.cmdZinterstore)
m.srv.Register("ZLEXCOUNT", m.cmdZlexcount)
m.srv.Register("ZRANGE", m.makeCmdZrange(false))
m.srv.Register("ZRANGEBYLEX", m.makeCmdZrangebylex(false))
m.srv.Register("ZRANGEBYSCORE", m.makeCmdZrangebyscore(false))
m.srv.Register("ZRANK", m.makeCmdZrank(false))
m.srv.Register("ZREM", m.cmdZrem)
m.srv.Register("ZREMRANGEBYLEX", m.cmdZremrangebylex)
m.srv.Register("ZREMRANGEBYRANK", m.cmdZremrangebyrank)
m.srv.Register("ZREMRANGEBYSCORE", m.cmdZremrangebyscore)
m.srv.Register("ZREVRANGE", m.makeCmdZrange(true))
m.srv.Register("ZREVRANGEBYLEX", m.makeCmdZrangebylex(true))
m.srv.Register("ZREVRANGEBYSCORE", m.makeCmdZrangebyscore(true))
m.srv.Register("ZREVRANK", m.makeCmdZrank(true))
m.srv.Register("ZSCORE", m.cmdZscore)
m.srv.Register("ZUNIONSTORE", m.cmdZunionstore)
m.srv.Register("ZSCAN", m.cmdZscan)
m.srv.Register("ZPOPMAX", m.cmdZpopmax(true))
m.srv.Register("ZPOPMIN", m.cmdZpopmax(false))
} | go | func commandsSortedSet(m *Miniredis) {
m.srv.Register("ZADD", m.cmdZadd)
m.srv.Register("ZCARD", m.cmdZcard)
m.srv.Register("ZCOUNT", m.cmdZcount)
m.srv.Register("ZINCRBY", m.cmdZincrby)
m.srv.Register("ZINTERSTORE", m.cmdZinterstore)
m.srv.Register("ZLEXCOUNT", m.cmdZlexcount)
m.srv.Register("ZRANGE", m.makeCmdZrange(false))
m.srv.Register("ZRANGEBYLEX", m.makeCmdZrangebylex(false))
m.srv.Register("ZRANGEBYSCORE", m.makeCmdZrangebyscore(false))
m.srv.Register("ZRANK", m.makeCmdZrank(false))
m.srv.Register("ZREM", m.cmdZrem)
m.srv.Register("ZREMRANGEBYLEX", m.cmdZremrangebylex)
m.srv.Register("ZREMRANGEBYRANK", m.cmdZremrangebyrank)
m.srv.Register("ZREMRANGEBYSCORE", m.cmdZremrangebyscore)
m.srv.Register("ZREVRANGE", m.makeCmdZrange(true))
m.srv.Register("ZREVRANGEBYLEX", m.makeCmdZrangebylex(true))
m.srv.Register("ZREVRANGEBYSCORE", m.makeCmdZrangebyscore(true))
m.srv.Register("ZREVRANK", m.makeCmdZrank(true))
m.srv.Register("ZSCORE", m.cmdZscore)
m.srv.Register("ZUNIONSTORE", m.cmdZunionstore)
m.srv.Register("ZSCAN", m.cmdZscan)
m.srv.Register("ZPOPMAX", m.cmdZpopmax(true))
m.srv.Register("ZPOPMIN", m.cmdZpopmax(false))
} | [
"func",
"commandsSortedSet",
"(",
"m",
"*",
"Miniredis",
")",
"{",
"m",
".",
"srv",
".",
"Register",
"(",
"\"ZADD\"",
",",
"m",
".",
"cmdZadd",
")",
"\n",
"m",
".",
"srv",
".",
"Register",
"(",
"\"ZCARD\"",
",",
"m",
".",
"cmdZcard",
")",
"\n",
"m"... | // commandsSortedSet handles all sorted set operations. | [
"commandsSortedSet",
"handles",
"all",
"sorted",
"set",
"operations",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_sorted_set.go#L19-L43 | train |
alicebob/miniredis | cmd_sorted_set.go | makeCmdZrank | func (m *Miniredis) makeCmdZrank(reverse bool) server.Cmd {
return func(c *server.Peer, cmd string, args []string) {
if len(args) != 2 {
setDirty(c)
c.WriteError(errWrongNumber(cmd))
return
}
if !m.handleAuth(c) {
return
}
if m.checkPubsub(c) {
return
}
key, member := args[0], args[1]
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(key) {
c.WriteNull()
return
}
if db.t(key) != "zset" {
c.WriteError(ErrWrongType.Error())
return
}
direction := asc
if reverse {
direction = desc
}
rank, ok := db.ssetRank(key, member, direction)
if !ok {
c.WriteNull()
return
}
c.WriteInt(rank)
})
}
} | go | func (m *Miniredis) makeCmdZrank(reverse bool) server.Cmd {
return func(c *server.Peer, cmd string, args []string) {
if len(args) != 2 {
setDirty(c)
c.WriteError(errWrongNumber(cmd))
return
}
if !m.handleAuth(c) {
return
}
if m.checkPubsub(c) {
return
}
key, member := args[0], args[1]
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(key) {
c.WriteNull()
return
}
if db.t(key) != "zset" {
c.WriteError(ErrWrongType.Error())
return
}
direction := asc
if reverse {
direction = desc
}
rank, ok := db.ssetRank(key, member, direction)
if !ok {
c.WriteNull()
return
}
c.WriteInt(rank)
})
}
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"makeCmdZrank",
"(",
"reverse",
"bool",
")",
"server",
".",
"Cmd",
"{",
"return",
"func",
"(",
"c",
"*",
"server",
".",
"Peer",
",",
"cmd",
"string",
",",
"args",
"[",
"]",
"string",
")",
"{",
"if",
"len",
... | // ZRANK and ZREVRANK | [
"ZRANK",
"and",
"ZREVRANK"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_sorted_set.go#L778-L819 | train |
alicebob/miniredis | cmd_sorted_set.go | parseFloatRange | func parseFloatRange(s string) (float64, bool, error) {
if len(s) == 0 {
return 0, false, nil
}
inclusive := true
if s[0] == '(' {
s = s[1:]
inclusive = false
}
f, err := strconv.ParseFloat(s, 64)
return f, inclusive, err
} | go | func parseFloatRange(s string) (float64, bool, error) {
if len(s) == 0 {
return 0, false, nil
}
inclusive := true
if s[0] == '(' {
s = s[1:]
inclusive = false
}
f, err := strconv.ParseFloat(s, 64)
return f, inclusive, err
} | [
"func",
"parseFloatRange",
"(",
"s",
"string",
")",
"(",
"float64",
",",
"bool",
",",
"error",
")",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"0",
",",
"false",
",",
"nil",
"\n",
"}",
"\n",
"inclusive",
":=",
"true",
"\n",
"if",
... | // parseFloatRange handles ZRANGEBYSCORE floats. They are inclusive unless the
// string starts with '(' | [
"parseFloatRange",
"handles",
"ZRANGEBYSCORE",
"floats",
".",
"They",
"are",
"inclusive",
"unless",
"the",
"string",
"starts",
"with",
"("
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_sorted_set.go#L1054-L1065 | train |
alicebob/miniredis | cmd_sorted_set.go | parseLexrange | func parseLexrange(s string) (string, bool, error) {
if len(s) == 0 {
return "", false, errInvalidRangeItem
}
if s == "+" || s == "-" {
return s, false, nil
}
switch s[0] {
case '(':
return s[1:], false, nil
case '[':
return s[1:], true, nil
default:
return "", false, errInvalidRangeItem
}
} | go | func parseLexrange(s string) (string, bool, error) {
if len(s) == 0 {
return "", false, errInvalidRangeItem
}
if s == "+" || s == "-" {
return s, false, nil
}
switch s[0] {
case '(':
return s[1:], false, nil
case '[':
return s[1:], true, nil
default:
return "", false, errInvalidRangeItem
}
} | [
"func",
"parseLexrange",
"(",
"s",
"string",
")",
"(",
"string",
",",
"bool",
",",
"error",
")",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"\"\"",
",",
"false",
",",
"errInvalidRangeItem",
"\n",
"}",
"\n",
"if",
"s",
"==",
"\"+\"",... | // parseLexrange handles ZRANGEBYLEX ranges. They start with '[', '(', or are
// '+' or '-'.
// Returns range, inclusive, error.
// On '+' or '-' that's just returned. | [
"parseLexrange",
"handles",
"ZRANGEBYLEX",
"ranges",
".",
"They",
"start",
"with",
"[",
"(",
"or",
"are",
"+",
"or",
"-",
".",
"Returns",
"range",
"inclusive",
"error",
".",
"On",
"+",
"or",
"-",
"that",
"s",
"just",
"returned",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_sorted_set.go#L1071-L1086 | train |
alicebob/miniredis | cmd_sorted_set.go | withSSRange | func withSSRange(members ssElems, min float64, minIncl bool, max float64, maxIncl bool) ssElems {
gt := func(a, b float64) bool { return a > b }
gteq := func(a, b float64) bool { return a >= b }
mincmp := gt
if minIncl {
mincmp = gteq
}
for i, m := range members {
if mincmp(m.score, min) {
members = members[i:]
goto checkmax
}
}
// all elements were smaller
return nil
checkmax:
maxcmp := gteq
if maxIncl {
maxcmp = gt
}
for i, m := range members {
if maxcmp(m.score, max) {
members = members[:i]
break
}
}
return members
} | go | func withSSRange(members ssElems, min float64, minIncl bool, max float64, maxIncl bool) ssElems {
gt := func(a, b float64) bool { return a > b }
gteq := func(a, b float64) bool { return a >= b }
mincmp := gt
if minIncl {
mincmp = gteq
}
for i, m := range members {
if mincmp(m.score, min) {
members = members[i:]
goto checkmax
}
}
// all elements were smaller
return nil
checkmax:
maxcmp := gteq
if maxIncl {
maxcmp = gt
}
for i, m := range members {
if maxcmp(m.score, max) {
members = members[:i]
break
}
}
return members
} | [
"func",
"withSSRange",
"(",
"members",
"ssElems",
",",
"min",
"float64",
",",
"minIncl",
"bool",
",",
"max",
"float64",
",",
"maxIncl",
"bool",
")",
"ssElems",
"{",
"gt",
":=",
"func",
"(",
"a",
",",
"b",
"float64",
")",
"bool",
"{",
"return",
"a",
"... | // withSSRange limits a list of sorted set elements by the ZRANGEBYSCORE range
// logic. | [
"withSSRange",
"limits",
"a",
"list",
"of",
"sorted",
"set",
"elements",
"by",
"the",
"ZRANGEBYSCORE",
"range",
"logic",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_sorted_set.go#L1090-L1120 | train |
alicebob/miniredis | cmd_sorted_set.go | withLexRange | func withLexRange(members []string, min string, minIncl bool, max string, maxIncl bool) []string {
if max == "-" || min == "+" {
return nil
}
if min != "-" {
if minIncl {
for i, m := range members {
if m >= min {
members = members[i:]
break
}
}
} else {
// Excluding min
for i, m := range members {
if m > min {
members = members[i:]
break
}
}
}
}
if max != "+" {
if maxIncl {
for i, m := range members {
if m > max {
members = members[:i]
break
}
}
} else {
// Excluding max
for i, m := range members {
if m >= max {
members = members[:i]
break
}
}
}
}
return members
} | go | func withLexRange(members []string, min string, minIncl bool, max string, maxIncl bool) []string {
if max == "-" || min == "+" {
return nil
}
if min != "-" {
if minIncl {
for i, m := range members {
if m >= min {
members = members[i:]
break
}
}
} else {
// Excluding min
for i, m := range members {
if m > min {
members = members[i:]
break
}
}
}
}
if max != "+" {
if maxIncl {
for i, m := range members {
if m > max {
members = members[:i]
break
}
}
} else {
// Excluding max
for i, m := range members {
if m >= max {
members = members[:i]
break
}
}
}
}
return members
} | [
"func",
"withLexRange",
"(",
"members",
"[",
"]",
"string",
",",
"min",
"string",
",",
"minIncl",
"bool",
",",
"max",
"string",
",",
"maxIncl",
"bool",
")",
"[",
"]",
"string",
"{",
"if",
"max",
"==",
"\"-\"",
"||",
"min",
"==",
"\"+\"",
"{",
"return... | // withLexRange limits a list of sorted set elements. | [
"withLexRange",
"limits",
"a",
"list",
"of",
"sorted",
"set",
"elements",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_sorted_set.go#L1123-L1164 | train |
alicebob/miniredis | cmd_sorted_set.go | cmdZpopmax | func (m *Miniredis) cmdZpopmax(reverse bool) server.Cmd {
return func(c *server.Peer, cmd string, args []string) {
if len(args) < 1 {
setDirty(c)
c.WriteError(errWrongNumber(cmd))
return
}
if !m.handleAuth(c) {
return
}
key := args[0]
count := 1
var err error
if len(args) > 1 {
count, err = strconv.Atoi(args[1])
if err != nil {
setDirty(c)
c.WriteError(msgInvalidInt)
return
}
}
withScores := true
if len(args) > 2 {
c.WriteError(msgSyntaxError)
return
}
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(key) {
c.WriteLen(0)
return
}
if db.t(key) != "zset" {
c.WriteError(ErrWrongType.Error())
return
}
members := db.ssetMembers(key)
if reverse {
reverseSlice(members)
}
rs, re := redisRange(len(members), 0, count-1, false)
if withScores {
c.WriteLen((re - rs) * 2)
} else {
c.WriteLen(re - rs)
}
for _, el := range members[rs:re] {
c.WriteBulk(el)
if withScores {
c.WriteBulk(formatFloat(db.ssetScore(key, el)))
}
db.ssetRem(key, el)
}
})
}
} | go | func (m *Miniredis) cmdZpopmax(reverse bool) server.Cmd {
return func(c *server.Peer, cmd string, args []string) {
if len(args) < 1 {
setDirty(c)
c.WriteError(errWrongNumber(cmd))
return
}
if !m.handleAuth(c) {
return
}
key := args[0]
count := 1
var err error
if len(args) > 1 {
count, err = strconv.Atoi(args[1])
if err != nil {
setDirty(c)
c.WriteError(msgInvalidInt)
return
}
}
withScores := true
if len(args) > 2 {
c.WriteError(msgSyntaxError)
return
}
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(key) {
c.WriteLen(0)
return
}
if db.t(key) != "zset" {
c.WriteError(ErrWrongType.Error())
return
}
members := db.ssetMembers(key)
if reverse {
reverseSlice(members)
}
rs, re := redisRange(len(members), 0, count-1, false)
if withScores {
c.WriteLen((re - rs) * 2)
} else {
c.WriteLen(re - rs)
}
for _, el := range members[rs:re] {
c.WriteBulk(el)
if withScores {
c.WriteBulk(formatFloat(db.ssetScore(key, el)))
}
db.ssetRem(key, el)
}
})
}
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"cmdZpopmax",
"(",
"reverse",
"bool",
")",
"server",
".",
"Cmd",
"{",
"return",
"func",
"(",
"c",
"*",
"server",
".",
"Peer",
",",
"cmd",
"string",
",",
"args",
"[",
"]",
"string",
")",
"{",
"if",
"len",
"... | // ZPOPMAX and ZPOPMIN | [
"ZPOPMAX",
"and",
"ZPOPMIN"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_sorted_set.go#L1388-L1450 | train |
alicebob/miniredis | cmd_transactions.go | commandsTransaction | func commandsTransaction(m *Miniredis) {
m.srv.Register("DISCARD", m.cmdDiscard)
m.srv.Register("EXEC", m.cmdExec)
m.srv.Register("MULTI", m.cmdMulti)
m.srv.Register("UNWATCH", m.cmdUnwatch)
m.srv.Register("WATCH", m.cmdWatch)
} | go | func commandsTransaction(m *Miniredis) {
m.srv.Register("DISCARD", m.cmdDiscard)
m.srv.Register("EXEC", m.cmdExec)
m.srv.Register("MULTI", m.cmdMulti)
m.srv.Register("UNWATCH", m.cmdUnwatch)
m.srv.Register("WATCH", m.cmdWatch)
} | [
"func",
"commandsTransaction",
"(",
"m",
"*",
"Miniredis",
")",
"{",
"m",
".",
"srv",
".",
"Register",
"(",
"\"DISCARD\"",
",",
"m",
".",
"cmdDiscard",
")",
"\n",
"m",
".",
"srv",
".",
"Register",
"(",
"\"EXEC\"",
",",
"m",
".",
"cmdExec",
")",
"\n",... | // commandsTransaction handles MULTI &c. | [
"commandsTransaction",
"handles",
"MULTI",
"&c",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_transactions.go#L10-L16 | train |
alicebob/miniredis | cmd_set.go | commandsSet | func commandsSet(m *Miniredis) {
m.srv.Register("SADD", m.cmdSadd)
m.srv.Register("SCARD", m.cmdScard)
m.srv.Register("SDIFF", m.cmdSdiff)
m.srv.Register("SDIFFSTORE", m.cmdSdiffstore)
m.srv.Register("SINTER", m.cmdSinter)
m.srv.Register("SINTERSTORE", m.cmdSinterstore)
m.srv.Register("SISMEMBER", m.cmdSismember)
m.srv.Register("SMEMBERS", m.cmdSmembers)
m.srv.Register("SMOVE", m.cmdSmove)
m.srv.Register("SPOP", m.cmdSpop)
m.srv.Register("SRANDMEMBER", m.cmdSrandmember)
m.srv.Register("SREM", m.cmdSrem)
m.srv.Register("SUNION", m.cmdSunion)
m.srv.Register("SUNIONSTORE", m.cmdSunionstore)
m.srv.Register("SSCAN", m.cmdSscan)
} | go | func commandsSet(m *Miniredis) {
m.srv.Register("SADD", m.cmdSadd)
m.srv.Register("SCARD", m.cmdScard)
m.srv.Register("SDIFF", m.cmdSdiff)
m.srv.Register("SDIFFSTORE", m.cmdSdiffstore)
m.srv.Register("SINTER", m.cmdSinter)
m.srv.Register("SINTERSTORE", m.cmdSinterstore)
m.srv.Register("SISMEMBER", m.cmdSismember)
m.srv.Register("SMEMBERS", m.cmdSmembers)
m.srv.Register("SMOVE", m.cmdSmove)
m.srv.Register("SPOP", m.cmdSpop)
m.srv.Register("SRANDMEMBER", m.cmdSrandmember)
m.srv.Register("SREM", m.cmdSrem)
m.srv.Register("SUNION", m.cmdSunion)
m.srv.Register("SUNIONSTORE", m.cmdSunionstore)
m.srv.Register("SSCAN", m.cmdSscan)
} | [
"func",
"commandsSet",
"(",
"m",
"*",
"Miniredis",
")",
"{",
"m",
".",
"srv",
".",
"Register",
"(",
"\"SADD\"",
",",
"m",
".",
"cmdSadd",
")",
"\n",
"m",
".",
"srv",
".",
"Register",
"(",
"\"SCARD\"",
",",
"m",
".",
"cmdScard",
")",
"\n",
"m",
".... | // commandsSet handles all set value operations. | [
"commandsSet",
"handles",
"all",
"set",
"value",
"operations",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_set.go#L14-L30 | train |
alicebob/miniredis | cmd_set.go | shuffle | func shuffle(m []string) {
for _ = range m {
i := rand.Intn(len(m))
j := rand.Intn(len(m))
m[i], m[j] = m[j], m[i]
}
} | go | func shuffle(m []string) {
for _ = range m {
i := rand.Intn(len(m))
j := rand.Intn(len(m))
m[i], m[j] = m[j], m[i]
}
} | [
"func",
"shuffle",
"(",
"m",
"[",
"]",
"string",
")",
"{",
"for",
"_",
"=",
"range",
"m",
"{",
"i",
":=",
"rand",
".",
"Intn",
"(",
"len",
"(",
"m",
")",
")",
"\n",
"j",
":=",
"rand",
".",
"Intn",
"(",
"len",
"(",
"m",
")",
")",
"\n",
"m"... | // shuffle shuffles a string. Kinda. | [
"shuffle",
"shuffles",
"a",
"string",
".",
"Kinda",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_set.go#L678-L684 | train |
minio/mc | pkg/ioutils/filepath.go | IsDirEmpty | func IsDirEmpty(dirname string) (status bool, err error) {
f, err := os.Open(dirname)
if err == nil {
defer f.Close()
if _, err = f.Readdirnames(1); err == io.EOF {
status = true
err = nil
}
}
return
} | go | func IsDirEmpty(dirname string) (status bool, err error) {
f, err := os.Open(dirname)
if err == nil {
defer f.Close()
if _, err = f.Readdirnames(1); err == io.EOF {
status = true
err = nil
}
}
return
} | [
"func",
"IsDirEmpty",
"(",
"dirname",
"string",
")",
"(",
"status",
"bool",
",",
"err",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"dirname",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"defer",
"f",
".",
"Close",
"(",
")",
... | // IsDirEmpty Check if a directory is empty | [
"IsDirEmpty",
"Check",
"if",
"a",
"directory",
"is",
"empty"
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/pkg/ioutils/filepath.go#L28-L39 | train |
minio/mc | pkg/ioutils/filepath.go | FTW | func FTW(root string, walkFn FTWFunc) error {
info, err := os.Lstat(root)
if err != nil {
return walkFn(root, nil, err)
}
return walk(root, info, walkFn)
} | go | func FTW(root string, walkFn FTWFunc) error {
info, err := os.Lstat(root)
if err != nil {
return walkFn(root, nil, err)
}
return walk(root, info, walkFn)
} | [
"func",
"FTW",
"(",
"root",
"string",
",",
"walkFn",
"FTWFunc",
")",
"error",
"{",
"info",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"root",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"walkFn",
"(",
"root",
",",
"nil",
",",
"err",
")",
... | // FTW walks the file tree rooted at root, calling walkFn for each file or
// directory in the tree, including root. | [
"FTW",
"walks",
"the",
"file",
"tree",
"rooted",
"at",
"root",
"calling",
"walkFn",
"for",
"each",
"file",
"or",
"directory",
"in",
"the",
"tree",
"including",
"root",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/pkg/ioutils/filepath.go#L43-L49 | train |
minio/mc | pkg/ioutils/filepath.go | readDir | func readDir(dirname string) (fi []os.FileInfo, err error) {
f, err := os.Open(dirname)
if err == nil {
defer f.Close()
if fi, err = f.Readdir(-1); fi != nil {
sort.Sort(byName(fi))
}
}
return
} | go | func readDir(dirname string) (fi []os.FileInfo, err error) {
f, err := os.Open(dirname)
if err == nil {
defer f.Close()
if fi, err = f.Readdir(-1); fi != nil {
sort.Sort(byName(fi))
}
}
return
} | [
"func",
"readDir",
"(",
"dirname",
"string",
")",
"(",
"fi",
"[",
"]",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"dirname",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"defer",
"f",
".",
... | // readDir reads the directory named by dirname and returns
// a sorted list of directory entries. | [
"readDir",
"reads",
"the",
"directory",
"named",
"by",
"dirname",
"and",
"returns",
"a",
"sorted",
"list",
"of",
"directory",
"entries",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/pkg/ioutils/filepath.go#L72-L82 | train |
minio/mc | cmd/config-host-list.go | printHosts | func printHosts(hosts ...hostMessage) {
var maxAlias = 0
for _, host := range hosts {
if len(host.Alias) > maxAlias {
maxAlias = len(host.Alias)
}
}
for _, host := range hosts {
if !globalJSON {
// Format properly for alignment based on alias length only in non json mode.
host.Alias = fmt.Sprintf("%-*.*s", maxAlias, maxAlias, host.Alias)
}
if host.AccessKey == "" || host.SecretKey == "" {
host.AccessKey = ""
host.SecretKey = ""
host.API = ""
}
printMsg(host)
}
} | go | func printHosts(hosts ...hostMessage) {
var maxAlias = 0
for _, host := range hosts {
if len(host.Alias) > maxAlias {
maxAlias = len(host.Alias)
}
}
for _, host := range hosts {
if !globalJSON {
// Format properly for alignment based on alias length only in non json mode.
host.Alias = fmt.Sprintf("%-*.*s", maxAlias, maxAlias, host.Alias)
}
if host.AccessKey == "" || host.SecretKey == "" {
host.AccessKey = ""
host.SecretKey = ""
host.API = ""
}
printMsg(host)
}
} | [
"func",
"printHosts",
"(",
"hosts",
"...",
"hostMessage",
")",
"{",
"var",
"maxAlias",
"=",
"0",
"\n",
"for",
"_",
",",
"host",
":=",
"range",
"hosts",
"{",
"if",
"len",
"(",
"host",
".",
"Alias",
")",
">",
"maxAlias",
"{",
"maxAlias",
"=",
"len",
... | // Prints all the hosts. | [
"Prints",
"all",
"the",
"hosts",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/config-host-list.go#L88-L107 | train |
minio/mc | cmd/config-host-list.go | listHosts | func listHosts(alias string) {
conf, err := loadMcConfig()
fatalIf(err.Trace(globalMCConfigVersion), "Unable to load config version `"+globalMCConfigVersion+"`.")
// If specific alias is requested, look for it and print.
if alias != "" {
if v, ok := conf.Hosts[alias]; ok {
printHosts(hostMessage{
op: "list",
prettyPrint: false,
Alias: alias,
URL: v.URL,
AccessKey: v.AccessKey,
SecretKey: v.SecretKey,
API: v.API,
Lookup: v.Lookup,
})
return
}
fatalIf(errInvalidAliasedURL(alias), "No such alias `"+alias+"` found.")
}
var hosts []hostMessage
for k, v := range conf.Hosts {
hosts = append(hosts, hostMessage{
op: "list",
prettyPrint: true,
Alias: k,
URL: v.URL,
AccessKey: v.AccessKey,
SecretKey: v.SecretKey,
API: v.API,
Lookup: v.Lookup,
})
}
// Sort hosts by alias names lexically.
sort.Sort(byAlias(hosts))
// Display all the hosts.
printHosts(hosts...)
} | go | func listHosts(alias string) {
conf, err := loadMcConfig()
fatalIf(err.Trace(globalMCConfigVersion), "Unable to load config version `"+globalMCConfigVersion+"`.")
// If specific alias is requested, look for it and print.
if alias != "" {
if v, ok := conf.Hosts[alias]; ok {
printHosts(hostMessage{
op: "list",
prettyPrint: false,
Alias: alias,
URL: v.URL,
AccessKey: v.AccessKey,
SecretKey: v.SecretKey,
API: v.API,
Lookup: v.Lookup,
})
return
}
fatalIf(errInvalidAliasedURL(alias), "No such alias `"+alias+"` found.")
}
var hosts []hostMessage
for k, v := range conf.Hosts {
hosts = append(hosts, hostMessage{
op: "list",
prettyPrint: true,
Alias: k,
URL: v.URL,
AccessKey: v.AccessKey,
SecretKey: v.SecretKey,
API: v.API,
Lookup: v.Lookup,
})
}
// Sort hosts by alias names lexically.
sort.Sort(byAlias(hosts))
// Display all the hosts.
printHosts(hosts...)
} | [
"func",
"listHosts",
"(",
"alias",
"string",
")",
"{",
"conf",
",",
"err",
":=",
"loadMcConfig",
"(",
")",
"\n",
"fatalIf",
"(",
"err",
".",
"Trace",
"(",
"globalMCConfigVersion",
")",
",",
"\"Unable to load config version `\"",
"+",
"globalMCConfigVersion",
"+"... | // listHosts - list all host URLs or a requested host. | [
"listHosts",
"-",
"list",
"all",
"host",
"URLs",
"or",
"a",
"requested",
"host",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/config-host-list.go#L117-L158 | train |
minio/mc | cmd/session-resume.go | sessionExecute | func sessionExecute(s *sessionV8) {
switch s.Header.CommandType {
case "cp":
sseKeys := s.Header.CommandStringFlags["encrypt-key"]
sseServer := s.Header.CommandStringFlags["encrypt"]
encKeyDB, _ := parseAndValidateEncryptionKeys(sseKeys, sseServer)
doCopySession(s, encKeyDB)
}
} | go | func sessionExecute(s *sessionV8) {
switch s.Header.CommandType {
case "cp":
sseKeys := s.Header.CommandStringFlags["encrypt-key"]
sseServer := s.Header.CommandStringFlags["encrypt"]
encKeyDB, _ := parseAndValidateEncryptionKeys(sseKeys, sseServer)
doCopySession(s, encKeyDB)
}
} | [
"func",
"sessionExecute",
"(",
"s",
"*",
"sessionV8",
")",
"{",
"switch",
"s",
".",
"Header",
".",
"CommandType",
"{",
"case",
"\"cp\"",
":",
"sseKeys",
":=",
"s",
".",
"Header",
".",
"CommandStringFlags",
"[",
"\"encrypt-key\"",
"]",
"\n",
"sseServer",
":... | // sessionExecute - run a given session. | [
"sessionExecute",
"-",
"run",
"a",
"given",
"session",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/session-resume.go#L63-L71 | train |
minio/mc | cmd/session-resume.go | findClosestSessions | func findClosestSessions(session string) []string {
sessionsTree := trie.NewTrie() // Allocate a new trie for sessions strings.
for _, sid := range getSessionIDs() {
sessionsTree.Insert(sid)
}
var closestSessions []string
for _, value := range sessionsTree.PrefixMatch(session) {
closestSessions = append(closestSessions, value.(string))
}
sort.Strings(closestSessions)
return closestSessions
} | go | func findClosestSessions(session string) []string {
sessionsTree := trie.NewTrie() // Allocate a new trie for sessions strings.
for _, sid := range getSessionIDs() {
sessionsTree.Insert(sid)
}
var closestSessions []string
for _, value := range sessionsTree.PrefixMatch(session) {
closestSessions = append(closestSessions, value.(string))
}
sort.Strings(closestSessions)
return closestSessions
} | [
"func",
"findClosestSessions",
"(",
"session",
"string",
")",
"[",
"]",
"string",
"{",
"sessionsTree",
":=",
"trie",
".",
"NewTrie",
"(",
")",
"\n",
"for",
"_",
",",
"sid",
":=",
"range",
"getSessionIDs",
"(",
")",
"{",
"sessionsTree",
".",
"Insert",
"("... | // findClosestSessions to match a given string with sessions trie tree. | [
"findClosestSessions",
"to",
"match",
"a",
"given",
"string",
"with",
"sessions",
"trie",
"tree",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/session-resume.go#L74-L85 | train |
minio/mc | cmd/session-resume.go | checkSessionResumeSyntax | func checkSessionResumeSyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
cli.ShowCommandHelpAndExit(ctx, "resume", 1) // last argument is exit code
}
} | go | func checkSessionResumeSyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
cli.ShowCommandHelpAndExit(ctx, "resume", 1) // last argument is exit code
}
} | [
"func",
"checkSessionResumeSyntax",
"(",
"ctx",
"*",
"cli",
".",
"Context",
")",
"{",
"if",
"len",
"(",
"ctx",
".",
"Args",
"(",
")",
")",
"==",
"0",
"||",
"len",
"(",
"ctx",
".",
"Args",
"(",
")",
")",
">",
"2",
"{",
"cli",
".",
"ShowCommandHelp... | // checkSessionResumeSyntax - Validate session resume command. | [
"checkSessionResumeSyntax",
"-",
"Validate",
"session",
"resume",
"command",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/session-resume.go#L88-L92 | train |
minio/mc | cmd/session-resume.go | mainSessionResume | func mainSessionResume(ctx *cli.Context) error {
// Validate session resume syntax.
checkSessionResumeSyntax(ctx)
// Additional command specific theme customization.
console.SetColor("Command", color.New(color.FgWhite, color.Bold))
console.SetColor("SessionID", color.New(color.FgYellow, color.Bold))
console.SetColor("SessionTime", color.New(color.FgGreen))
if !isSessionDirExists() {
fatalIf(createSessionDir().Trace(), "Unable to create session folder.")
}
sessionID := ctx.Args().Get(0)
if !isSessionExists(sessionID) {
closestSessions := findClosestSessions(sessionID)
errorMsg := "Session `" + sessionID + "` not found."
if len(closestSessions) > 0 {
errorMsg += fmt.Sprintf("\n\nDid you mean?\n")
for _, session := range closestSessions {
errorMsg += fmt.Sprintf(" `mc resume session %s`", session)
// break on the first one, it is good enough.
break
}
}
fatalIf(errDummy().Trace(sessionID), errorMsg)
}
resumeSession(sessionID)
return nil
} | go | func mainSessionResume(ctx *cli.Context) error {
// Validate session resume syntax.
checkSessionResumeSyntax(ctx)
// Additional command specific theme customization.
console.SetColor("Command", color.New(color.FgWhite, color.Bold))
console.SetColor("SessionID", color.New(color.FgYellow, color.Bold))
console.SetColor("SessionTime", color.New(color.FgGreen))
if !isSessionDirExists() {
fatalIf(createSessionDir().Trace(), "Unable to create session folder.")
}
sessionID := ctx.Args().Get(0)
if !isSessionExists(sessionID) {
closestSessions := findClosestSessions(sessionID)
errorMsg := "Session `" + sessionID + "` not found."
if len(closestSessions) > 0 {
errorMsg += fmt.Sprintf("\n\nDid you mean?\n")
for _, session := range closestSessions {
errorMsg += fmt.Sprintf(" `mc resume session %s`", session)
// break on the first one, it is good enough.
break
}
}
fatalIf(errDummy().Trace(sessionID), errorMsg)
}
resumeSession(sessionID)
return nil
} | [
"func",
"mainSessionResume",
"(",
"ctx",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"checkSessionResumeSyntax",
"(",
"ctx",
")",
"\n",
"console",
".",
"SetColor",
"(",
"\"Command\"",
",",
"color",
".",
"New",
"(",
"color",
".",
"FgWhite",
",",
"color",... | // mainSessionResume - Main session resume function. | [
"mainSessionResume",
"-",
"Main",
"session",
"resume",
"function",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/session-resume.go#L95-L124 | train |
minio/mc | cmd/session-resume.go | resumeSession | func resumeSession(sessionID string) {
s, err := loadSessionV8(sessionID)
fatalIf(err.Trace(sessionID), "Unable to load session.")
// Restore the state of global variables from this previous session.
s.restoreGlobals()
savedCwd, e := os.Getwd()
fatalIf(probe.NewError(e), "Unable to determine current working folder.")
if s.Header.RootPath != "" {
// change folder to RootPath.
e = os.Chdir(s.Header.RootPath)
fatalIf(probe.NewError(e), "Unable to change working folder to root path while resuming session.")
}
sessionExecute(s)
err = s.Close()
fatalIf(err.Trace(), "Unable to close session file properly.")
err = s.Delete()
fatalIf(err.Trace(), "Unable to clear session files properly.")
// change folder back to saved path.
e = os.Chdir(savedCwd)
fatalIf(probe.NewError(e), "Unable to change working folder to saved path `"+savedCwd+"`.")
} | go | func resumeSession(sessionID string) {
s, err := loadSessionV8(sessionID)
fatalIf(err.Trace(sessionID), "Unable to load session.")
// Restore the state of global variables from this previous session.
s.restoreGlobals()
savedCwd, e := os.Getwd()
fatalIf(probe.NewError(e), "Unable to determine current working folder.")
if s.Header.RootPath != "" {
// change folder to RootPath.
e = os.Chdir(s.Header.RootPath)
fatalIf(probe.NewError(e), "Unable to change working folder to root path while resuming session.")
}
sessionExecute(s)
err = s.Close()
fatalIf(err.Trace(), "Unable to close session file properly.")
err = s.Delete()
fatalIf(err.Trace(), "Unable to clear session files properly.")
// change folder back to saved path.
e = os.Chdir(savedCwd)
fatalIf(probe.NewError(e), "Unable to change working folder to saved path `"+savedCwd+"`.")
} | [
"func",
"resumeSession",
"(",
"sessionID",
"string",
")",
"{",
"s",
",",
"err",
":=",
"loadSessionV8",
"(",
"sessionID",
")",
"\n",
"fatalIf",
"(",
"err",
".",
"Trace",
"(",
"sessionID",
")",
",",
"\"Unable to load session.\"",
")",
"\n",
"s",
".",
"restor... | // resumeSession - Resumes a session specified by sessionID. | [
"resumeSession",
"-",
"Resumes",
"a",
"session",
"specified",
"by",
"sessionID",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/session-resume.go#L127-L152 | train |
minio/mc | cmd/signals.go | signalTrap | func signalTrap(sig ...os.Signal) <-chan bool {
// channel to notify the caller.
trapCh := make(chan bool, 1)
go func(chan<- bool) {
// channel to receive signals.
sigCh := make(chan os.Signal, 1)
defer close(sigCh)
// `signal.Notify` registers the given channel to
// receive notifications of the specified signals.
signal.Notify(sigCh, sig...)
// Wait for the signal.
<-sigCh
// Once signal has been received stop signal Notify handler.
signal.Stop(sigCh)
// Notify the caller.
trapCh <- true
}(trapCh)
return trapCh
} | go | func signalTrap(sig ...os.Signal) <-chan bool {
// channel to notify the caller.
trapCh := make(chan bool, 1)
go func(chan<- bool) {
// channel to receive signals.
sigCh := make(chan os.Signal, 1)
defer close(sigCh)
// `signal.Notify` registers the given channel to
// receive notifications of the specified signals.
signal.Notify(sigCh, sig...)
// Wait for the signal.
<-sigCh
// Once signal has been received stop signal Notify handler.
signal.Stop(sigCh)
// Notify the caller.
trapCh <- true
}(trapCh)
return trapCh
} | [
"func",
"signalTrap",
"(",
"sig",
"...",
"os",
".",
"Signal",
")",
"<-",
"chan",
"bool",
"{",
"trapCh",
":=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n",
"go",
"func",
"(",
"chan",
"<-",
"bool",
")",
"{",
"sigCh",
":=",
"make",
"(",
"chan",... | // signalTrap traps the registered signals and notifies the caller. | [
"signalTrap",
"traps",
"the",
"registered",
"signals",
"and",
"notifies",
"the",
"caller",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/signals.go#L25-L49 | train |
minio/mc | cmd/session-old.go | loadSessionV7 | func loadSessionV7(sid string) (*sessionV7, *probe.Error) {
if !isSessionDirExists() {
return nil, errInvalidArgument().Trace()
}
sessionFile, err := getSessionFile(sid)
if err != nil {
return nil, err.Trace(sid)
}
if _, e := os.Stat(sessionFile); e != nil {
return nil, probe.NewError(e)
}
s := &sessionV7{}
s.Header = &sessionV7Header{}
s.SessionID = sid
s.Header.Version = "7"
qs, e := quick.NewConfig(s.Header, nil)
if e != nil {
return nil, probe.NewError(e).Trace(sid, s.Header.Version)
}
e = qs.Load(sessionFile)
if e != nil {
return nil, probe.NewError(e).Trace(sid, s.Header.Version)
}
s.mutex = new(sync.Mutex)
s.Header = qs.Data().(*sessionV7Header)
sessionDataFile, err := getSessionDataFile(s.SessionID)
if err != nil {
return nil, err.Trace(sid, s.Header.Version)
}
dataFile, e := os.Open(sessionDataFile)
if e != nil {
return nil, probe.NewError(e)
}
s.DataFP = &sessionDataFP{false, dataFile}
return s, nil
} | go | func loadSessionV7(sid string) (*sessionV7, *probe.Error) {
if !isSessionDirExists() {
return nil, errInvalidArgument().Trace()
}
sessionFile, err := getSessionFile(sid)
if err != nil {
return nil, err.Trace(sid)
}
if _, e := os.Stat(sessionFile); e != nil {
return nil, probe.NewError(e)
}
s := &sessionV7{}
s.Header = &sessionV7Header{}
s.SessionID = sid
s.Header.Version = "7"
qs, e := quick.NewConfig(s.Header, nil)
if e != nil {
return nil, probe.NewError(e).Trace(sid, s.Header.Version)
}
e = qs.Load(sessionFile)
if e != nil {
return nil, probe.NewError(e).Trace(sid, s.Header.Version)
}
s.mutex = new(sync.Mutex)
s.Header = qs.Data().(*sessionV7Header)
sessionDataFile, err := getSessionDataFile(s.SessionID)
if err != nil {
return nil, err.Trace(sid, s.Header.Version)
}
dataFile, e := os.Open(sessionDataFile)
if e != nil {
return nil, probe.NewError(e)
}
s.DataFP = &sessionDataFP{false, dataFile}
return s, nil
} | [
"func",
"loadSessionV7",
"(",
"sid",
"string",
")",
"(",
"*",
"sessionV7",
",",
"*",
"probe",
".",
"Error",
")",
"{",
"if",
"!",
"isSessionDirExists",
"(",
")",
"{",
"return",
"nil",
",",
"errInvalidArgument",
"(",
")",
".",
"Trace",
"(",
")",
"\n",
... | // loadSessionV7 - reads session file if exists and re-initiates internal variables | [
"loadSessionV7",
"-",
"reads",
"session",
"file",
"if",
"exists",
"and",
"re",
"-",
"initiates",
"internal",
"variables"
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/session-old.go#L108-L149 | train |
minio/mc | cmd/client-fs_linux.go | IsGetEvent | func IsGetEvent(event notify.Event) bool {
for _, ev := range EventTypeGet {
if event&ev != 0 {
return true
}
}
return false
} | go | func IsGetEvent(event notify.Event) bool {
for _, ev := range EventTypeGet {
if event&ev != 0 {
return true
}
}
return false
} | [
"func",
"IsGetEvent",
"(",
"event",
"notify",
".",
"Event",
")",
"bool",
"{",
"for",
"_",
",",
"ev",
":=",
"range",
"EventTypeGet",
"{",
"if",
"event",
"&",
"ev",
"!=",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n"... | // IsGetEvent checks if the event return is a get event. | [
"IsGetEvent",
"checks",
"if",
"the",
"event",
"return",
"is",
"a",
"get",
"event",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/client-fs_linux.go#L41-L48 | train |
minio/mc | cmd/client-fs_linux.go | IsPutEvent | func IsPutEvent(event notify.Event) bool {
for _, ev := range EventTypePut {
if event&ev != 0 {
return true
}
}
return false
} | go | func IsPutEvent(event notify.Event) bool {
for _, ev := range EventTypePut {
if event&ev != 0 {
return true
}
}
return false
} | [
"func",
"IsPutEvent",
"(",
"event",
"notify",
".",
"Event",
")",
"bool",
"{",
"for",
"_",
",",
"ev",
":=",
"range",
"EventTypePut",
"{",
"if",
"event",
"&",
"ev",
"!=",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n"... | // IsPutEvent checks if the event returned is a put event | [
"IsPutEvent",
"checks",
"if",
"the",
"event",
"returned",
"is",
"a",
"put",
"event"
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/client-fs_linux.go#L51-L58 | train |
minio/mc | cmd/client-fs_linux.go | IsDeleteEvent | func IsDeleteEvent(event notify.Event) bool {
for _, ev := range EventTypeDelete {
if event&ev != 0 {
return true
}
}
return false
} | go | func IsDeleteEvent(event notify.Event) bool {
for _, ev := range EventTypeDelete {
if event&ev != 0 {
return true
}
}
return false
} | [
"func",
"IsDeleteEvent",
"(",
"event",
"notify",
".",
"Event",
")",
"bool",
"{",
"for",
"_",
",",
"ev",
":=",
"range",
"EventTypeDelete",
"{",
"if",
"event",
"&",
"ev",
"!=",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
... | // IsDeleteEvent checks if the event returned is a delete event | [
"IsDeleteEvent",
"checks",
"if",
"the",
"event",
"returned",
"is",
"a",
"delete",
"event"
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/client-fs_linux.go#L61-L68 | train |
minio/mc | cmd/client-fs_linux.go | getAllXattrs | func getAllXattrs(path string) (map[string]string, error) {
xMetadata := make(map[string]string)
list, e := xattr.List(path)
if e != nil {
if isNotSupported(e) {
return nil, nil
}
return nil, e
}
for _, key := range list {
// filter out system specific xattr
if strings.HasPrefix(key, "system.") {
continue
}
xMetadata[key], e = getXAttr(path, key)
if e != nil {
if isNotSupported(e) {
return nil, nil
}
return nil, e
}
}
return xMetadata, nil
} | go | func getAllXattrs(path string) (map[string]string, error) {
xMetadata := make(map[string]string)
list, e := xattr.List(path)
if e != nil {
if isNotSupported(e) {
return nil, nil
}
return nil, e
}
for _, key := range list {
// filter out system specific xattr
if strings.HasPrefix(key, "system.") {
continue
}
xMetadata[key], e = getXAttr(path, key)
if e != nil {
if isNotSupported(e) {
return nil, nil
}
return nil, e
}
}
return xMetadata, nil
} | [
"func",
"getAllXattrs",
"(",
"path",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"xMetadata",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"list",
",",
"e",
":=",
"xattr",
".",
"List",
"(",... | // getAllXattrs returns the extended attributes for a file if supported
// by the OS | [
"getAllXattrs",
"returns",
"the",
"extended",
"attributes",
"for",
"a",
"file",
"if",
"supported",
"by",
"the",
"OS"
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/client-fs_linux.go#L85-L108 | train |
minio/mc | cmd/cat-main.go | newPrettyStdout | func newPrettyStdout(w io.Writer) *prettyStdout {
return &prettyStdout{
writer: w,
buffer: bytes.NewBuffer([]byte{}),
}
} | go | func newPrettyStdout(w io.Writer) *prettyStdout {
return &prettyStdout{
writer: w,
buffer: bytes.NewBuffer([]byte{}),
}
} | [
"func",
"newPrettyStdout",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"prettyStdout",
"{",
"return",
"&",
"prettyStdout",
"{",
"writer",
":",
"w",
",",
"buffer",
":",
"bytes",
".",
"NewBuffer",
"(",
"[",
"]",
"byte",
"{",
"}",
")",
",",
"}",
"\n",
"}... | // newPrettyStdout returns an initialized prettyStdout struct | [
"newPrettyStdout",
"returns",
"an",
"initialized",
"prettyStdout",
"struct"
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/cat-main.go#L88-L93 | train |
minio/mc | cmd/cat-main.go | checkCatSyntax | func checkCatSyntax(ctx *cli.Context) {
args := ctx.Args()
if !args.Present() {
args = []string{"-"}
}
for _, arg := range args {
if strings.HasPrefix(arg, "-") && len(arg) > 1 {
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Unknown flag `%s` passed.", arg))
}
}
} | go | func checkCatSyntax(ctx *cli.Context) {
args := ctx.Args()
if !args.Present() {
args = []string{"-"}
}
for _, arg := range args {
if strings.HasPrefix(arg, "-") && len(arg) > 1 {
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Unknown flag `%s` passed.", arg))
}
}
} | [
"func",
"checkCatSyntax",
"(",
"ctx",
"*",
"cli",
".",
"Context",
")",
"{",
"args",
":=",
"ctx",
".",
"Args",
"(",
")",
"\n",
"if",
"!",
"args",
".",
"Present",
"(",
")",
"{",
"args",
"=",
"[",
"]",
"string",
"{",
"\"-\"",
"}",
"\n",
"}",
"\n",... | // checkCatSyntax performs command-line input validation for cat command. | [
"checkCatSyntax",
"performs",
"command",
"-",
"line",
"input",
"validation",
"for",
"cat",
"command",
"."
] | f0f156aca82e451c80b05d5be8eb01a04fee29dd | https://github.com/minio/mc/blob/f0f156aca82e451c80b05d5be8eb01a04fee29dd/cmd/cat-main.go#L127-L137 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.