rewledis

package module
v0.0.0-...-e6d4a3c Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: MIT Imports: 11 Imported by: 0

README

rewledis

Go Reference

rewledis provides wrappers for the redigo Redis client library and transparently rewrites Redis commands to LedisDB commands. Existing applications developed to target Redis are thus enabled to use LedisDB without changing any code.

The simplest entrypoint to this module is rewledis.NewPool(), which returns a redis.Pool to be treated (almost) like a regular pool processing Redis commands. Commands are internally rewritten to work on LedisDB.

The motivation for developing this package was that I wanted to use an established Work-Queue library which targeted Redis, but instead use LedisDB embedded in one of the application's components. Transparently rewriting commands on each client would serve as the compatibility layer between the library expecting to communicate with Redis and the LedisDB instance.

Caveats

  • LedisDB seems to be unmaintained.
  • LedisDB's memory model/transaction models differs from Redis.

This project has been discontinued. During development and testing I ran into problems related to the execution of scripts: On Redis these are executed as a single unit/transaction while LedisDB executes each command in the script individually. This made LedisDB unsuitable for the use case I had in mind. I abandoned the project in a half-ready state, so some things may work while others don't.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RedisCommandAPPEND = RedisCommand{
		Name:          "APPEND",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "APPEND key value",
	}

	RedisCommandBITCOUNT = RedisCommand{
		Name:          "BITCOUNT",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "BITCOUNT key [start end]",
	}

	// RedisCommandBITOP contains information about the BITOP Redis command.
	// BITOP writes the result of operation to destkey. However, it treats
	// unset keys as "\x00" * max(len key). I.e. the commands succeeds even if
	// some keys are not set.
	//
	// Perhaps KeyExtractor should be ArgsAtIndices(1) instead, as only
	// destkey is a string.
	// If no keys are set the result of applying the operation is a 0 length
	// string. In this case Redis sets destkey to nil (does not exist).
	//
	// TODO: Define the exact meaning of KeyType / KeyExtractor.
	RedisCommandBITOP = RedisCommand{
		Name:          "BITOP",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsFromIndex(1),
		TransformFunc: NoneTransformer(),
		Syntax:        "BITOP operation destkey key [key ...]",
	}

	RedisCommandBITPOS = RedisCommand{
		Name:          "BITPOS",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "BITPOS key bit [start] [end]",
	}

	RedisCommandDECR = RedisCommand{
		Name:          "DECR",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "DECR key",
	}

	RedisCommandDECRBY = RedisCommand{
		Name:          "DECRBY",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "DECRBY key decrement",
	}

	RedisCommandGET = RedisCommand{
		Name:          "GET",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "GET key",
	}

	RedisCommandGETBIT = RedisCommand{
		Name:          "GETBIT",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "GETBIT key offset",
	}

	RedisCommandGETRANGE = RedisCommand{
		Name:          "GETRANGE",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "GETRANGE key start end",
	}

	RedisCommandGETSET = RedisCommand{
		Name:          "GETSET",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "GETSET key value",
	}

	RedisCommandINCR = RedisCommand{
		Name:          "INCR",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "INCR key",
	}

	RedisCommandINCRBY = RedisCommand{
		Name:          "INCRBY",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "INCRBY key increment",
	}

	RedisCommandMGET = RedisCommand{
		Name:          "MGET",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsFromIndex(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "MGET key [key ...]",
	}

	RedisCommandMSET = RedisCommand{
		Name:          "MSET",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsFromIndex(0, 1),
		TransformFunc: NoneTransformer(),
		Syntax:        "MSET key value [key value ...]",
	}

	RedisCommandSET = RedisCommand{
		Name:          "SET",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: SetCommandTransformer,
		Syntax:        "SET key value [expiration EX seconds|PX milliseconds] [NX|XX]",
	}

	RedisCommandSETBIT = RedisCommand{
		Name:          "SETBIT",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SETBIT key offset value",
	}

	RedisCommandSETEX = RedisCommand{
		Name:          "SETEX",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SETEX key seconds value",
	}

	RedisCommandSETNX = RedisCommand{
		Name:          "SETNX",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SETNX key value",
	}

	RedisCommandSETRANGE = RedisCommand{
		Name:          "SETRANGE",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SETRANGE key offset value",
	}

	RedisCommandSTRLEN = RedisCommand{
		Name:          "STRLEN",
		KeyType:       RedisTypeString,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "STRLEN key",
	}
)

RedisCommand variables describing the Redis commands operating on strings (RedisTypeString).

https://redis.io/commands#string
View Source
var (
	RedisCommandHDEL = RedisCommand{
		Name:          "HDEL",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HDEL key field [field ...]",
	}

	RedisCommandHEXISTS = RedisCommand{
		Name:          "HEXISTS",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HEXISTS key field",
	}

	RedisCommandHGET = RedisCommand{
		Name:          "HGET",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HGET key field",
	}

	RedisCommandHGETALL = RedisCommand{
		Name:          "HGETALL",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HGETALL key",
	}

	RedisCommandHINCRBY = RedisCommand{
		Name:          "HINCRBY",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HINCRBY key field increment",
	}

	RedisCommandHKEYS = RedisCommand{
		Name:          "HKEYS",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HKEYS key",
	}

	RedisCommandHLEN = RedisCommand{
		Name:          "HLEN",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HLEN key",
	}

	RedisCommandHMGET = RedisCommand{
		Name:          "HMGET",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HMGET key field [field ...]",
	}

	RedisCommandHMSET = RedisCommand{
		Name:          "HMSET",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HMSET key field value [field value ...]",
	}

	RedisCommandHSET = RedisCommand{
		Name:          "HSET",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HSET key field value",
	}

	RedisCommandHVALS = RedisCommand{
		Name:          "HVALS",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HVALS key",
	}

	RedisCommandHSCAN = RedisCommand{
		Name:          "HSCAN",
		KeyType:       RedisTypeHash,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "HSCAN key cursor [MATCH pattern] [COUNT count]",
	}
)

RedisCommand variables describing the Redis commands operating on hashes (RedisTypeHash).

https://redis.io/commands#hash
View Source
var (
	RedisCommandBLPOP = RedisCommand{
		Name:          "BLPOP",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsFromUntilIndex(0, -1),
		TransformFunc: NoneTransformer(),
		Syntax:        "BLPOP key [key ...] timeout",
	}

	RedisCommandBRPOP = RedisCommand{
		Name:          "BRPOP",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsFromUntilIndex(0, -1),
		TransformFunc: NoneTransformer(),
		Syntax:        "BRPOP key [key ...] timeout",
	}

	RedisCommandBRPOPLPUSH = RedisCommand{
		Name:          "BRPOPLPUSH",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0, 1),
		TransformFunc: NoneTransformer(),
		Syntax:        "BRPOPLPUSH source destination timeout",
	}

	RedisCommandLINDEX = RedisCommand{
		Name:          "LINDEX",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "LINDEX key index",
	}

	RedisCommandLLEN = RedisCommand{
		Name:          "LLEN",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "LLEN key index",
	}

	RedisCommandLPOP = RedisCommand{
		Name:          "LPOP",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "LPOP key",
	}

	RedisCommandLPUSH = RedisCommand{
		Name:          "LPUSH",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "LPUSH key value [value ...]",
	}

	RedisCommandLRANGE = RedisCommand{
		Name:          "LRANGE",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "LRANGE key start stop",
	}

	RedisCommandLREM = RedisCommand{
		Name:          "LREM",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: LremCommandTransformer,
		Syntax:        "LREM key count value",
	}

	RedisCommandLTRIM = RedisCommand{
		Name:          "LTRIM",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "LTRIM key start stop",
	}

	RedisCommandRPOP = RedisCommand{
		Name:          "RPOP",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "RPOP key",
	}

	RedisCommandRPOPLPUSH = RedisCommand{
		Name:          "RPOPLPUSH",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0, 1),
		TransformFunc: NoneTransformer(),
		Syntax:        "RPOPLPUSH source destination",
	}

	RedisCommandRPUSH = RedisCommand{
		Name:          "RPUSH",
		KeyType:       RedisTypeList,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "RPUSH key value [value ...]",
	}
)

RedisCommand variables describing the Redis commands operating on lists (RedisTypeList).

https://redis.io/commands#list
View Source
var (
	RedisCommandSADD = RedisCommand{
		Name:          "SADD",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SADD key member [member ...]",
	}

	RedisCommandSCARD = RedisCommand{
		Name:          "SCARD",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SCARD key",
	}

	RedisCommandSDIFF = RedisCommand{
		Name:          "SDIFF",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsFromIndex(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SDIFF key [key ...]",
	}

	RedisCommandSDIFFSTORE = RedisCommand{
		Name:          "SDIFFSTORE",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsFromIndex(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SDIFFSTORE destination key [key ...]",
	}

	RedisCommandSINTER = RedisCommand{
		Name:          "SINTER",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsFromIndex(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SINTER key [key ...]",
	}

	RedisCommandSINTERSTORE = RedisCommand{
		Name:          "SINTERSTORE",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsFromIndex(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SINTERSTORE destination key [key ...]",
	}

	RedisCommandSISMEMBER = RedisCommand{
		Name:          "SISMEMBER",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SISMEMBER key member",
	}

	RedisCommandSMEMBERS = RedisCommand{
		Name:          "SMEMBERS",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SMEMBERS key",
	}

	RedisCommandSREM = RedisCommand{
		Name:          "SREM",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SREM key member [member ...]",
	}

	RedisCommandSSCAN = RedisCommand{
		Name:          "SSCAN",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SSCAN key cursor [MATCH pattern] [COUNT count]",
	}

	RedisCommandSUNION = RedisCommand{
		Name:          "SUNION",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsFromIndex(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SUNION key [key ...]",
	}

	RedisCommandSUNIONSTORE = RedisCommand{
		Name:          "SUNIONSTORE",
		KeyType:       RedisTypeSet,
		KeyExtractor:  ArgsFromIndex(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "SUNIONSTORE destination key [key ...]",
	}
)

RedisCommand variables describing the Redis commands operating on sets (RedisTypeSet).

https://redis.io/commands#set
View Source
var (
	RedisCommandZADD = RedisCommand{
		Name:          "ZADD",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: ZaddCommandTransformer,
		Syntax:        "ZADD key [NX|XX] [CH] [INCR] score member [score member ...]",
	}

	RedisCommandZCARD = RedisCommand{
		Name:          "ZCARD",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZCARD key",
	}

	RedisCommandZCOUNT = RedisCommand{
		Name:          "ZCOUNT",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZCOUNT key min max",
	}

	RedisCommandZINCRBY = RedisCommand{
		Name:          "ZINCRBY",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZINCRBY key increment member",
	}

	// RedisCommandZINTERSTORE contains information about the ZINTERSTORE Redis
	// command.
	//
	// The KeyExtractor only extracts the destination key. Further keys could
	// be extracted by introducing a new KeyExtractor implementation.
	// However, Redis interprets non-existing key as empty keys.
	RedisCommandZINTERSTORE = RedisCommand{
		Name:          "ZINTERSTORE",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]",
	}

	RedisCommandZLEXCOUNT = RedisCommand{
		Name:          "ZLEXCOUNT",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZLEXCOUNT key min max",
	}

	RedisCommandZRANGE = RedisCommand{
		Name:          "ZRANGE",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZRANGE key start stop [WITHSCORES]",
	}

	RedisCommandZRANGEBYLEX = RedisCommand{
		Name:          "ZRANGEBYLEX",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZRANGEBYLEX key min max [LIMIT offset count]",
	}

	RedisCommandZRANGEBYSCORE = RedisCommand{
		Name:          "ZRANGEBYSCORE",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]",
	}

	RedisCommandZRANK = RedisCommand{
		Name:          "ZRANK",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZRANK key member",
	}

	RedisCommandZREM = RedisCommand{
		Name:          "ZREM",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZREM key member [member ...]",
	}

	RedisCommandZREMRANGEBYLEX = RedisCommand{
		Name:          "ZREMRANGEBYLEX",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZREMRANGEBYLEX key min max",
	}

	RedisCommandZREMRANGEBYRANK = RedisCommand{
		Name:          "ZREMRANGEBYRANK",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZREMRANGEBYRANK key start stop",
	}

	RedisCommandZREMRANGEBYSCORE = RedisCommand{
		Name:          "ZREMRANGEBYSCORE",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZREMRANGEBYSCORE key min max",
	}

	RedisCommandZREVRANGE = RedisCommand{
		Name:          "ZREVRANGE",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZREVRANGE key start stop [WITHSCORES]",
	}

	RedisCommandZREVRANGEBYSCORE = RedisCommand{
		Name:          "ZREVRANGEBYSCORE",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]",
	}

	RedisCommandZREVRANK = RedisCommand{
		Name:          "ZREVRANK",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZREVRANK key member",
	}

	RedisCommandZSCAN = RedisCommand{
		Name:          "ZSCAN",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZSCAN key cursor [MATCH pattern] [COUNT count]",
	}

	RedisCommandZSCORE = RedisCommand{
		Name:          "ZSCORE",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZSCORE key member",
	}

	// RedisCommandZUNIONSTORE contains information about the ZUNIONSTORE Redis
	// command.
	//
	// The KeyExtractor only extracts the destination key. Further keys could
	// be extracted by introducing a new KeyExtractor implementation.
	// However, Redis interprets non-existing key as empty keys.
	RedisCommandZUNIONSTORE = RedisCommand{
		Name:          "ZUNIONSTORE",
		KeyType:       RedisTypeZSet,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: NoneTransformer(),
		Syntax:        "ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]",
	}
)

RedisCommand variables describing the Redis commands operating on sorted sets (RedisTypeZSet).

https://redis.io/commands#sorted_set
View Source
var (
	RedisCommandDEL = RedisCommand{
		Name:         "DEL",
		KeyType:      RedisTypeGeneric,
		KeyExtractor: ArgsFromIndex(0),
		TransformFunc: TypeSpecificBulkTransformer(&TypeSpecificBulkTransformerConfig{
			Commands: TypeSpecificCommands{
				KV:   "DEL",
				List: "LMCLEAR",
				Hash: "HMCLEAR",
				Set:  "SMCLEAR",
				ZSet: "ZMCLEAR",
			},
			Aggregation: AggregationSum,
		}),
		Syntax: "DEL key [key ...]",
	}

	RedisCommandDUMP = RedisCommand{
		Name:         "DUMP",
		KeyType:      RedisTypeGeneric,
		KeyExtractor: ArgsAtIndices(0),
		TransformFunc: TypeSpecificBulkTransformer(&TypeSpecificBulkTransformerConfig{
			Commands: TypeSpecificCommands{
				KV:   "DUMP",
				List: "LDUMP",
				Hash: "HDUMP",
				Set:  "SDUMP",
				ZSet: "ZDUMP",
			},
			Aggregation: AggregationFirst,
		}),
		Syntax: "DUMP key",
	}

	RedisCommandEXISTS = RedisCommand{
		Name:         "EXISTS",
		KeyType:      RedisTypeGeneric,
		KeyExtractor: ArgsAtIndices(0),
		TransformFunc: TypeSpecificBulkTransformer(&TypeSpecificBulkTransformerConfig{
			Commands: TypeSpecificCommands{
				KV:   "EXISTS",
				List: "LKEYEXISTS",
				Hash: "HKEYEXISTS",
				Set:  "SKEYEXISTS",
				ZSet: "ZKEYEXISTS",
			},
			Debulk:      true,
			Aggregation: AggregationSum,
		}),
		Syntax: "EXISTS key [key ...]",
	}

	RedisCommandEXPIRE = RedisCommand{
		Name:         "EXPIRE",
		KeyType:      RedisTypeGeneric,
		KeyExtractor: ArgsAtIndices(0),
		TransformFunc: TypeSpecificBulkTransformer(&TypeSpecificBulkTransformerConfig{
			Commands: TypeSpecificCommands{
				KV:   "EXPIRE",
				List: "LEXPIRE",
				Hash: "HEXPIRE",
				Set:  "SEXPIRE",
				ZSet: "ZEXPIRE",
			},
			Aggregation:         AggregationSum,
			AppendArgsExtractor: ArgsAtIndices(1),
		}),
		Syntax: "EXPIRE key seconds",
	}

	RedisCommandEXPIREAT = RedisCommand{
		Name:         "EXPIREAT",
		KeyType:      RedisTypeGeneric,
		KeyExtractor: ArgsAtIndices(0),
		TransformFunc: TypeSpecificBulkTransformer(&TypeSpecificBulkTransformerConfig{
			Commands: TypeSpecificCommands{
				KV:   "EXPIREAT",
				List: "LEXPIREAT",
				Hash: "HEXPIREAT",
				Set:  "SEXPIREAT",
				ZSet: "ZEXPIREAT",
			},
			Aggregation:         AggregationSum,
			AppendArgsExtractor: ArgsAtIndices(1),
		}),
		Syntax: "EXPIREAT key timestamp",
	}

	RedisCommandPERSIST = RedisCommand{
		Name:         "PERSIST",
		KeyType:      RedisTypeGeneric,
		KeyExtractor: ArgsAtIndices(0),
		TransformFunc: TypeSpecificBulkTransformer(&TypeSpecificBulkTransformerConfig{
			Commands: TypeSpecificCommands{
				KV:   "PERSIST",
				List: "LPERSIST",
				Hash: "HPERSIST",
				Set:  "SPERSIST",
				ZSet: "ZPERSIST",
			},
			Aggregation: AggregationSum,
		}),
		Syntax: "PERSIST key",
	}

	RedisCommandRESTORE = RedisCommand{
		Name:          "RESTORE",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: RestoreCommandTransformer,
		Syntax:        "RESTORE key ttl serialized-value [REPLACE] [ABSTTL] [IDLETIME seconds] [FREQ frequency]",
	}

	RedisCommandSORT = RedisCommand{
		Name:         "SORT",
		KeyType:      RedisTypeGeneric,
		KeyExtractor: ArgsAtIndices(0),
		TransformFunc: TypeSpecificBulkTransformer(&TypeSpecificBulkTransformerConfig{
			Commands: TypeSpecificCommands{
				List: "XLSORT",
				Set:  "XSSORT",
				ZSet: "XZSORT",
			},
			Aggregation: AggregationFirst,
		}),
		Syntax: "SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination]",
	}

	RedisCommandTTL = RedisCommand{
		Name:         "TTL",
		KeyType:      RedisTypeGeneric,
		KeyExtractor: ArgsAtIndices(0),
		TransformFunc: TypeSpecificBulkTransformer(&TypeSpecificBulkTransformerConfig{
			Commands: TypeSpecificCommands{
				KV:   "TTL",
				List: "LTTL",
				Hash: "HTTL",
				Set:  "STTL",
				ZSet: "ZTTL",
			},
			Aggregation: AggregationSum,
		}),
		Syntax: "TTL key",
	}
)

RedisCommand variables describing the Redis commands operating on keys / generics (RedisTypeGeneric).

https://redis.io/commands#generic
View Source
var (
	RedisCommandDISCARD = RedisCommand{
		Name:          "DISCARD",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: TransactionTransformer,
		Syntax:        "DISCARD",
	}

	RedisCommandEXEC = RedisCommand{
		Name:          "EXEC",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: TransactionTransformer,
		Syntax:        "EXEC",
	}

	RedisCommandMULTI = RedisCommand{
		Name:          "MULTI",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: TransactionTransformer,
		Syntax:        "MULTI",
	}

	RedisCommandUNWATCH = RedisCommand{
		Name:          "UNWATCH",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(0),
		TransformFunc: TransactionTransformer,
		Syntax:        "UNWATCH",
	}

	RedisCommandWATCH = RedisCommand{
		Name:          "WATCH",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsFromIndex(0),
		TransformFunc: TransactionTransformer,
		Syntax:        "WATCH key [key ...]",
	}
)

RedisCommand variables describing the Redis commands for performing transactions.

https://redis.io/commands#transactions
View Source
var (
	RedisCommandAUTH = RedisCommand{
		Name:          "AUTH",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(),
		TransformFunc: NoneTransformer(),
		Syntax:        "AUTH password",
	}

	RedisCommandECHO = RedisCommand{
		Name:          "ECHO",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(),
		TransformFunc: NoneTransformer(),
		Syntax:        "ECHO message",
	}

	RedisCommandPING = RedisCommand{
		Name:          "PING",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(),
		TransformFunc: PingCommandTransformer,
		Syntax:        "PING [message]",
	}

	RedisCommandSELECT = RedisCommand{
		Name:          "SELECT",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(),
		TransformFunc: NoneTransformer(),
		Syntax:        "SELECT index",
	}
)

RedisCommand variables describing the Redis commands for managing the connection: Utilities for probing and altering connection properties.

https://redis.io/commands#connection
View Source
var (
	RedisCommandEVAL = RedisCommand{
		Name:          "EVAL",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(),
		TransformFunc: NoneTransformer(),
		Syntax:        "EVAL script numkeys key [key ...] arg [arg ...]",
	}

	RedisCommandEVALSHA = RedisCommand{
		Name:          "EVALSHA",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(),
		TransformFunc: NoneTransformer(),
		Syntax:        "EVALSHA sha1 numkeys key [key ...] arg [arg ...]",
	}

	RedisCommandSCRIPT = RedisCommand{
		Name:          "SCRIPT",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(),
		TransformFunc: ScriptCommandTransformer,
		Syntax:        "SCRIPT subcommand [arg ...]",
	}
)

RedisCommand variables describing the Redis commands for working with lua scripts.

https://redis.io/commands#scripting
View Source
var (
	ErrUnknownLedisTypeString   = errors.New("input string does not represent a known LedisType value")
	ErrInvalidLedisType         = errors.New("input LedisType value is unknown or otherwise invalid for this operation")
	ErrNoCorrespondingLedisType = errors.New("there is no LedisType value corresponding to the input RedisType value")
)
View Source
var (
	ErrUnknownRedisTypeString = errors.New("input string does not represent a known RedisType value")
	ErrInvalidRedisType       = errors.New("input RedisType value is unknown or otherwise invalid for this operation")
)
View Source
var (
	ErrTimeoutNotSupported = errors.New("rewledis: connection does not support ConnWithTimeout")
	ErrConnClosed          = errors.New("rewledis: connection closed")
)

Error variables related to the LedisConn type.

View Source
var (
	ErrUnexpectedCacheEntryState = errors.New("encountered cache entry with unexpected state")
	ErrErrorCacheEntryState      = errors.New("encountered cache entry with Error state")
)

Error variables related to Resolver.

View Source
var (
	ErrSubCommandNotImplemented   = errors.New("sub command not implemented")
	ErrSubCommandUnknown          = errors.New("sub command unknown")
	ErrInvalidArgumentCombination = errors.New("invalid argument combination")
	ErrInvalidSyntax              = errors.New("invalid syntax")
	ErrInvalidArgumentType        = errors.New("invalid argument type")
	ErrNoEmulationPossible        = errors.New("no emulation possible for the issued command")
)

Error variables related to transformers.

View Source
var (
	ErrInvalidAggregationValue = errors.New("invalid Aggregation value")
)
View Source
var (
	ErrUnknownRedisCommandName = errors.New("input string does not represent a known RedisCommand name")
)
View Source
var (
	ErrUnsupportedSubPoolConnection = errors.New("connection returned by SubPool is unsupported by this operation")
)

Error variables related to SubPool.

View Source
var (
	RedisCommandUNSAFE = RedisCommand{
		Name:          "UNSAFE",
		KeyType:       RedisTypeGeneric,
		KeyExtractor:  ArgsAtIndices(),
		TransformFunc: UnsafeCommandTransformer,
		Syntax:        "UNSAFE subcommand [arg ...]",
	}
)

RedisCommand variable describing the rewledis specific UNSAFE command. Similarly to the homonymous Go package: Do not use this unless you know what you are doing.

Functions

func Aggregator

func Aggregator(aggregation Aggregation) func([]interface{}) (interface{}, error)

Aggregator creates an aggregator, i.e. a function which reduces any number of reply values to a single reply value.

func NewPool

func NewPool(poolConfig *PoolConfig, internalMaxActive int) *redis.Pool

NewPool is a convenience function creating a new Pool returning rewriting connections. poolConfig and internalMaxActive are passed on to (*Rewriter).NewPrimaryPool().

Types

type Aggregation

type Aggregation int8
const (
	AggregationSum Aggregation = iota
	AggregationCountOne
	AggregationFirst
)

type ArgsExtractor

type ArgsExtractor interface {
	AppendArgs(extracted []interface{}, args []interface{}) []interface{}
	Args(args []interface{}) []interface{}
}

func ArgsAtIndices

func ArgsAtIndices(indices ...int) ArgsExtractor

ArgsAtIndices returns an ArgsExtractor. The ArgsExtractor returns the arguments with the indices passed to ArgsAtIndices.

func ArgsFromIndex

func ArgsFromIndex(index int, skip ...int) ArgsExtractor

ArgsFromIndex returns an ArgsExtractor. The ArgsExtractor returns all arguments starting at the index passed as a parameter. If the optional parameter skip is passed, skip arguments are skipped after each key argument.

func ArgsFromUntilIndex

func ArgsFromUntilIndex(from, until int, skip ...int) ArgsExtractor

ArgsFromIndexUntil returns an ArgsExtractor. The ArgsExtractor returns all arguments between the two indices passed as parameters, including the argument at from and excluding the argument at until. It works in the same way as slice ranges: args[from:until].

If until is 0 the maximum possible value is presumed. If until is less than 0 it is subtracted from the length of the arguments.

If the optional parameter skip is passed, skip arguments are skipped after each key argument.

type ArgsExtractorFunc

type ArgsExtractorFunc func(extracted []interface{}, args []interface{}) []interface{}

func (ArgsExtractorFunc) AppendArgs

func (a ArgsExtractorFunc) AppendArgs(extracted []interface{}, args []interface{}) []interface{}

func (ArgsExtractorFunc) Args

func (a ArgsExtractorFunc) Args(args []interface{}) []interface{}

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func (*Cache) LoadOrCreateEntry

func (c *Cache) LoadOrCreateEntry(key string) (CacheEntryData, CacheEntrySetter, bool)

LoadOrCreateEntry is the primary access method for the cache. For a given key, it returns either entry data or a setter. If a setter is returned, the caller must fulfill the setter by calling .Set().

The bool returned indicates whether the entry exists and is in the Loading or Exists state (this means the returned CacheEntryData is valid). If the bool is false, the returned CacheEntrySetter is valid.

func (*Cache) LoadType

func (c *Cache) LoadType(key string) (LedisType, bool)

func (*Cache) TrySetEntry

func (c *Cache) TrySetEntry(key string, state CacheEntryState, keyType LedisType) bool

TrySetEntry tries to update the entry for the given key with given state and keyType information. TrySetEntry does not wait for an ongoing loading procedure and returns without setting in this case. TrySetEntry returns true, if the entry was updated and false if not.

type CacheEntryData

type CacheEntryData struct {
	WrittenAt   time.Time
	Key         string
	DoneLoading <-chan struct{}
	State       CacheEntryState
	Type        LedisType
	// contains filtered or unexported fields
}

func (*CacheEntryData) Refresh

func (c *CacheEntryData) Refresh()

type CacheEntrySetter

type CacheEntrySetter struct {
	Key string
	// contains filtered or unexported fields
}

func (*CacheEntrySetter) Set

func (c *CacheEntrySetter) Set(state CacheEntryState, keyType LedisType)

Set sets the Type field of an entry along with the State and WrittenAt fields. It also signals completion of the loading process by closing the DoneLoading channel. state must be either CacheEntryStateExists, CacheEntryStateDeleted or CacheEntryStateError and indicates the success state of the type resolution. If state is not CacheEntryStateExists the keyType value is ignored.

type CacheEntryState

type CacheEntryState int8
const (
	CacheEntryStateNone CacheEntryState = iota
	CacheEntryStateLoading
	CacheEntryStateExists
	CacheEntryStateDeleted
	CacheEntryStateError
)

Constants which a CacheEntryState value can assume.

type KeyTypeAggregation

type KeyTypeAggregation struct {
	None []string
	KV   []string
	List []string
	Hash []string
	Set  []string
	ZSet []string
}

func (*KeyTypeAggregation) AppendKeys

func (k *KeyTypeAggregation) AppendKeys(typesInfo []TypeInfo)

type LedisConn

type LedisConn struct {
	// contains filtered or unexported fields
}

LedisConn is a rewriting wrapper around a connection to a LedisDB server. Many Redis commands can be issued on this connection. The commands are dynamically rewritten to their LedisDB equivalent. See the repository's README for more information on which commands are supported.

func (*LedisConn) Close

func (l *LedisConn) Close() error

Close closes the connection.

func (*LedisConn) Do

func (l *LedisConn) Do(commandName string, args ...interface{}) (interface{}, error)

Do sends a command to the server and returns the received reply.

func (*LedisConn) DoWithTimeout

func (l *LedisConn) DoWithTimeout(timeout time.Duration, commandName string, args ...interface{}) (interface{}, error)

Do sends a command to the server and returns the received reply. The timeout overrides the read timeout set when dialing the connection.

func (*LedisConn) Err

func (l *LedisConn) Err() error

Err returns a non-nil value when the connection is not usable.

func (*LedisConn) Flush

func (l *LedisConn) Flush() error

Flush flushes the output buffer to the Redis server.

func (*LedisConn) RawConn

func (l *LedisConn) RawConn() redis.Conn

RawConn returns the underlying connection to the LedisDB server.

This method must be used with care, as the stack of internally stored reply procedures (Slots) can no longer be maintained. RawConn should only be used on connections without any pending replies.

func (*LedisConn) Receive

func (l *LedisConn) Receive() (interface{}, error)

Receive receives a single reply from the Redis server.

func (*LedisConn) ReceiveWithTimeout

func (l *LedisConn) ReceiveWithTimeout(timeout time.Duration) (interface{}, error)

Receive receives a single reply from the Redis server. The timeout overrides the read timeout set when dialing the connection.

func (*LedisConn) Send

func (l *LedisConn) Send(commandName string, args ...interface{}) error

Send writes the command to the client's output buffer.

type LedisType

type LedisType int8
const (
	LedisTypeNone LedisType = iota
	LedisTypeKV
	LedisTypeList
	LedisTypeHash
	LedisTypeSet
	LedisTypeZSet
)

func LedisTypeFromRedisType

func LedisTypeFromRedisType(redisType RedisType) (LedisType, error)

func ParseLedisType

func ParseLedisType(str string) (LedisType, error)

func ParseLedisTypeFromLedis

func ParseLedisTypeFromLedis(str string) (LedisType, error)

func (LedisType) String

func (l LedisType) String() string

type PoolConfig

type PoolConfig struct {
	// Dial is an application supplied function for creating and configuring a
	// connection. Dial must return a connection to a LedisDB server.
	Dial func() (redis.Conn, error)

	// TestOnBorrow is an optional application supplied function for checking the
	// health of an idle connection before the connection is used again by the
	// application. Argument c is a wrapped (rewriting) connection emulating
	// Redis semantics. Argument t is the time that the connection was returned
	// to the pool. If the function returns an error, then the connection is
	// closed.
	TestOnBorrow func(c redis.Conn, t time.Time) error

	// Maximum number of idle connections in the pool.
	MaxIdle int

	// MaxActive is the maximum number of connections allocated by the pool at
	// a given time. When zero, there is no limit on the number of connections
	// in the pool.
	MaxActive int

	// IdleTimeout is the duration after which to close idle connections. If
	// the value is zero, then idle connections are not closed. Applications
	// should set the timeout to a value less than the server's timeout.
	IdleTimeout time.Duration

	// If Wait is true and the pool is at the MaxActive limit, then Get() waits
	// for a connection to be returned to the pool before returning.
	Wait bool

	// Close connections older than this duration. If the value is zero, then
	// the pool does not close connections based on age.
	MaxConnLifetime time.Duration
}

PoolConfig contains all configuration options for a redigo pool instance. The fields contained mirror the redis.Pool type of redigo.

func (*PoolConfig) Clone

func (p *PoolConfig) Clone() *PoolConfig

func (*PoolConfig) CopyFrom

func (p *PoolConfig) CopyFrom(other *PoolConfig)

func (*PoolConfig) Merge

func (p *PoolConfig) Merge(other *PoolConfig) *PoolConfig

type RedisCommand

type RedisCommand struct {
	Name          string
	KeyType       RedisType
	KeyExtractor  ArgsExtractor
	TransformFunc TransformFunc
	Syntax        string
}

func RedisCommandFromName

func RedisCommandFromName(name string) (*RedisCommand, error)

func (RedisCommand) AppendKeys

func (r RedisCommand) AppendKeys(keys []string, args []interface{}) []string

func (RedisCommand) Keys

func (r RedisCommand) Keys(args []interface{}) []string

type RedisType

type RedisType int8
const (
	RedisTypeNone RedisType = iota
	RedisTypeString
	RedisTypeList
	RedisTypeHash
	RedisTypeSet
	RedisTypeZSet

	RedisTypeGeneric = -2
)

func ParseRedisType

func ParseRedisType(str string) (RedisType, error)

func ParseRedisTypeFromRedis

func ParseRedisTypeFromRedis(str string) (RedisType, error)

func (RedisType) String

func (r RedisType) String() string

type Resolver

type Resolver struct {
	Cache   *Cache
	SubPool *SubPool
}

Resolver provides functionality to resolve the type of keys while using a Cache instance.

func (*Resolver) ResolveAppend

func (r *Resolver) ResolveAppend(typesInfo []TypeInfo, ctx context.Context, keys []string) ([]TypeInfo, error)

func (*Resolver) ResolveOne

func (r *Resolver) ResolveOne(ctx context.Context, key string) (LedisType, error)

type Rewriter

type Rewriter struct {
	// contains filtered or unexported fields
}

func (*Rewriter) NewPool

func (r *Rewriter) NewPool(config *PoolConfig) *redis.Pool

NewPool creates and returns a new Pool of connections to a LedisDB server. The returned Pool yields wrapped connections emulating Redis semantics. Commands are rewritten using this Rewriter.

In order for rewriting to work properly, the primary pool of the Rewriter must have been set. That means NewPrimaryPool has to have been called.

func (*Rewriter) NewPrimaryPool

func (r *Rewriter) NewPrimaryPool(config *PoolConfig, internalMaxActive int) *redis.Pool

NewPrimaryPool creates a new pool from config and uses the created pool as its primary pool. The primary pool is used for internal operations, at the moment only by a Resolver. Use internalMaxActive to set the maximum number of connections used for internal purposes. 0 means no limit.

The primary pool is not changed if the primary pool of the Rewriter has already been set and this method is called again.

The returned Pool yields wrapped connections emulating Redis semantics. Commands are rewritten using this Rewriter.

func (*Rewriter) Resolver

func (r *Rewriter) Resolver() Resolver

Resolver constructs and returns a Resolver instance using this rewriter.

func (*Rewriter) Rewrite

func (r *Rewriter) Rewrite(commandName string, args ...interface{}) (SendLedisFunc, error)

Rewrite applies transformations for a single supplied command invocation.

func (*Rewriter) WrapConn

func (r *Rewriter) WrapConn(conn redis.Conn) *LedisConn

WrapConn wraps a connection to a LedisDB server and returns a connection emulating Redis semantics. All commands issued on the returned connection are rewritten using this rewriter.

type SendLedisFunc

type SendLedisFunc func(ledisConn redis.Conn) (Slot, error)

func LremCommandTransformer

func LremCommandTransformer(rewriter *Rewriter, command *RedisCommand, args []interface{}) (SendLedisFunc, error)

func PingCommandTransformer

func PingCommandTransformer(rewriter *Rewriter, command *RedisCommand, args []interface{}) (SendLedisFunc, error)

PingCommandTransformer performs transformations for the PING Redis command.

func RestoreCommandTransformer

func RestoreCommandTransformer(rewriter *Rewriter, command *RedisCommand, args []interface{}) (SendLedisFunc, error)

RestoreCommandTransformer performs transformations for the RESTORE Redis command.

The IDLETIME and FREQ modifiers are ignored and removed when passing on the command to LedisDB.

TODO: Figure out how LedisDB performs RESTORE and incorporate into REPLACE handling.

func ScriptCommandTransformer

func ScriptCommandTransformer(rewriter *Rewriter, command *RedisCommand, args []interface{}) (SendLedisFunc, error)

ScriptCommandTransformer performs transformations for the SCRIPT Redis command.

Only some sub-commands are supported. Issuing a not supported sub-command results in a ErrSubCommandNotImplemented error.

Implemented:
  SCRIPT EXISTS sha1 [sha1 ...]
  SCRIPT FLUSH
  SCRIPT LOAD script
Not implemented:
  SCRIPT DEBUG YES|SYNC|NO
  SCRIPT KILL

func SetCommandTransformer

func SetCommandTransformer(rewriter *Rewriter, command *RedisCommand, args []interface{}) (SendLedisFunc, error)

SetCommandTransformer performs transformations for the SET Redis command.

This transformer mirrors Redis behaviour: When both XX and EX is supplied, nil is returned without applying any changes. When both EX and PX is supplied, the PX value takes precedence.

func TransactionTransformer

func TransactionTransformer(rewriter *Rewriter, command *RedisCommand, args []interface{}) (SendLedisFunc, error)

TransactionTransformer performs transformations for transaction related Redis commands.

Support for transaction commands has not yet been integrated into rewledis. The transformer drops all commands except DISCARD for which ErrNoEmulationPossible is returned. This "emulation" is subject to race-conditions.

func UnsafeCommandTransformer

func UnsafeCommandTransformer(rewriter *Rewriter, command *RedisCommand, args []interface{}) (SendLedisFunc, error)

UnsafeCommandTransformer performs transformations for the UNSAFE Redis command provided by rewledis.

func ZaddCommandTransformer

func ZaddCommandTransformer(rewriter *Rewriter, command *RedisCommand, args []interface{}) (SendLedisFunc, error)

type Slot

type Slot struct {
	RepliesCount int
	ProcessFunc  func([]interface{}) (interface{}, error)
}

type SlotDeque

type SlotDeque struct {
	// contains filtered or unexported fields
}

SlotDeque represents a single instance of the deque data structure.

func (*SlotDeque) At

func (q *SlotDeque) At(i int) Slot

At returns the element at index i in the queue without removing the element from the queue. This method accepts only non-negative index values. At(0) refers to the first element and is the same as Front(). At(Len()-1) refers to the last element and is the same as Back(). If the index is invalid, the call panics.

The purpose of At is to allow SlotDeque to serve as a more general purpose circular buffer, where items are only added to and removed from the ends of the deque, but may be read from any place within the deque. Consider the case of a fixed-size circular log buffer: A new entry is pushed onto one end and when full the oldest is popped from the other end. All the log entries in the buffer must be readable without altering the buffer contents.

func (*SlotDeque) Back

func (q *SlotDeque) Back() Slot

Back returns the element at the back of the queue. This is the element that would be returned by PopBack(). This call panics if the queue is empty.

func (*SlotDeque) Clear

func (q *SlotDeque) Clear()

Clear removes all elements from the queue, but retains the current capacity. This is useful when repeatedly reusing the queue at high frequency to avoid GC during reuse. The queue will not be resized smaller as long as items are only added. Only when items are removed is the queue subject to getting resized smaller.

func (*SlotDeque) Front

func (q *SlotDeque) Front() Slot

Front returns the element at the front of the queue. This is the element that would be returned by PopFront(). This call panics if the queue is empty.

func (*SlotDeque) Len

func (q *SlotDeque) Len() int

Len returns the number of elements currently stored in the queue.

func (*SlotDeque) PopBack

func (q *SlotDeque) PopBack() Slot

PopBack removes and returns the element from the back of the queue. Implements LIFO when used with PushBack(). If the queue is empty, the call panics.

func (*SlotDeque) PopFront

func (q *SlotDeque) PopFront() Slot

PopFront removes and returns the element from the front of the queue. Implements FIFO when used with PushBack(). If the queue is empty, the call panics.

func (*SlotDeque) PushBack

func (q *SlotDeque) PushBack(elem Slot)

PushBack appends an element to the back of the queue. Implements FIFO when elements are removed with PopFront(), and LIFO when elements are removed with PopBack().

func (*SlotDeque) PushFront

func (q *SlotDeque) PushFront(elem Slot)

PushFront prepends an element to the front of the queue.

func (*SlotDeque) Rotate

func (q *SlotDeque) Rotate(n int)

Rotate rotates the deque n steps front-to-back. If n is negative, rotates back-to-front. Having SlotDeque provide Rotate() avoids resizing that could happen if implementing rotation using only Pop and Push methods.

type SubPool

type SubPool struct {
	Pool      *redis.Pool
	MaxActive int
	// contains filtered or unexported fields
}

SubPool represents a fixed-capacity part of an existing redis.Pool. The SubPool allows a maximum of MaxActive connections to be in use by its consumers at any point in time.

The type mimics redis.Pool behaviour and should be initialised using struct initialisation.

subPool := SubPool{
    Pool:      pool,
    MaxActive: 5,
}

Close() and further methods are purposefully omitted, the underlying redis.Pool is considered the owner and manager of the connection resources.

func (*SubPool) Get

func (s *SubPool) Get() redis.Conn

Get retrieves a connection from the pool. The connection must be closed.

func (*SubPool) GetContext

func (s *SubPool) GetContext(ctx context.Context) (redis.Conn, error)

GetContext retrieves a connection from the pool. GetContext respects the passed in context while retrieving the connection. The connection must be closed.

type TransformFunc

type TransformFunc func(rewriter *Rewriter, command *RedisCommand, args []interface{}) (SendLedisFunc, error)

func NoneTransformer

func NoneTransformer() TransformFunc

func TypeSpecificBulkTransformer

func TypeSpecificBulkTransformer(config *TypeSpecificBulkTransformerConfig) TransformFunc

type TypeInfo

type TypeInfo struct {
	Key  string
	Type LedisType
}

type TypeSpecificBulkTransformerConfig

type TypeSpecificBulkTransformerConfig struct {
	Commands            TypeSpecificCommands
	Debulk              bool
	Aggregation         Aggregation
	AppendArgsExtractor ArgsExtractor
}

type TypeSpecificCommands

type TypeSpecificCommands struct {
	None string
	KV   string
	List string
	Hash string
	Set  string
	ZSet string
}

Directories

Path Synopsis
Package args provides utilities for working with redigo command arguments.
Package args provides utilities for working with redigo command arguments.

Jump to

Keyboard shortcuts

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