search

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client manages a redis.Client for use with indexing and searching within a node.

func NewClient

func NewClient(address string, version int) (search *Client, err error)

NewClient is a factory method for Client. The address should contain ip and port with no "http://", e.g. "localhost:6379". Pass in a version number for your client. Start it at zero. If you later increment it, the client will wipe the database and require reindexing.

func (*Client) Del

func (search *Client) Del(key string) (int64, error)

Del is a wrapper for redis DEL.

func (*Client) FlushDB

func (search *Client) FlushDB() error

FlushDB is a wrapper for redis FLUSHDB.

func (*Client) Get

func (search *Client) Get(key string) (string, error)

Get is a wrapper for redis GET. Returns empty string (not nil) if the key doesn't exist.

func (*Client) GetNextHeight

func (search *Client) GetNextHeight() uint64

GetNextHeight gets the high water mark (height) we've indexed up to, but not including it.

func (*Client) HGet

func (search *Client) HGet(key, field string) (string, error)

HGet is a wrapper for redis HGET.

func (*Client) HGetAll

func (search *Client) HGetAll(key string) (map[string]string, error)

HGetAll is a wrapper for redis HGETALL.

func (*Client) HSet

func (search *Client) HSet(key, field string, value interface{}) (bool, error)

HSet is a wrapper for redis HSET. Returns true for new fields, false if field already exists.

func (*Client) IndexDateToHeight

func (search *Client) IndexDateToHeight(
	blockTime math.Timestamp, blockHeight uint64,
) (updateCount int, insertCount int, err error)

IndexDateToHeight will index all necessary date-to-height keys back in time to the latest one we've indexed, using the given date and height. Typically this function will only need to do work once every dateRangeInterval seconds. But if there are long periods of block inactivity, this function will fill in all missing date-to-height keys up to the given block time. The given block height must be > 0, which is guaranteed if it comes from Tendermint.

func (*Client) Inner

func (search *Client) Inner() *redis.Client

Inner returns the internal bare client so that methods can be accessed without wrapping

func (*Client) Keys

func (search *Client) Keys(pattern string) ([]string, error)

Keys is a wrapper for redis KEYS.

func (*Client) Ping

func (search *Client) Ping() error

Ping is a wrapper for redis PING.

func (*Client) SAdd

func (search *Client) SAdd(
	key string, value string,
) (int64, error)

SAdd is a wrapper for redis SADD. Returns the number of elements added.

func (*Client) SScan

func (search *Client) SScan(
	key string,
	cb func(value string) error,
) error

SScan is a wrapper for redis full-iteration SSCAN with wildcard match.

func (*Client) SearchDateRange

func (search *Client) SearchDateRange(first, last string) (uint64, uint64, error)

SearchDateRange returns the first and last block heights for the given ISO-3339 date range. The first is inclusive, the last is exclusive.

func (*Client) Set

func (search *Client) Set(key string, value interface{}) error

Set is a wrapper for redis SET with no expiration.

func (*Client) SetNextHeight

func (search *Client) SetNextHeight(height uint64) (err error)

SetNextHeight saves the given height in the database as a high water mark. Call this after you've indexed something at a given blockchain height. It's also acceptable to call this once after an initial scan. It will make the next scan-on-launch index blocks down to, and including, this height.

func (*Client) ZAdd

func (search *Client) ZAdd(
	key string, score float64, value string,
) (int64, error)

ZAdd is a wrapper for redis ZADD. Returns the number of elements added.

func (*Client) ZCard

func (search *Client) ZCard(key string) (int64, error)

ZCard is a wrapper for redis ZCARD. It's like "ZCOUNT key -inf +inf" but is O(1).

func (*Client) ZRevRange

func (search *Client) ZRevRange(key string, start, stop int64) ([]string, error)

ZRevRange is a wrapper for redis ZREVRANGE without returning scores.

func (*Client) ZRevRangeByScore

func (search *Client) ZRevRangeByScore(key string, max float64, count int64) ([]string, error)

ZRevRangeByScore is a wrapper for redis ZREVRANGEBYSCORE without returning scores. We use an exclusive range (-inf, max). The initial use-case for this was for returning all transactions in and before a given block height, and scores for transactions are floats with integer part being the height and fractional part holding the tx offset within the block. So, for example, to get all transactions on or before height 50, we'd use:

ZRevRangeByScore(key, 51.0, count)

This will include a transaction with score 50.999 (the 1000th tx in block 50). It will not include a transaction with score 51 (the first tx in block 51). See ndau/pkg/ndau/search/index.go for how we encode height-txoffset pairs in a float score. The count param can be used to limit the number of results. Zero means no limit.

func (*Client) ZRevRangeByScoreMinMax

func (search *Client) ZRevRangeByScoreMinMax(key string, min float64, max float64, count int64) ([]string, error)

func (*Client) ZRevRank

func (search *Client) ZRevRank(key, searchValue string) (int64, error)

ZRevRank is a wrapper for redis ZREVRANK.

func (*Client) ZScan

func (search *Client) ZScan(
	key string,
	cb func(value string, score float64) error,
) error

ZScan is a wrapper for redis full-iteration ZSCAN with wildcard match.

func (*Client) ZUnionStore

func (search *Client) ZUnionStore(key string, searchKeys []string) (int64, error)

ZUnionStore is a wrapper for redis ZUNIONSTORE.

type DateRangeRequest

type DateRangeRequest struct {
	FirstTimestamp string
	LastTimestamp  string
}

DateRangeRequest is used for passing date range query terms over endpoints.

func (*DateRangeRequest) Marshal

func (request *DateRangeRequest) Marshal() string

Marshal the request.

func (*DateRangeRequest) Unmarshal

func (request *DateRangeRequest) Unmarshal(requestString string) error

Unmarshal the request.

type DateRangeResult

type DateRangeResult struct {
	FirstHeight uint64
	LastHeight  uint64
}

DateRangeResult is used for returning search results for the date range endpoint.

func (*DateRangeResult) Marshal

func (result *DateRangeResult) Marshal() string

Marshal the result.

func (*DateRangeResult) Unmarshal

func (result *DateRangeResult) Unmarshal(resultString string) error

Unmarshal the result.

Jump to

Keyboard shortcuts

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