本文整理汇总了Golang中github.com/gosuri/go-store/store.Item类的典型用法代码示例。如果您正苦于以下问题:Golang Item类的具体用法?Golang Item怎么用?Golang Item使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Item类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Write
// Write writes the item to the store. It constructs the key using the i.Key()
// and prefixes it with the type of struct. When the key is empty, it assigns
// a unique universal id(UUID) using the SetKey method of the Item
func (s *Store) Write(i store.Item) error {
c := s.pool.Get()
defer c.Close()
value := reflect.ValueOf(i).Elem()
ri := &Item{
prefix: s.typeName(value),
data: make(map[string]interface{}),
}
// Use the Items id if set or generate
// a new UUID
ri.key = i.Key()
if len(ri.key) == 0 {
ri.key = uuid.New()
}
i.SetKey(ri.key)
// convert the item to redis item
if err := marshall(i, value, ri); err != nil {
return err
}
for key, val := range ri.data {
if err := c.Send("HSET", ri.Key(), key, val); err != nil {
return err
}
c.Flush()
}
return nil
}
开发者ID:rargulati,项目名称:go-store,代码行数:36,代码来源:redis.go
示例2: Delete
// Delete deletes the item from the store. It constructs the key using i.Key().
// When the key is empty, it returns a store.ErrEmptyKey error. When the key
// does not exist, it returns a store.ErrKeyNotFound error.
func (s *Redis) Delete(i store.Item) error {
c := s.pool.Get()
defer c.Close()
value := reflect.ValueOf(i).Elem()
ri := &item{
prefix: s.typeName(value),
}
ri.key = i.Key()
if len(ri.key) == 0 {
return store.ErrEmptyKey
}
count, err := driver.Int(c.Do("DEL", ri.Key()))
if err != nil {
return err
}
if count == 0 {
return store.ErrKeyNotFound
}
return nil
}
开发者ID:dexter-cn,项目名称:go-store,代码行数:28,代码来源:redis.go
示例3: Read
// Read reads the item from redis store and copies the values to item
// It Returns store.ErrKeyNotFound when no values are found for the key provided
// and store.ErrKeyMissing when key is not provided. Unmarshalling id done using
// driver provided redis.ScanStruct
func (s *Store) Read(i store.Item) error {
c := s.pool.Get()
defer c.Close()
value := reflect.ValueOf(i).Elem()
if len(i.Key()) == 0 {
return store.ErrEmptyKey
}
ri := &Item{
key: i.Key(),
prefix: value.Type().Name(),
}
reply, err := driver.Values(c.Do("HGETALL", ri.Key()))
if err != nil {
return err
}
if len(reply) == 0 {
return store.ErrKeyNotFound
}
if err := driver.ScanStruct(reply, i); err != nil {
return err
}
return nil
}
开发者ID:rargulati,项目名称:go-store,代码行数:28,代码来源:redis.go
注:本文中的github.com/gosuri/go-store/store.Item类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论