cmd

package
v0.0.0-...-62d4185 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var ADDCmd = &cobra.Command{
	Use:   "ADD",
	Short: "Add a key and value",
	Long:  "Add a member to a collection for a given key.",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			log.Fatal("please supply a key and value to add")
			return
		}
		AppendMember(nil, args[0], args[1])
	},
}

ADDCmd represents the ADD command

View Source
var ALLMEMBERSCmd = &cobra.Command{
	Use:   "ALLMEMBERS",
	Short: "Get all members (keys)",
	Long:  `Get all members (keys)`,
	Run: func(cmd *cobra.Command, args []string) {
		members := GetAllMembers()
		for i := 0; i < len(members); i++ {
			fmt.Printf("%d) %s \n", i+1, members[i])
		}
	},
}

ALLMEMBERSCmd represents the ALLMEMBERS command

View Source
var CLEARCmd = &cobra.Command{
	Use:   "CLEAR",
	Short: "Removes all keys and all members",
	Long:  `Removes all keys and all members from the dictionary`,
	Run: func(cmd *cobra.Command, args []string) {
		Clear()
	},
}

CLEARCmd represents the CLEAR command

View Source
var INTERSECTCmd = &cobra.Command{
	Use:   "INTERSECT",
	Short: "INTERSECT",
	Long:  `INTERSECT`,
	Run: func(cmd *cobra.Command, args []string) {
		intersect(args[0], args[1])
	},
}

INTERSECTCmd

View Source
var ITEMSCmd = &cobra.Command{
	Use:   "ITEMS",
	Short: "Get everything",
	Long:  `Get everything including keys and members`,
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println(getItems())
	},
}

ITEMSCmd represents the ITEMS command

View Source
var KEYEXISTSCmd = &cobra.Command{
	Use:   "KEYEXISTS",
	Short: "Does key exist?",
	Long:  "Returns whether a key exists or not.",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			log.Fatal("please supply a key to search for")
			return
		}
		fmt.Println(KeyExists(nil, args[0]))
	},
}

KEYEXISTSCmd represents the KEYEXISTS command

View Source
var KEYSCmd = &cobra.Command{
	Use:   "KEYS",
	Short: "Get all keys",
	Long:  "Returns a collection of keys",
	Run: func(cmd *cobra.Command, args []string) {
		keys := GetKeys(nil)
		for index, key := range keys {
			fmt.Printf("%d) %s\n", index+1, key)
		}
	},
}

KEYSCmd represents the KEYS command

View Source
var MEMBEREXISTSCmd = &cobra.Command{
	Use:   "MEMBEREXISTS",
	Short: "Is the value here?",
	Long:  `Is the value here?`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 || len(args) == 1 {
			log.Fatal("please supply a key and value to search for")
			return
		}
		fmt.Println(MemberExists(nil, args[0], args[1]))
	},
}

MEMBEREXISTSCmd represents the MEMBEREXISTS command

View Source
var MEMBERSCmd = &cobra.Command{
	Use:   "MEMBERS",
	Short: "Get values for key",
	Long:  "Returns the collection of strings for the given key.",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			log.Fatal("please supply a key to get members for")
			return
		}
		members := GetMembers(nil, args[0])
		for i := 0; i < len(members); i++ {
			fmt.Printf("%d) %s \n", i+1, members[i])
		}
	},
}

MEMBERSCmd represents the MEMBERS command

View Source
var REMOVEALLCmd = &cobra.Command{
	Use:   "REMOVEALL",
	Short: "Removes a key and values",
	Long:  `Removes a key and values`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			log.Fatal("please supply a key to remove values for")
			return
		}
		e := RemoveAll(args[0])
		if e != nil {
			fmt.Println(e)
		}
	},
}

REMOVEALLCmd represents the REMOVE command

View Source
var REMOVECmd = &cobra.Command{
	Use:   "REMOVE",
	Short: "Remove a key and value",
	Long:  `Remove a key and value`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			log.Fatal("please supply a key and value to remove")
			return
		}
		e := RemoveMember(args[0], args[1])
		if e != nil {
			fmt.Println(e)
		}
	},
}

REMOVECmd represents the REMOVE command

Functions

func AppendMember

func AppendMember(r redis.Conn, k, v string)

Append adds a member to a collection for a given key.

func Clear

func Clear()

Clear removes all keys and all members from the dictionary.

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func GetAllMembers

func GetAllMembers() []string

GetAllMembers returns all the members in the dictionary. Returns nothing if there are none. Order is not guaranteed.

func GetCacheConn

func GetCacheConn() redis.Conn

func GetKeys

func GetKeys(r redis.Conn) []string

GetMembers returns the collection of strings for the given key.

func GetMembers

func GetMembers(r redis.Conn, key string) []string

GetMembers returns the collection of strings for the given key.

func InsertAll

func InsertAll(r redis.Conn, k string, args []string)

InsertAll inserts all given members for a key

func KeyExists

func KeyExists(r redis.Conn, k string) bool

KeyExists returns whether a key exists or not.

func MemberExists

func MemberExists(r redis.Conn, k, v string) bool

MemberExists returns whether a key exists or not.

func RemoveAll

func RemoveAll(key string) error

RemoveMember removes all members for a key and removes the key from the dictionary. Returns an error if the key does not exist.

func RemoveMember

func RemoveMember(key, val string) error

RemoveMember removes a member from a key.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL